def test_disconnected(self): '''If no path exists, do we return None?''' g = nx.Graph() g.add_node('A') g.add_node('Z') path = BFS(g, 'A', 'Z') self.assertEquals(path, None)
def test_line(self): '''Check shortest path for line graph.''' # Return the line graph with n nodes, lowest-num node is 0 for i in range(2, 4): g = nx.path_graph(i) set_unit_weights(g) path = BFS(g, 0, i - 1) self.assertTrue(path) self.assertEqual(path[0], 0) self.assertEqual(path[-1], i - 1)
def test_example_3_16_a(self): '''Example 3.16a on pg 74.''' g = graph_fig_3_16_a path = BFS(g, 'A', 'Z') self.assertEqual(path, [i for i in 'ABCDEFZ']) self.assertEqual(pathlen(g, path), 6)
def test_example_3_1_a(self): '''Example 3.1a on pg. 41.''' g = graph_fig_3_1_a path = BFS(g, 'A', 'Z') self.assertEqual(path, [i for i in 'ABCDZ']) self.assertEqual(pathlen(g, path), 4)
def test_example_2_6(self): '''Example 2.6 on pg. 35.''' g = graph_fig_2_3 path = BFS(g, 'A', 'Z') self.assertEqual(path, [i for i in 'ADECBZ']) self.assertEqual(pathlen(g, path), 12)
def test_example_2_5(self): '''Example 2.5 on pg. 34.''' path = BFS(graph_fig_2_1, 'A', 'Z') self.assertEqual(path, [i for i in 'ABCZ'])