public void TransitionWait()
        {
            //Variables
            var log = new List <string>();
            var i   = 0;

            //States
            var start  = new TestState("Start", log);
            var state1 = new TestState("State1", log);
            var state2 = new TestState("State2", log);
            var end    = new TestState("End", log);

            var stateMachine = new StateMachine()
                               .AddNode(start)
                               .AddNode(state1)
                               .AddNode(state2)
                               .AddNode(end);

            var t = new Transition(start, state2, () =>
            {
                log.Add("Edge1");
                i++;
                return(i >= 3);
            });

            stateMachine.AddEdge("Start", "State1", () => { return(false); })
            .AddEdge(t)
            .AddEdge("State2", "End", () => { return(true); });

            stateMachine.Invoke();

            Assert.AreEqual("Start->Edge1->Edge1->Edge1->State2->End", string.Join("->", log));
        }
Example #2
0
        public void SelfReference()
        {
            var log = new List <string>();

            var stateMachine = new StateMachine();

            stateMachine.AddNode(new TestState("Start", log));
            stateMachine.AddNode(new TestState("State1", log));
            stateMachine.AddNode(new TestState("State2", log));
            stateMachine.AddNode(new TestState("End", log));
            stateMachine.AddEdge("Start", "State1", () => { return(true); });
            stateMachine.AddEdge("State1", "State1", () => { return(false); });
            stateMachine.AddEdge("State1", "State2", () => { return(true); });
            stateMachine.AddEdge("State2", "End", () => { return(true); });

            stateMachine.Invoke();

            Assert.AreEqual("Start->State1->State2->End", string.Join("->", log));
        }