コード例 #1
0
ファイル: StateTests.cs プロジェクト: Diebanez/LudredStates
        public void TestRemoveBehaviour()
        {
            var state = new State();

            var behaviourTestNumber = Random.Range(1, 10);
            var behaviours          = new TestStateBehaviour[behaviourTestNumber];

            for (int i = 0; i < behaviourTestNumber; i++)
            {
                behaviours[i] = new TestStateBehaviour();
            }

            for (int i = 0; i < behaviourTestNumber; i++)
            {
                state.AddBehaviour(behaviours[i]);
            }

            var removeElement = Random.Range(0, behaviourTestNumber);

            state.RemoveBehaviour(behaviours[removeElement]);
            Assert.True(state.Behaviours.Length == behaviours.Length - 1);
            if (removeElement < state.Behaviours.Length)
            {
                Assert.True(behaviours[removeElement] != state.Behaviours[removeElement]);
            }
        }
コード例 #2
0
        public void Return_Behaviour_Of_Specific_Type_From_Specific_State()
        {
            var fsm = new HierarchicalStateMachine <int, int>();

            var stateBehaviour = new TestStateBehaviour();

            fsm.AddWithBehaviours(1, stateBehaviour);

            Assert.AreEqual(stateBehaviour, fsm.GetBehaviourOf <TestStateBehaviour, int, int>(1));
        }
コード例 #3
0
        public void Return_Behaviour_Of_Specific_Type_From_Specific_State()
        {
            var fsm = NewStateMachine();

            var stateId1 = NewStateId();

            var stateBehaviour = new TestStateBehaviour();

            fsm.AddWithBehaviours(stateId1, stateBehaviour);

            Assert.AreEqual(stateBehaviour, fsm.GetBehaviourOf <TestStateBehaviour, TState, TTrigger>(stateId1));
        }
コード例 #4
0
        public void Return_Behaviours_Of_Specific_Type_From_Specific_Behavioural_State()
        {
            var fsm = new HierarchicalStateMachine <int, int>();

            var stateBehaviour1 = new TestStateBehaviour();
            var stateBehaviour2 = new TestStateBehaviour();
            var stateBehaviour3 = Substitute.For <IStateBehaviour>();

            fsm.AddWithBehaviours(1, stateBehaviour1, stateBehaviour2, stateBehaviour3);

            var behaviors = fsm.GetBehavioursOf <TestStateBehaviour, int, int>(1);

            Assert.IsTrue(behaviors.Length == 2);
            Assert.IsTrue(behaviors.Contains(stateBehaviour1));
            Assert.IsTrue(behaviors.Contains(stateBehaviour2));
        }
コード例 #5
0
        public void Return_Behaviours_Of_Specific_Type_From_Specific_Behavioural_State()
        {
            var fsm = NewStateMachine();

            var stateId1 = NewStateId();

            var stateBehaviour1 = new TestStateBehaviour();
            var stateBehaviour2 = new TestStateBehaviour();
            var stateBehaviour3 = Substitute.For <IStateBehaviour>();

            fsm.AddWithBehaviours(stateId1, stateBehaviour1, stateBehaviour2, stateBehaviour3);

            var behaviors = fsm.GetBehavioursOf <TestStateBehaviour, TState, TTrigger>(stateId1);

            Assert.IsTrue(behaviors.Length == 2);
            Assert.IsTrue(behaviors.Contains(stateBehaviour1));
            Assert.IsTrue(behaviors.Contains(stateBehaviour2));
        }
コード例 #6
0
ファイル: StateTests.cs プロジェクト: Diebanez/LudredStates
        public void TestAddBehaviour()
        {
            var state = new State();

            var behaviourTestNumber = Random.Range(1, 10);
            var behaviours          = new TestStateBehaviour[behaviourTestNumber];

            for (int i = 0; i < behaviourTestNumber; i++)
            {
                behaviours[i] = new TestStateBehaviour();
            }

            for (int i = 0; i < behaviourTestNumber; i++)
            {
                state.AddBehaviour(behaviours[i]);
                Assert.True(state.Behaviours.Length == i + 1);
                Assert.True(state.Behaviours[i] == behaviours[i]);
            }

            for (int i = 0; i < behaviourTestNumber; i++)
            {
                Assert.True(behaviours[i] == state.Behaviours[i]);
            }
        }