-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bay_door_v1.py
34 lines (28 loc) · 1.12 KB
/
test_bay_door_v1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import unittest
from bay_door_v1 import *
from test_helpers import *
# Define expected behavior
expected_transitions_by_state = namify([
['', CLOSING_STATE, 'ex', 'ex'], # for OPEN_STATE
[OPENING_STATE, '', 'ex', 'ex'], # for CLOSED_STATE
['', CLOSING_STATE, OPEN_STATE, 'ex'], # for OPENING_STATE
[OPENING_STATE, '', 'ex', CLOSED_STATE] # for CLOSING_STATE
], STATE_NAMES)
class BayDoorV1(unittest.TestCase):
def test_matrix(self):
sm = StateMachine()
problems = []
# Artificially place state machine in a state, and test every event to see if
# it triggers the expected transition.
for state in range(len(STATE_NAMES)):
for event in range(len(EVENT_NAMES)):
sm.state = state
transition = expected_transitions_by_state[state][event]
outcome = check_transition(sm, event, transition, STATE_NAMES, EVENT_NAMES)
if outcome:
problems.append(outcome)
if problems:
msg = '\n'.join(problems)
self.fail(msg)
if __name__ == '__main__':
unittest.main()