def test_mst_prim(): graph = RandomGraph() mst = mst_prim(graph, graph.nodes()[0]) nx_graph = networkx.Graph() for node in graph.nodes(): for neighbor in graph.get(node): if nx_graph.has_edge(node, neighbor) is False and nx_graph.has_edge( neighbor, node) is False: nx_graph.add_edge(node, neighbor, weight=graph.get(node, neighbor)) tree = [] for node in mst: if mst[node] is not None: tree.append((node, mst[node])) print(tree) T = networkx.minimum_spanning_tree(nx_graph) edges = T.edges(data=False) # Begin the test test = True # I need to check if (x,y) or (y,x) is in networkx generated mst for node in tree: x, y = node print(x, y) test = test and ((x, y) in edges or (y, x) in edges) assert test