Exemplo n.º 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);
        }
Exemplo n.º 2
0
 private void CreateSimpleStatesAndMonitor(TestAction action, StateMachine m, int n)
 {
     for (int i = 0; i < n; i++)
     {
         var state = new SimpleState();
         action.Monitor(state);
         m.AddState(state);
     }
     action.Monitor(m);
 }
Exemplo n.º 3
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);
        }