Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/core.py')
-rw-r--r--tutorius/core.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/tutorius/core.py b/tutorius/core.py
index dd2435e..41089f1 100644
--- a/tutorius/core.py
+++ b/tutorius/core.py
@@ -258,6 +258,42 @@ class State(object):
tutorial.
"""
self._event_filters = []
+
+ def is_identical(self, otherState):
+ """
+ Compares two states and tells whether they contain the same states and
+
+` """
+ if not isinstance(otherState, State):
+ return False
+ if self.name != otherState.name:
+ return False
+
+ # Do they have the same actions?
+ if len(self._actions) != len(otherState._actions):
+ return False
+ for act in self._actions:
+ found = False
+ for otherAct in otherState._actions:
+ if act.is_identical(otherAct):
+ found = True
+ break
+ if found == False:
+ return False
+
+ # Do they have the same event filters?
+ if len(self._actions) != len(otherState._actions):
+ return False
+ for event in self._event_filters:
+ found = False
+ for otherEvent in otherState._event_filters:
+ if event.is_identical(otherEvent):
+ found = True
+ break
+ if found == False:
+ return False
+
+ return True
class FiniteStateMachine(State):
"""
@@ -526,3 +562,43 @@ class FiniteStateMachine(State):
for st in self._states.itervalues():
out_string += st.name + ", "
return out_string
+
+ def is_identical(self, otherFSM):
+ """
+ Compares the elements of two FSM to ensure and returns true if they have the
+ same set of states, containing the same actions and the same event filters.
+
+ @returns True if the two FSMs have the same content false otherwise
+ """
+ if not isinstance(otherFSM, FiniteStateMachine):
+ return False
+
+ if not (self.name == otherFSM.name) or \
+ not (self.start_state_name == otherFSM.start_state_name):
+ return False
+
+ if len(self._actions) != len(otherFSM._actions):
+ return False
+ # Test that we have all the same FSM level actions
+ for act in self._actions:
+ found = False
+ for otherAct in otherFSM._actions:
+ if act.is_identical(otherAct):
+ found = True
+ break
+ if found == False:
+ return False
+
+ if len(self._states) != len(otherFSM._states):
+ return False
+
+ for state in self._states.itervalues():
+ found = False
+ for otherState in otherFSM._states.itervalues():
+ if state.is_identical(otherState):
+ found = True
+ break
+ if found == False:
+ return False
+
+ return True