| | |
| | | import unittest |
| | | |
| | | from pygraph.graphdemo import Graph |
| | | from pygraph.shortestpath import bfs |
| | | 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, [0, 3, 4]) |
| | | g.add_edges(2, [0, 4, 6, 7]) |
| | | g.add_edges(3, [1]) |
| | | g.add_edges(4, [1, 2, 5]) |
| | | g.add_edges(5, [4]) |
| | | g.add_edges(6, [2]) |
| | | g.add_edges(7, [2]) |
| | | #print(g) |
| | | # self.assertEqual(True, False) # add assertion here |
| | | |
| | | 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() |