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
| import unittest
|
| from pygraph.graphdemo import Graph
| from pygraph.shortestpath import bfs, bfs_dict, find_path, find_path_gpt
|
|
| class ShortestPathTestCase(unittest.TestCase):
| def test_bfs(self):
| g = Graph()
| g.add_edges(0, [1, 2])
| g.add_edges(1, [3, 4])
| g.add_edges(2, [4, 6, 7])
| g.add_edges(4, [5])
| print(g)
| print("#")
| tree = bfs(g, 0)
| print(tree)
|
| def test_bfs_dict(self):
| g = Graph()
| g.add_edges(0, [1, 2])
| g.add_edges(1, [3, 4])
| g.add_edges(2, [4, 6, 7])
| g.add_edges(4, [5])
| print(g)
| tree = bfs_dict(g, 6)
| print("Tree from Vertex 6")
| print(tree)
|
| def test_find_path(self):
| g = Graph()
| g.add_edges(0, [1, 2])
| g.add_edges(1, [3, 4])
| g.add_edges(2, [4, 6, 7])
| g.add_edges(4, [5])
| print(g)
| (u, v) = (6, 5)
| path = find_path(g, 6, 5)
| print(f"path from {u} to {v}")
| print(path)
|
| def test_find_path_gpt(self):
| g = Graph()
| g.add_edges(0, [1, 2])
| g.add_edges(1, [3, 4])
| g.add_edges(2, [4, 6, 7])
| g.add_edges(4, [5])
| print(g)
| (u, v) = (6, 5)
| path = find_path_gpt(g, 6, 5)
| print(f"path from {u} to {v}")
| print(path)
|
|
|
| if __name__ == '__main__':
| unittest.main()
|
|