def test_neighbors(): g = Graph() g.add_edge('a', 'b') g.add_edge('b', 'c') g.add_edge('a', 'c') neighbors = g.neighbors('a') assert 'b' in neighbors assert 'c' in neighbors try: g.neighbors('q') except IndexError: assert True else: assert False
def test_weighted_edges(): g = Graph() g.add_edge('a', 'b') g.add_edge('a', 'd') g.add_edge('a', 'g') g.add_edge('b', 'e') g.add_edge('e', 'g') g.add_edge('b', 'f') g.add_edge('f', 'd') g.add_edge('f', 'c') g.add_edge('c', 'h') assert g.adjacent('a', 'b') is True assert g.adjacent('a', 'c') is False g.del_edge('a', 'b') assert g.neighbors('a') == ['d', 'g']