def test__eq__false_by_transition(self): different_transitions = ((1, C, 0, D), (1, D, 0, D), (0, C, 1, D), (0, D, 1, C)) new_two_state = SimpleFSM(transitions=different_transitions, initial_state=1) self.assertFalse(new_two_state.__eq__(self.two_state))
def test__ne__(self): new_two_state = SimpleFSM( transitions=self.two_state_transition, initial_state=1 ) self.assertFalse(new_two_state.__ne__(self.two_state)) new_two_state.move(C) self.assertTrue(new_two_state.__ne__(self.two_state))
def setUp(self): self.two_state_transition = ( (1, C, 0, C), (1, D, 0, D), (0, C, 1, D), (0, D, 1, C), ) self.two_state = SimpleFSM(transitions=self.two_state_transition, initial_state=1)
def setUp(self): self.two_state_transition = ( (1, C, 0, C), (1, D, 0, D), (0, C, 1, D), (0, D, 1, C), ) self.two_state = SimpleFSM( transitions=self.two_state_transition, initial_state=1 )
def test__eq__true(self): new_two_state = SimpleFSM(transitions=self.two_state_transition, initial_state=1) self.assertTrue(new_two_state.__eq__(self.two_state)) new_two_state.move(C) self.two_state.move(D) self.assertTrue(new_two_state.__eq__(self.two_state))
class TestSimpleFSM(unittest.TestCase): def setUp(self): self.two_state_transition = ((1, C, 0, C), (1, D, 0, D), (0, C, 1, D), (0, D, 1, C)) self.two_state = SimpleFSM(transitions=self.two_state_transition, initial_state=1) def test__eq__true(self): new_two_state = SimpleFSM(transitions=self.two_state_transition, initial_state=1) self.assertTrue(new_two_state.__eq__(self.two_state)) new_two_state.move(C) self.two_state.move(D) self.assertTrue(new_two_state.__eq__(self.two_state)) def test__eq__false_by_state(self): new_two_state = SimpleFSM(transitions=self.two_state_transition, initial_state=0) self.assertFalse(new_two_state.__eq__(self.two_state)) def test__eq__false_by_transition(self): different_transitions = ((1, C, 0, D), (1, D, 0, D), (0, C, 1, D), (0, D, 1, C)) new_two_state = SimpleFSM(transitions=different_transitions, initial_state=1) self.assertFalse(new_two_state.__eq__(self.two_state)) def test__eq__false_by_not_SimpleFSM(self): self.assertFalse(self.two_state.__eq__(3)) def test__ne__(self): new_two_state = SimpleFSM(transitions=self.two_state_transition, initial_state=1) self.assertFalse(new_two_state.__ne__(self.two_state)) new_two_state.move(C) self.assertTrue(new_two_state.__ne__(self.two_state)) def test_move(self): self.assertEqual(self.two_state.move(C), C) self.assertEqual(self.two_state.state, 0) self.assertEqual(self.two_state.move(C), D) self.assertEqual(self.two_state.state, 1) self.assertEqual(self.two_state.move(D), D) self.assertEqual(self.two_state.state, 0) self.assertEqual(self.two_state.move(D), C) self.assertEqual(self.two_state.state, 1) def test_bad_transitions_raise_error(self): bad_transitions = [(1, C, 0, D), (1, D, 0, D), (0, C, 1, D)] self.assertRaises(ValueError, SimpleFSM, transitions=bad_transitions, initial_state=1) def test_bad_initial_state_raises_error(self): self.assertRaises(ValueError, SimpleFSM, transitions=self.two_state_transition, initial_state=5) def test_state_setter_raises_error_for_bad_input(self): with self.assertRaises(ValueError) as cm: self.two_state.state = 5 error_msg = cm.exception.args[0] self.assertEqual(error_msg, 'state: 5 does not have values for both C and D')
def test__eq__false_by_state(self): new_two_state = SimpleFSM(transitions=self.two_state_transition, initial_state=0) self.assertFalse(new_two_state.__eq__(self.two_state))
def test__eq__false_by_state(self): new_two_state = SimpleFSM( transitions=self.two_state_transition, initial_state=0 ) self.assertFalse(new_two_state.__eq__(self.two_state))
class TestSimpleFSM(unittest.TestCase): def setUp(self): self.two_state_transition = ( (1, C, 0, C), (1, D, 0, D), (0, C, 1, D), (0, D, 1, C), ) self.two_state = SimpleFSM( transitions=self.two_state_transition, initial_state=1 ) def test__eq__true(self): new_two_state = SimpleFSM( transitions=self.two_state_transition, initial_state=1 ) self.assertTrue(new_two_state.__eq__(self.two_state)) new_two_state.move(C) self.two_state.move(D) self.assertTrue(new_two_state.__eq__(self.two_state)) def test__eq__false_by_state(self): new_two_state = SimpleFSM( transitions=self.two_state_transition, initial_state=0 ) self.assertFalse(new_two_state.__eq__(self.two_state)) def test__eq__false_by_transition(self): different_transitions = ((1, C, 0, D), (1, D, 0, D), (0, C, 1, D), (0, D, 1, C)) new_two_state = SimpleFSM(transitions=different_transitions, initial_state=1) self.assertFalse(new_two_state.__eq__(self.two_state)) def test__eq__false_by_not_SimpleFSM(self): self.assertFalse(self.two_state.__eq__(3)) def test__ne__(self): new_two_state = SimpleFSM( transitions=self.two_state_transition, initial_state=1 ) self.assertFalse(new_two_state.__ne__(self.two_state)) new_two_state.move(C) self.assertTrue(new_two_state.__ne__(self.two_state)) def test_move(self): self.assertEqual(self.two_state.move(C), C) self.assertEqual(self.two_state.state, 0) self.assertEqual(self.two_state.move(C), D) self.assertEqual(self.two_state.state, 1) self.assertEqual(self.two_state.move(D), D) self.assertEqual(self.two_state.state, 0) self.assertEqual(self.two_state.move(D), C) self.assertEqual(self.two_state.state, 1) def test_bad_transitions_raise_error(self): bad_transitions = ((1, C, 0, D), (1, D, 0, D), (0, C, 1, D)) self.assertRaises( ValueError, SimpleFSM, transitions=bad_transitions, initial_state=1 ) def test_bad_initial_state_raises_error(self): self.assertRaises( ValueError, SimpleFSM, transitions=self.two_state_transition, initial_state=5, ) def test_state_setter_raises_error_for_bad_input(self): with self.assertRaises(ValueError) as cm: self.two_state.state = 5 error_msg = cm.exception.args[0] self.assertEqual(error_msg, "state: 5 does not have values for both C and D")