def test_add_edge(): graph = Graph() node1 = graph.add_node("a") node2 = graph.add_node("b") graph.add_edge(node1, node2) actual = graph.get_neighbors(node1)[0].vertex.value expected = "b" assert actual == expected
def depth(): aj_list = Graph() a = aj_list.add_node('A') b = aj_list.add_node('B') c = aj_list.add_node('C') d = aj_list.add_node('D') e = aj_list.add_node('E') f = aj_list.add_node('F') g = aj_list.add_node('G') h = aj_list.add_node('H') aj_list.add_edge(a, b) aj_list.add_edge(a, d) aj_list.add_edge(b, c) aj_list.add_edge(b, d) aj_list.add_edge(c, g) aj_list.add_edge(d, e) aj_list.add_edge(d, h) aj_list.add_edge(d, f) aj_list.add_edge(h, f) g = Graph() node1 = g.add_node('Pandora') node2 = g.add_node('Arendelle') node3 = g.add_node('Metroville') node4 = g.add_node('Monstroplolis') node5 = g.add_node('Narnia') node6 = g.add_node('Naboo') g.add_edge(node1, node2, 150) g.add_edge(node1, node3, 82) g.add_edge(node2, node3, 99) g.add_edge(node2, node4, 42) g.add_edge(node3, node4, 105) g.add_edge(node3, node5, 37) g.add_edge(node3, node6, 26) g.add_edge(node4, node6, 73) g.add_edge(node5, node6, 250) return [aj_list, g]
def test_empty_graph(): graph = Graph() actual = graph.depth_first() expected = [] assert actual == expected
def graph(): aj_list = Graph() node1 = aj_list.add_node('a') node2 = aj_list.add_node('b') node3 = aj_list.add_node('c') node4 = aj_list.add_node('d') node5 = aj_list.add_node('e') node6 = aj_list.add_node('f') aj_list.add_edge(node1, node3) aj_list.add_edge(node1, node4) aj_list.add_edge(node2, node3) aj_list.add_edge(node2, node6, [5]) aj_list.add_edge(node3, node5) aj_list.add_edge(node4, node5) aj_list.add_edge(node5, node6) return [aj_list, node1, node2, node3, node4, node5, node6]
def test_empty_graph(): graph = Graph() actual = graph.get_nodes() expected = None assert actual == expected
def test_add_node(): graph = Graph() actual = graph.add_node('a') expected = 'a' assert expected == actual.value
def graph3(): graph = Graph() node_a = graph.add_node('a') node_b = graph.add_node('Arendelle') node_c = graph.add_node('c') node_d = graph.add_node('Metroville') node_e = graph.add_node('e') node_f = graph.add_node('Naboo') graph.add_edge(node_a, node_f) graph.add_edge(node_b, node_e) graph.add_edge(node_c, node_d) graph.add_edge(node_e, node_a) graph.add_edge(node_f, node_b) graph.add_edge(node_a, node_c) graph.add_edge(node_d, node_f) return graph, node_a
def graph2(): graph = Graph() node_a = graph.add_node('a') node_b = graph.add_node('b') node_c = graph.add_node('c') node_d = graph.add_node('d') node_e = graph.add_node('e') node_f = graph.add_node('f') graph.add_edge(node_a, node_c, 1) graph.add_edge(node_a, node_d, 3) graph.add_edge(node_b, node_c, 5) graph.add_edge(node_b, node_f, 7) graph.add_edge(node_c, node_e, 9) graph.add_edge(node_d, node_e, 8) graph.add_edge(node_e, node_f, 4) return graph, node_a
def breadth(): g = Graph() node1 = g.add_node('Pandora') node2 = g.add_node('Arendelle') node5 = g.add_node('Narnia') node3 = g.add_node('Metroville') node4 = g.add_node('Monstroplolis') node6 = g.add_node('Naboo') g.add_edge(node1, node2) g.add_edge(node2, node3) g.add_edge(node3, node4) g.add_edge(node3, node5) g.add_edge(node3, node6) g.add_edge(node4, node6) g.add_edge(node5, node6) return [g, node1]