We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
example:
import unittest class StateMachine: def __init__(self, initial_state): self.state = initial_state def transition(self, event): self.state = self.state.transition(event) class State: def transition(self, event): raise NotImplementedError class InitialState(State): def transition(self, event): if event == "start": return StartedState() return self class StartedState(State): def transition(self, event): if event == "stop": return StoppedState() return self class StoppedState(State): def transition(self, event): if event == "start": return StartedState() return self class TestStateMachine(unittest.TestCase): def test_state_machine(self): machine = StateMachine(InitialState()) # Test initial state self.assertEqual(machine.state.__class__, InitialState) # Test transition to StartedState machine.transition("start") self.assertEqual(machine.state.__class__, StartedState) # Test transition to StoppedState machine.transition("stop") self.assertEqual(machine.state.__class__, StoppedState) # Test transition back to StartedState machine.transition("start") self.assertEqual(machine.state.__class__, StartedState) if __name__ == "__main__": unittest.main()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
example:
The text was updated successfully, but these errors were encountered: