예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
 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)
예제 #6
0
 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'])