def test_disconnected_graph(self): G = nx.Graph() node_list = ['A', 'B', 'C', 'D', 'E', 'F'] G.add_nodes_from(node_list) self.assertEqual(list(G.nodes), node_list) bfs.breadth_first_search(G, 'A', 1) self.assertEqual(G.nodes['A']['distance'], 0) self.assertEqual(G.nodes['B']['distance'], -1) self.assertEqual(G.nodes['C']['distance'], -1) self.assertEqual(G.nodes['D']['distance'], -1) self.assertEqual(G.nodes['E']['distance'], -1) self.assertEqual(G.nodes['F']['distance'], -1)
def test_parallel_6(self): G = nx.Graph() node_list = ['A', 'B', 'C', 'D', 'E', 'F'] G.add_nodes_from(node_list) edge_list = [('A', 'C'), ('A', 'B'), ('C', 'E'), ('B', 'D'), ('D', 'F')] G.add_edges_from(edge_list) bfs.breadth_first_search(G, 'A', 6) self.assertEqual(G.nodes['A']['distance'], 0) self.assertEqual(G.nodes['B']['distance'], 1) self.assertEqual(G.nodes['C']['distance'], 1) self.assertEqual(G.nodes['D']['distance'], 2) self.assertEqual(G.nodes['E']['distance'], 2) self.assertEqual(G.nodes['F']['distance'], 3)