-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_graph.py
49 lines (39 loc) · 1.17 KB
/
test_graph.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
import unittest
from graph import Graph
class GraphTest(unittest.TestCase):
"""
0 --> 1 --> 2
^ ^
| |
3 --> 4 --> 5
"""
data = [
'0 1',
'1 2',
'3 0',
'3 4',
'4 1',
'4 5'
]
def test_edges(self):
graph = Graph(self.data)
self.assertSetEqual(graph.edges(0), {1})
self.assertSetEqual(graph.edges(1), {2})
self.assertSetEqual(graph.edges(2), set())
self.assertSetEqual(graph.edges(3), {0, 4})
self.assertSetEqual(graph.edges(4), {1, 5})
self.assertSetEqual(graph.edges(5), set())
def test_reversed_edges(self):
graph = Graph(self.data)
graph.reverse()
self.assertSetEqual(graph.edges(0), {3})
self.assertSetEqual(graph.edges(1), {0, 4})
self.assertSetEqual(graph.edges(2), {1})
self.assertSetEqual(graph.edges(3), set())
self.assertSetEqual(graph.edges(4), {3})
self.assertSetEqual(graph.edges(5), {4})
def test_vertices(self):
graph = Graph(self.data)
self.assertEqual(sorted(graph.vertices()), [0, 1, 3, 4])
if __name__ == '__main__':
unittest.main()