Пример #1
0
def test_adjacent():
    g = Graph()
    g.add_edge('a', 'b')
    g.add_edge('a', 'c')
    try:
        g.adjacent('a', 'e')
    except IndexError:
        assert True
    else:
        assert False
    assert g.adjacent('a', 'b') is True
    assert g.adjacent('c', 'b') is False
Пример #2
0
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']