def test_addTerminalState(self): """ L{TransitionTable.addTerminalState} returns a L{TransitionTable} that includes the given state in its table with no transitions defined. """ table = TransitionTable() more = table.addTerminalState("foo") self.assertEqual({"foo": {}}, more.table)
def test_nextStateNotMissingIfInitial(self): """ L{MissingTransitionNextState} is not raised if a value defined by C{state} appears nowhere in C{transitions} as a next state but is given as C{initial}. """ transitions = TransitionTable() transitions = transitions.addTransition( MoreState.amber, Input.apple, [Output.aardvark], MoreState.amber) transitions = transitions.addTerminalState(MoreState.blue) constructFiniteStateMachine( Input, Output, MoreState, transitions, MoreState.blue, [], {}, NULL_WORLD)
def test_nextStateNotMissingIfInitial(self): """ L{MissingTransitionNextState} is not raised if a value defined by C{state} appears nowhere in C{transitions} as a next state but is given as C{initial}. """ transitions = TransitionTable() transitions = transitions.addTransition(MoreState.amber, Input.apple, [Output.aardvark], MoreState.amber) transitions = transitions.addTerminalState(MoreState.blue) constructFiniteStateMachine(Input, Output, MoreState, transitions, MoreState.blue, [], {}, NULL_WORLD)
def test_missingTransitionNextState(self): """ L{MissingTransitionNextState} is raised if any of the values defined by C{state} appears nowhere in C{transitions} as a next state. """ transitions = TransitionTable() transitions = transitions.addTransition( MoreState.amber, Input.apple, [Output.aardvark], MoreState.amber) transitions = transitions.addTerminalState(MoreState.blue) exc = self.assertRaises( MissingTransitionNextState, constructFiniteStateMachine, Input, Output, MoreState, transitions, MoreState.amber, [], {}, NULL_WORLD) self.assertEqual(({MoreState.blue},), exc.args)
def test_missingTransitionNextState(self): """ L{MissingTransitionNextState} is raised if any of the values defined by C{state} appears nowhere in C{transitions} as a next state. """ transitions = TransitionTable() transitions = transitions.addTransition(MoreState.amber, Input.apple, [Output.aardvark], MoreState.amber) transitions = transitions.addTerminalState(MoreState.blue) exc = self.assertRaises(MissingTransitionNextState, constructFiniteStateMachine, Input, Output, MoreState, transitions, MoreState.amber, [], {}, NULL_WORLD) self.assertEqual(({MoreState.blue}, ), exc.args)
class IFood(Interface): radius = Attribute("The radius of the food (all food is spherical)") @implementer(IFood) class Gravenstein(trivialInput(Input.apple)): # Conveniently, apples are approximately spherical. radius = 3 TRANSITIONS = TransitionTable() TRANSITIONS = TRANSITIONS.addTransition( MoreState.amber, Input.apple, [Output.aardvark], MoreState.blue) TRANSITIONS = TRANSITIONS.addTerminalState(MoreState.blue) class FiniteStateMachineTests(TestCase): """ Tests for the L{IFiniteStateMachine} provider returned by L{constructFiniteStateMachine}. """ def setUp(self): self.animals = [] self.initial = MoreState.amber self.world = AnimalWorld(self.animals) self.fsm = constructFiniteStateMachine( Input, Output, MoreState, TRANSITIONS, self.initial, [Gravenstein], {Output.aardvark: IFood},
class IFood(Interface): radius = Attribute("The radius of the food (all food is spherical)") @implementer(IFood) class Gravenstein(trivialInput(Input.apple)): # Conveniently, apples are approximately spherical. radius = 3 TRANSITIONS = TransitionTable() TRANSITIONS = TRANSITIONS.addTransition(MoreState.amber, Input.apple, [Output.aardvark], MoreState.blue) TRANSITIONS = TRANSITIONS.addTerminalState(MoreState.blue) class FiniteStateMachineTests(TestCase): """ Tests for the L{IFiniteStateMachine} provider returned by L{constructFiniteStateMachine}. """ def setUp(self): self.animals = [] self.initial = MoreState.amber self.world = AnimalWorld(self.animals) self.fsm = constructFiniteStateMachine( Input, Output, MoreState, TRANSITIONS, self.initial, [Gravenstein], {Output.aardvark: IFood}, MethodSuffixOutputer(self.world))