Exemplo n.º 1
0
def test_undirected_neighbors():
    # given
    g = UndirectedGraph()

    # when
    g.add_edge(1, 3)
    g.add_edge(3, 1)
    g.add_edge(5, 1)
    g.add_edge(1, 6)

    # then
    assert set(g.neighbors(1)) == {3, 5, 6}
    assert set(g.neighbors(6)) == {1}
Exemplo n.º 2
0
def test_add_node_already_graph_does_nothing():
    # given
    g = UndirectedGraph()

    # when
    g.add_edge(1, 3)
    g.add_edge(3, 1)
    g.add_edge(5, 1)

    g.add_node(3)

    assert len(g.neighbors(3)) == 1
    assert len(g.nodes) == 3