-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sgraph.py
More file actions
executable file
·58 lines (41 loc) · 1.76 KB
/
test_sgraph.py
File metadata and controls
executable file
·58 lines (41 loc) · 1.76 KB
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
#! env python3
import unittest
import sgraph
class TestSgraph(unittest.TestCase):
def setUp(self):
graph = []
with open('graph') as f: # one per line FIXME fixture?
for edge in f.readlines():
src, dest, *cost = list(edge.strip())
cost = int(''.join(cost)) # bc maybe size >= 10; FIXME multi-char cities needs diff input format
graph.append((src, dest, cost))
self.sgl = sgraph.SGraph(graph)
def test01(self):
self.assertEqual(9, self.sgl.route_distance(['A', 'B', 'C']))
def test02(self):
self.assertEqual(5, self.sgl.route_distance(['A', 'D']))
def test03(self):
self.assertEqual(13, self.sgl.route_distance(['A', 'D', 'C']))
def test04(self):
self.assertEqual(22, self.sgl.route_distance(['A', 'E', 'B', 'C', 'D']))
def test05(self):
self.assertRaises(sgraph.SGraph.NoSuchRoute, self.sgl.route_distance, ['A', 'E', 'D'])
try:
x = self.sgl.route_distance(['A', 'E', 'D'])
print(str(x)) # never
except sgraph.SGraph.NoSuchRoute as e:
self.assertEqual('NO SUCH ROUTE', str(e))
def test06(self):
self.assertEqual(2, self.sgl.count_routes_max_stops('C', 'C', 3))
def test07(self):
self.assertEqual(3, self.sgl.count_routes_exact_stops('A', 'C', 4))
def test08(self):
self.assertEqual(9, self.sgl.shortest_route('A', 'C'))
def test09(self):
self.assertEqual(9, self.sgl.shortest_route('B', 'B'))
def test10(self):
self.assertEqual(7, self.sgl.count_routes_max_distance('C', 'C', 30))
def test11(self):
self.assertEqual(float('inf'), self.sgl.shortest_route('A', 'A'))
if __name__ == '__main__':
unittest.main()