-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
66 lines (49 loc) · 2.1 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import unittest
from src.color import construct_constraint_graph, greedy_vertex_color
from src.draw import draw, int_to_rgb
class TestColoring(unittest.TestCase):
def setUp(self):
self.routes_for_stops = [[0], [0, 1], [2], [1], [1], [2, 3], [2], [3]]
self.stops_for_routes = [[0, 1], [3, 1, 4], [2, 5, 6], [5, 7]]
def test_constraint_graph(self):
constraint_graph = construct_constraint_graph(
self.routes_for_stops,
self.stops_for_routes,
)
# There must be one set for each route/vertex.
self.assertTrue(len(constraint_graph) == len(self.stops_for_routes))
# As described in module docstring.
self.assertTrue(constraint_graph[0] == {1})
self.assertTrue(constraint_graph[1] == {0})
self.assertTrue(constraint_graph[2] == {3})
self.assertTrue(constraint_graph[3] == {2})
def test_coloring(self):
constraint_graph = construct_constraint_graph(
self.routes_for_stops,
self.stops_for_routes,
)
coloring = greedy_vertex_color(constraint_graph)
# There must be one color for each route/vertex.
self.assertTrue(len(coloring) == len(self.stops_for_routes))
# As described above, neighbors should be different colors.
self.assertTrue(coloring[0] != coloring[1])
self.assertTrue(coloring[2] != coloring[3])
class TestDraw(unittest.TestCase):
def setUp(self):
self.routes_for_stops = [[0], [0, 1], [2], [1], [1], [2, 3], [2], [3]]
self.stops_for_routes = [[0, 1], [3, 1, 4], [2, 5, 6], [5, 7]]
def test_int_to_rgb(self):
res1 = int_to_rgb(1)
res2 = int_to_rgb(2)
self.assertTrue(isinstance(res1, str))
self.assertTrue(res1 != res2)
def test_draw(self):
constraint_graph = construct_constraint_graph(
self.routes_for_stops,
self.stops_for_routes,
)
coloring = greedy_vertex_color(constraint_graph)
nodes = draw(constraint_graph, coloring)
self.assertEqual(4, nodes)
if __name__ == '__main__':
unittest.main()