Beispiel #1
0
        private void CheckTransitions()
        {
            while (_pushedTriggers.Count != 0)
            {
                FTrigger trigger = _pushedTriggers.Dequeue();

                for (int i = 0; i < _activeStates.Count; ++i)
                {
                    IState state = _activeStates[i];

                    ITransition transition = state.CheckTransitions(trigger);

                    if (transition != null)
                    {
                        if (transition.Target is IHistoryState historyState)
                        {
                            if (historyState.LastState == null)
                            {
                                FAssert.IsNotNull(historyState.Parent, $"`{historyState.Name}` parent is null. A history state should always have parent!");
                                historyState.LastState = historyState.Parent.InitialState;
                            }

                            FireTransition(state, new FTransition(transition.Trigger, historyState.LastState, transition.Condition, transition.Actions));
                        }
                        else
                        {
                            FireTransition(state, transition);
                        }

                        break;
                    }
                }
            }
        }
Beispiel #2
0
        public void TestAssertNotNullOrEmptyCollection()
        {
            ArrayList ol = new ArrayList();

            ol.Add(new object());
            FAssert.NotEmpty(ol);
            try {
                ol.Clear();
                FAssert.NotEmpty(ol);
                Assert.IsTrue(false, "FAssert should have thrown an exception");
            } catch (FAssertException) { }

            List <string> sl = new List <string>();

            sl.Add("hi");
            FAssert.NotEmpty(sl);
            try {
                sl.Clear();
                FAssert.NotEmpty(sl);
                Assert.IsTrue(false, "FAssert should have thrown an exception");
            } catch (FAssertException) { }

            try {
                FAssert.NotEmpty((ICollection)null);
                Assert.IsTrue(false, "FAssert should have thrown an exception");
            } catch (FAssertException) { }
        }
Beispiel #3
0
        public void AddTransition(FTrigger trigger, IState target)
        {
            FAssert.IsTrue(trigger != null, "Trigger is invalid.");
            FAssert.IsNotNull(target, $"Target state can't be null.");

            _transitions.Add(new FTransition(trigger, target));
        }
Beispiel #4
0
 public void TestAssertEquals()
 {
     try {
         FAssert.Equals(1, 1);
         Assert.IsTrue(false, "FAssert should have thrown an exception");
     } catch (FAssertException) { }
 }
Beispiel #5
0
        public void TestAssertEqual()
        {
            object o = new object();
            object p = o;

            FAssert.Equal(o, p);
            int i = 3;
            int j = 3;

            FAssert.Equal(i, j);
            float f = 3f;
            float g = 3.0f;

            FAssert.Equal(f, g);
            FAssert.Equal(i, (int)g);
            try {
                o = new object();
                FAssert.Equal(o, p);
                Assert.IsTrue(false, "FAssert should have thrown an exception");
            } catch (FAssertException) { }
            try {
                o = null;
                FAssert.Equal(o, p);
                Assert.IsTrue(false, "FAssert should have thrown an exception");
            } catch (FAssertException) { }
        }
        /// <summary>
        /// If given instance's class has defines given attribute, return desire property.
        /// </summary>
        /// <returns>Value of desire property in given attribute</returns>
        public static T GetAttributeProperty <T>(object instance, Type attributeType, string propertyName)
        {
            FAssert.IsNotNull(instance);
            FAssert.IsNotNull(attributeType);
            FAssert.IsFalse(string.IsNullOrEmpty(propertyName));
            FAssert.IsTrue(attributeType.IsSubclassOf(typeof(Attribute)));

            Type instanceType = instance.GetType();

            FAssert.IsTrue(HasDefinedAttribute(instanceType, attributeType));

            PropertyInfo propertyInfo = attributeType.GetProperty(propertyName, BINDING_FLAGS);

            FAssert.IsNotNull(propertyInfo);

            try
            {
                Attribute attribute = instanceType.GetCustomAttribute(attributeType);

                return((T)propertyInfo.GetValue(attribute));
            }
            catch (InvalidCastException exception)
            {
                FLog.Error(CLASS_TYPE.Name, exception.Message);

                return(default);
        public void AddValue <T>(FStringId key, T value) where T : class, IVariant
        {
            FAssert.IsFalse(string.IsNullOrWhiteSpace(key), $"Name can't be null or empty.");
            FAssert.IsFalse(_values.ContainsKey(key), $"A value with {key} key is already exist in blackboard.");

            _values.Add(key, value);
        }
        /// <summary>
        /// Is given class type defines following attributes on it self?
        /// </summary>
        /// <param name="classType">Type of the class that you want to check.</param>
        /// <param name="attributeType">Type of attribute that you want to check.</param>
        /// <returns></returns>
        public static bool HasDefinedAttribute(Type classType, Type attributeType)
        {
            FAssert.IsNotNull(classType);
            FAssert.IsNotNull(attributeType);
            FAssert.IsTrue(attributeType.IsSubclassOf(typeof(Attribute)));

            return(classType.IsDefined(attributeType));
        }
        public void CompareTwoFalseBoolTest()
        {
            FBool left = false;

            FBool right = false;

            FAssert.AreEqual(left, right);
        }
        public void CompareTwoDifferentFloatTest()
        {
            FFloat left = 1;

            FFloat right = 2;

            FAssert.AreNotEqual(left, right);
        }
        public void CompareTwoSameFloatTest()
        {
            FFloat left = 1;

            FFloat right = 1;

            FAssert.AreEqual(left, right);
        }
Beispiel #12
0
        public void AddTransition(FTrigger trigger, IState target, IEnumerable <ITransitionAction> actions)
        {
            FAssert.IsTrue(trigger != null, "Trigger is invalid.");
            FAssert.IsNotNull(target, $"Target state can't be null.");
            FAssert.IsNotNull(actions, "Actions can't be null");

            _transitions.Add(new FTransition(trigger, target, actions));
        }
Beispiel #13
0
        private void FireTransition(IState source, ITransition transition)
        {
            FAssert.IsTrue(_pooledStates.ContainsKey(transition.Target.Name), $"{transition.Target.Name} is not exist in this machine.");

            ExitHierarchyToClosestCommonAncestor(source, transition);
            transition.PerformActions();
            EnterHierarhcyFromClosestCommonAncestor(source, transition);
        }
Beispiel #14
0
        public void CompareTwoDifferentIntTest()
        {
            FInt left = 1;

            FInt right = 2;

            FAssert.AreNotEqual(left, right);
        }
Beispiel #15
0
        public void CompareTwoSameIntTest()
        {
            FInt left = 1;

            FInt right = 1;

            FAssert.AreEqual(left, right);
        }
        public void CompareTwoDifferentStringTest()
        {
            FString left = "A";

            FString right = "B";

            FAssert.AreNotEqual(left, right);
        }
        public void CompareTwoSameStringTest()
        {
            FString left = "A";

            FString right = "A";

            FAssert.AreEqual(left, right);
        }
        public void CompreAFalseAndATrueBoolTest()
        {
            FBool left = false;

            FBool right = true;

            FAssert.AreNotEqual(left, right);
        }
        /// <summary>
        /// return instance of given service if it has been registered before.
        /// </summary>
        /// <typeparam name="TService">ServiceType</typeparam>
        /// <returns>Service instance of given type</returns>
        public static TService Get <TService>() where TService : class
        {
            Type serviceType = typeof(TService);

            FAssert.IsTrue(_registeredServices.ContainsKey(serviceType), $"{serviceType.Name} service does not exist.");

            return(_registeredServices[serviceType] as TService);
        }
Beispiel #20
0
        protected override bool Equals(IVariant other)
        {
            FInt castedOther = other as FInt;

            FAssert.IsNotNull(castedOther, $"Other is not type of {nameof(FInt)}");

            return(this._value == castedOther._value);
        }
Beispiel #21
0
        protected override int CompareTo(IVariant other)
        {
            FInt castedOther = other as FInt;

            FAssert.IsNotNull(castedOther, $"Other is not type of {nameof(FInt)}");

            return(_value.CompareTo(castedOther._value));
        }
Beispiel #22
0
        public void AddTransition(FTrigger trigger, IState target, ICondition condition, ITransitionAction action)
        {
            FAssert.IsTrue(trigger != null, "Trigger is invalid.");
            FAssert.IsNotNull(target, $"Target state can't be null.");
            FAssert.IsNotNull(condition, $"Condition can't be null.");
            FAssert.IsNotNull(action, "Action can't be null");

            _transitions.Add(new FTransition(trigger, target, condition, action));
        }
Beispiel #23
0
 public void TestAssertFail()
 {
     try {
         FAssert.Fail("Test", "hi", "boo", 33, 44.55);
         Assert.IsTrue(false, "FAssert should have thrown an exception");
     } catch (FAssertException e) {
         Debug.Log(e);
     }
 }
Beispiel #24
0
        public void EvaluateCriteriaIsNotEqualTest()
        {
            FBlackboard blackboard = new FBlackboard();

            blackboard.AddValue <FInt>("FloatValue", 2);

            ICriteria criteria = new FCriteria(blackboard, "FloatValue", EValueComparer.Equal, new FInt(1));

            FAssert.IsFalse(criteria.Evaluate());
        }
Beispiel #25
0
        public void EvaluateCriteriaGreaterThanTest()
        {
            FBlackboard blackboard = new FBlackboard();

            blackboard.AddValue <FInt>("FloatValue", 2);

            ICriteria criteria = new FCriteria(blackboard, "FloatValue", EValueComparer.GreaterThan, new FInt(1));

            FAssert.IsTrue(criteria.Evaluate());
        }
Beispiel #26
0
 public void TestGreaterThanOrEqual()
 {
     FAssert.GreaterThanOrEqual(2.0001f, 1.9999f);
     FAssert.GreaterThanOrEqual(2, 1);
     FAssert.GreaterThanOrEqual((byte)234, (long)234);
     try {
         FAssert.GreaterThanOrEqual(1.9999f, 2.0001);
         Assert.IsTrue(false, "FAssert should have thrown an exception");
     } catch (FAssertException) { }
 }
Beispiel #27
0
        public void EvaluateCriteriaLessThanEqualTest()
        {
            FBlackboard blackboard = new FBlackboard();

            blackboard.AddValue <FInt>("FloatValue", 2);

            ICriteria criteria = new FCriteria(blackboard, "FloatValue", EValueComparer.LessThanEqual, new FInt(2));

            FAssert.IsTrue(criteria.Evaluate());
        }
Beispiel #28
0
        public override bool Equals(object obj)
        {
            FAssert.IsTrue(obj is FStringId, $"Given value is not an FStringId type.");

            if ((object)this == obj)
            {
                return(true);
            }

            return(_id == ((FStringId)obj)._id);
        }
Beispiel #29
0
        public void TestAssertNotNull()
        {
            object o = new object();

            FAssert.NotNull(o);
            try {
                o = null;
                FAssert.NotNull(o);
                Assert.IsTrue(false, "FAssert should have thrown an exception");
            } catch (FAssertException) { }
        }
Beispiel #30
0
 public void TestLessThanOrEqual()
 {
     FAssert.LessThanOrEqual(1.9999f, 2.0001);
     FAssert.LessThanOrEqual(1, 2);
     FAssert.LessThanOrEqual((byte)0x23, (long)0x24);
     FAssert.LessThanOrEqual(300.1, 300.1);
     try {
         FAssert.LessThanOrEqual(2.0001f, 1.9999f);
         Assert.IsTrue(false, "FAssert should have thrown an exception");
     } catch (FAssertException) { }
 }