Exemple #1
0
        public void EpsilonTransitions()
        {
            TestSequentialTrigger trigger      = new TestSequentialTrigger(1);
            TestAction            action       = new TestAction();
            StateMachine          stateMachine = new StateMachine();

            for (int i = 0; i < 4; i++)
            {
                var state = new SimpleState();
                action.Monitor(state);
                stateMachine.AddState(state);
            }
            action.Monitor(stateMachine);
            stateMachine.AddEntryTransition(0, null);
            stateMachine.AddExitTransition(3, null);
            stateMachine.AddTransition(0, 1, null);
            stateMachine.AddTransition(1, 2, trigger[0]);
            stateMachine.AddTransition(2, 3, null);
            stateMachine.Run();
            Assert.AreEqual(1, stateMachine.ActiveStateId);
            trigger.Run(0);
            action.CompareResults(new List <string>()
            {
                "enter: 0",
                "enter: 0", "leave: 0",
                "enter: 1", "leave: 1",
                "enter: 2", "leave: 2",
                "enter: 3", "leave: 3",
            });
            Assert.AreEqual(State.ExitStateId, stateMachine.ActiveStateId);
        }
Exemple #2
0
        public void SimpleStatesOnly()
        {
            TestSequentialTrigger trigger      = new TestSequentialTrigger(8);
            TestAction            action       = new TestAction();
            StateMachine          stateMachine = new StateMachine();

            for (int i = 0; i < 4; i++)
            {
                var state = new SimpleState();
                action.Monitor(state);
                stateMachine.AddState(state);
            }
            action.Monitor(stateMachine);
            stateMachine.AddEntryTransition(0, trigger[7]);
            stateMachine.AddExitTransition(1, trigger[6]);
            stateMachine.AddTransition(0, 1, trigger[0]);
            stateMachine.AddTransition(0, 3, trigger[1]);
            stateMachine.AddTransition(1, 2, trigger[4]);
            stateMachine.AddTransition(2, 0, trigger[3]);
            stateMachine.AddTransition(3, 1, trigger[5]);
            stateMachine.AddTransition(3, 2, trigger[2]);
            Assert.AreEqual(State.InvalidStateId, stateMachine.ActiveStateId);
            Assert.AreEqual("-3", stateMachine.GenerateActiveStateDescriptor());
            stateMachine.Run();
            Assert.AreEqual(State.EntryStateId, stateMachine.ActiveStateId);
            Assert.AreEqual("-2", stateMachine.GenerateActiveStateDescriptor());
            trigger.Run(7, 1, 2, 3, 0, 4, 3, 1, 5); // loop around
            Assert.AreEqual("1.-1", stateMachine.GenerateActiveStateDescriptor());
            trigger.Run(0, 1, 2, 3, 5);             // invalid triggers
            Assert.AreEqual("1.-1", stateMachine.GenerateActiveStateDescriptor());
            trigger.Run(6);                         // to the end
            Assert.AreEqual("-1", stateMachine.GenerateActiveStateDescriptor());
            action.CompareResults(new List <string>()
            {
                "enter: 0",             // outer state machine
                "enter: 0", "leave: 0", // state 0
                "enter: 3", "leave: 3",
                "enter: 2", "leave: 2",
                "enter: 0", "leave: 0",
                "enter: 1", "leave: 1",
                "enter: 2", "leave: 2",
                "enter: 0", "leave: 0",
                "enter: 3", "leave: 3",
                "enter: 1", "leave: 1",
            });
            Assert.AreEqual(State.ExitStateId, stateMachine.ActiveStateId);
        }
Exemple #3
0
        public RecursiveMachineTestBase()
        {
            trigger0   = new TestSequentialTrigger(2);
            trigger00  = new TestSequentialTrigger(3);
            trigger01  = new TestSequentialTrigger(4);
            trigger010 = new TestSequentialTrigger(2);

            stateMachine00 = new StateMachine();
            CreateSimpleStatesAndMonitor(action, stateMachine00, 3);
            stateMachine00.AddEntryTransition(0, null);
            stateMachine00.AddExitTransition(2, null);
            stateMachine00.AddTransition(0, 1, trigger00[0]);
            stateMachine00.AddTransition(2, 0, trigger00[2]);
            stateMachine00.AddTransition(1, 2, trigger00[1]);

            stateMachine010 = new StateMachine();
            CreateSimpleStatesAndMonitor(action, stateMachine010, 1);
            stateMachine010.AddEntryTransition(0, trigger010[0]);
            stateMachine010.AddExitTransition(0, trigger010[1]);

            stateMachine01 = new StateMachine();
            stateMachine01.AddState(stateMachine010);
            CreateSimpleStatesAndMonitor(action, stateMachine01, 1);
            stateMachine01.AddEntryTransition(0, trigger01[1]);
            stateMachine01.AddExitTransition(0, trigger01[2]);
            stateMachine01.AddTransition(0, 1, trigger01[3]);
            stateMachine01.AddTransition(1, 0, trigger01[0]);

            stateMachine0 = new StateMachine();
            stateMachine0.AddState(stateMachine00);
            stateMachine0.AddState(stateMachine01);
            CreateSimpleStatesAndMonitor(action, stateMachine0, 1);
            stateMachine0.AddEntryTransition(0, null); // No exit transition
            stateMachine0.AddTransition(0, 1, null);
            stateMachine0.AddTransition(1, 0, trigger0[1]);
            stateMachine0.AddTransition(1, 2, null);
            stateMachine0.AddTransition(2, 0, trigger0[0]);
        }