-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdijkstra_test.py
38 lines (31 loc) · 995 Bytes
/
dijkstra_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
import unittest
from dijkstra import *
class TestDijkstra(unittest.TestCase):
def setUp(self):
pass
def test_simple_path(self):
root = Node(1)
n2, n5 = Node(2), Node(5)
target = Node(7)
n2.add_neighbor(target)
n5.add_neighbor(target)
root.add_neighbor(n2)
root.add_neighbor(n5)
path = dijkstra([root,n2,n5,target], root, target)
self.assertEqual(value_sum(path), 10)
def test_bidirectional_links(self):
root = Node(1)
n2, n5 = Node(2), Node(5)
target = Node(7)
root.add_neighbor(n2)
n2.add_neighbor(root)
root.add_neighbor(n5)
n5.add_neighbor(root)
n2.add_neighbor(target)
target.add_neighbor(n2)
n5.add_neighbor(target)
target.add_neighbor(n5)
path = dijkstra([root,n2,n5,target], root, target)
self.assertEqual(value_sum(path), 10)
if __name__ == '__main__':
unittest.main()