-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_state.py
50 lines (41 loc) · 1.24 KB
/
test_state.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Tests the states
"""
import unittest
from pyformlang.finite_automaton import State
class TestState(unittest.TestCase):
""" Test the states
"""
def test_can_create(self):
""" Tests the creation of states
"""
self.assertIsNotNone(State(""))
self.assertIsNotNone(State(1))
def test_repr(self):
""" Tests the representation of states
"""
state1 = State("ABC")
self.assertEqual(str(state1), "ABC")
state2 = State(1)
self.assertEqual(str(state2), "1")
def test_eq(self):
""" Tests the equality of states
"""
state1 = State("ABC")
state2 = State(1)
state3 = State("ABC")
self.assertEqual(state1, state3)
self.assertTrue(state2 == 1)
self.assertNotEqual(state2, state3)
self.assertEqual(state2, 1)
self.assertNotEqual(state1, state2)
def test_hash(self):
""" Tests the hashing of states
"""
state1 = hash(State("ABC"))
state2 = hash(State(1))
state3 = hash(State("ABC"))
self.assertIsInstance(state1, int)
self.assertEqual(state1, state3)
self.assertNotEqual(state2, state3)
self.assertNotEqual(state1, state2)