Ejemplo n.º 1
0
        public void AutoAdvanceThroughStates()
        {
            var fsm = new TutorialManagerFSM();

            fsm.dispatcher = new MockStateDispatcher();
            var dispatcher = (MockStateDispatcher)(fsm.dispatcher);

            fsm.stateList = aListOfStates;

            fsm.NextState();

            Assert.AreEqual(1, dispatcher.fireCount, "one (enter) event fired");
            Assert.AreEqual(0, fsm.index, "fsm index should be 0");
            Assert.That(aListOfStates[0], Is.EqualTo(dispatcher.lastEnterFired), string.Format("should have entered {0}", aListOfStates[0]));
            Assert.IsNull(dispatcher.lastExitFired, "exit should not have fired");

            fsm.NextState();

            Assert.AreEqual(3, dispatcher.fireCount, "three events should have fired");
            Assert.AreEqual(1, fsm.index, "fsm index should be 1");
            Assert.That(aListOfStates[0], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[0]));
            Assert.That(aListOfStates[1], Is.EqualTo(dispatcher.lastEnterFired), string.Format("should have entered {0}", aListOfStates[1]));
            Assert.That(fsm.state, Is.EqualTo(aListOfStates[1]), string.Format("current state should be {0}", aListOfStates[1]));

            fsm.NextState();
            Assert.AreEqual(5, dispatcher.fireCount, "5 events should have fired");
            fsm.NextState();
            Assert.AreEqual(7, dispatcher.fireCount, "7 events should have fired");
            fsm.NextState();
            Assert.AreEqual(9, dispatcher.fireCount, "9 events should have fired");

            Assert.AreEqual(4, fsm.index, "fsm index should be 4");
            Assert.That(aListOfStates[3], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[3]));
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastEnterFired), string.Format("should have entered {0}", aListOfStates[4]));
            Assert.That(fsm.state, Is.EqualTo(aListOfStates[4]), string.Format("current state should be {0}", aListOfStates[4]));

            fsm.NextState();
            Assert.AreEqual(10, dispatcher.fireCount, "10 events should have fired");
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[4]));
            Assert.AreEqual(-1, fsm.index, "fsm index should be -1");
            Assert.IsTrue(string.IsNullOrEmpty(fsm.state), "current state should be empty");

            Assert.IsTrue(fsm.complete, "FSM should be complete");

            // Monkey bashing
            fsm.NextState();
            fsm.NextState();
            fsm.NextState();
            fsm.NextState();

            Assert.AreEqual(10, dispatcher.fireCount, "10 events should have fired (no change)");
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastExitFired), string.Format("last exit should be unchanged at {0}", aListOfStates[4]));
            Assert.IsTrue(string.IsNullOrEmpty(fsm.state), "current state should be empty");
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastEnterFired), string.Format("last enter should be unchanged at {0}", aListOfStates[4]));

            Assert.IsTrue(fsm.complete, "FSM should still be complete");
        }
Ejemplo n.º 2
0
        public void GoToArbitraryStates()
        {
            var fsm = new TutorialManagerFSM();

            fsm.dispatcher = new MockStateDispatcher();

            var dispatcher = (MockStateDispatcher)(fsm.dispatcher);

            fsm.stateList = aListOfStates;

            // Go to state 3
            fsm.GoToState(aListOfStates[3]);

            Assert.AreEqual(1, dispatcher.fireCount, "one (enter) event fired");
            Assert.AreEqual(3, fsm.index, "fsm index should be 3");
            Assert.That(aListOfStates[3], Is.EqualTo(dispatcher.lastEnterFired), string.Format("should have entered {0}", aListOfStates[3]));
            Assert.That(fsm.state, Is.EqualTo(aListOfStates[3]), string.Format("current state should be {0}", aListOfStates[3]));
            Assert.IsNull(dispatcher.lastExitFired, "exit should not have fired");

            // Advance to state 4
            fsm.NextState();

            Assert.AreEqual(3, dispatcher.fireCount, "three events should have fired");
            Assert.AreEqual(4, fsm.index, "fsm index should be 4");
            Assert.That(fsm.state, Is.EqualTo(aListOfStates[4]), string.Format("current state should be {0}", aListOfStates[4]));
            Assert.That(aListOfStates[3], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[3]));
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastEnterFired), string.Format("entered should still be {0}", aListOfStates[4]));

            // Jump to state 0
            fsm.GoToState(aListOfStates[0]);

            Assert.AreEqual(5, dispatcher.fireCount, "five events fired");
            Assert.AreEqual(0, fsm.index, "fsm index should be 0");
            Assert.That(aListOfStates[0], Is.EqualTo(dispatcher.lastEnterFired), string.Format("should have entered {0}", aListOfStates[0]));
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[4]));
            Assert.That(fsm.state, Is.EqualTo(aListOfStates[0]), string.Format("current state should be {0}", aListOfStates[0]));
        }
Ejemplo n.º 3
0
        public void ManualAdvanceThroughStates()
        {
            bool fsmShouldAutoAdvance = false;

            var fsm = new TutorialManagerFSM(fsmShouldAutoAdvance);

            fsm.dispatcher = new MockStateDispatcher();

            var dispatcher = (MockStateDispatcher)(fsm.dispatcher);

            fsm.stateList = aListOfStates;

            // Enter state 0
            fsm.NextState();

            Assert.AreEqual(1, dispatcher.fireCount, "one (enter) event fired");
            Assert.AreEqual(0, fsm.index, "fsm index should be 0");
            Assert.That(aListOfStates[0], Is.EqualTo(dispatcher.lastEnterFired), string.Format("should have entered {0}", aListOfStates[0]));
            Assert.That(fsm.state, Is.EqualTo(aListOfStates[0]), string.Format("current state should be {0}", aListOfStates[0]));
            Assert.IsNull(dispatcher.lastExitFired, "exit should not have fired");

            // Exit state 0
            fsm.NextState();

            Assert.AreEqual(2, dispatcher.fireCount, "two events should have fired");
            Assert.AreEqual(-1, fsm.index, "fsm index should be -1");
            Assert.That(aListOfStates[0], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[0]));
            Assert.IsTrue(string.IsNullOrEmpty(fsm.state), "current state should be empty");
            Assert.That(aListOfStates[0], Is.EqualTo(dispatcher.lastEnterFired), string.Format("entered should still be {0}", aListOfStates[0]));

            // Enter state 1
            fsm.NextState();

            Assert.AreEqual(3, dispatcher.fireCount, "three events should have fired");
            Assert.AreEqual(1, fsm.index, "fsm index should be 1");
            Assert.That(fsm.state, Is.EqualTo(aListOfStates[1]), string.Format("current state should be {0}", aListOfStates[1]));
            Assert.That(aListOfStates[0], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[0]));
            Assert.That(aListOfStates[1], Is.EqualTo(dispatcher.lastEnterFired), string.Format("entered should still be {0}", aListOfStates[1]));

            // Exit state 1
            fsm.NextState();

            Assert.AreEqual(4, dispatcher.fireCount, "four events should have fired");
            Assert.AreEqual(-1, fsm.index, "fsm index should be -1");
            Assert.That(aListOfStates[1], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[1]));
            Assert.IsTrue(string.IsNullOrEmpty(fsm.state), "current state should be empty");
            Assert.That(aListOfStates[1], Is.EqualTo(dispatcher.lastEnterFired), string.Format("entered should still be {0}", aListOfStates[1]));

            // Enter/exit state 2
            fsm.NextState();
            fsm.NextState();
            Assert.AreEqual(6, dispatcher.fireCount, "6 events should have fired");

            // Enter/exit state 3
            fsm.NextState();
            fsm.NextState();
            Assert.AreEqual(8, dispatcher.fireCount, "8 events should have fired");

            // Enter/exit state 4
            fsm.NextState();
            fsm.NextState();
            Assert.AreEqual(10, dispatcher.fireCount, "10 events should have fired");

            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastExitFired), string.Format("should have exited {0}", aListOfStates[4]));
            Assert.IsTrue(string.IsNullOrEmpty(fsm.state), "current state should be empty");
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastEnterFired), string.Format("entered should still be {0}", aListOfStates[4]));
            Assert.IsTrue(fsm.complete, "FSM should be complete");

            // Monkey-bashing
            fsm.NextState();
            fsm.NextState();
            fsm.NextState();

            Assert.AreEqual(10, dispatcher.fireCount, "10 events should have fired (no change)");
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastExitFired), string.Format("last exit should be unchanged at {0}", aListOfStates[4]));
            Assert.IsTrue(string.IsNullOrEmpty(fsm.state), "current state should be empty");
            Assert.That(aListOfStates[4], Is.EqualTo(dispatcher.lastEnterFired), string.Format("last enter should be unchanged at {0}", aListOfStates[4]));

            Assert.IsTrue(fsm.complete, "FSM should still be complete");
        }