Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/tests/coretests.py
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-03-18 19:04:33 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-03-18 19:04:33 (GMT)
commit79ffdf4c4c38e0064f25db06685af9156b39e679 (patch)
treecb1f2934acd54e984c65cab7523fc1db4a71cbcc /src/sugar/tutorius/tests/coretests.py
parentf5d13236595810710aaab6c9622a12dc86045166 (diff)
TutoriusV2 : Correcting constructors for States and FSMs, exploration
tests
Diffstat (limited to 'src/sugar/tutorius/tests/coretests.py')
-rw-r--r--src/sugar/tutorius/tests/coretests.py56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/sugar/tutorius/tests/coretests.py b/src/sugar/tutorius/tests/coretests.py
index 086c833..297a7c3 100644
--- a/src/sugar/tutorius/tests/coretests.py
+++ b/src/sugar/tutorius/tests/coretests.py
@@ -100,7 +100,7 @@ class FakeEventFilter(TriggerEventFilter):
The difference between this one and the TriggerEventFilter is that the
tutorial's set_state will be called on the callback.
- Do not forget to add the do_callback() function.
+ Do not forget to add the do_callback() after creating the object.
"""
def set_tutorial(self, tutorial):
self.tutorial = tutorial
@@ -251,5 +251,59 @@ class FSMTest(unittest.TestCase):
assert act_second.active == False, "FSM did not teardown SECOND properly"
+class FSMExplorationTests(unittest.TestCase):
+ def buildFSM(self):
+ """
+ Create a sample FSM to play with in the rest of the tests.
+ """
+ st1 = State("INIT")
+ st1.add_action(CountAction())
+ st1.add_event_filter(TriggerEventFilter("Second"))
+ st1.add_event_filter(TriggerEventFilter("Third"))
+
+ st2 = State("Second")
+ st2.add_action(TrueWhileActiveAction())
+ st2.add_event_filter(TriggerEventFilter("Third"))
+ st2.add_event_filter(TriggerEventFilter("Fourth"))
+
+ st3 = State("Third")
+ st3.add_action(CountAction())
+ st3.add_action(TrueWhileActiveAction())
+
+ self.fsm = FiniteStateMachine("ExplorationTestingMachine")
+ self.fsm.add_state(st1)
+ self.fsm.add_state(st2)
+ self.fsm.add_state(st3)
+
+ def validate_following_states(self, in_name, out_name_list):
+ nextStates = self.fsm.get_following_states(in_name)
+ assert list(nextStates).sort() == list(out_name_list).sort(), \
+ "The following states for %s are wrong : got %s"%\
+ (in_name, str(nextStates))
+
+ def validate_previous_states(self, in_name, out_name_list):
+ prevStates = self.fsm.get_previous_states(in_name)
+ assert list(prevStates).sort() == list(out_name_list).sort(), \
+ "The following states for %s are wrong : got %s"%\
+ (in_name, str(prevStates))
+
+ def test_get_following_states(self):
+ self.buildFSM()
+ self.validate_following_states("INIT", ('Second', 'Third'))
+
+ self.validate_following_states("Second", ("Third", "Fourth"))
+
+ self.validate_following_states("Third", ())
+
+ def test_get_previous_states(self):
+ self.buildFSM()
+ self.validate_previous_states("INIT", ())
+
+ self.validate_previous_states("Second", ("INIT"))
+
+ self.validate_previous_states("Third", ("INIT", "Second"))
+
+ self.validate_previous_states("Fourth", ("Second"))
+
if __name__ == "__main__":
unittest.main()