diff options
author | mike <michael.jmontcalm@gmail.com> | 2009-10-02 22:24:56 (GMT) |
---|---|---|
committer | mike <michael.jmontcalm@gmail.com> | 2009-10-02 22:24:56 (GMT) |
commit | cf40c1951f4f0f26090226fb4969ca147341a031 (patch) | |
tree | b3bb17043645aff11a93940eba90d7488bcebf45 /tutorius/core.py | |
parent | 09b2ea3369df967309f030f9196c2f9861bc1b2c (diff) |
LP 439980 : Refactored the XMLSerializer to support complex components; Corrected specs for the addons properties and constructor parameters names; Moved all existing actions and events to components (except a few left in code for testing purposes)
Diffstat (limited to 'tutorius/core.py')
-rw-r--r-- | tutorius/core.py | 76 |
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 |