Esempio n. 1
0
def __edge_view_returns_false_if_node_isnt_in_graph():
    # given
    g = DirectedGraph()

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

    # then
    assert (5, 2) not in g
Esempio n. 2
0
def test_directed_add_edge_and_opposite():
    # given
    g = DirectedGraph()

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

    # then
    assert set(g.edges) == {(1, 3), (3, 1)}
Esempio n. 3
0
def test_remove_node_removes_edges_too_directed():
    # given
    g = DirectedGraph()

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

    assert (1, 3) not in g.edges
    assert (3, 1) not in g.edges
    assert (5, 1) not in g.edges
    assert len(g.edges) == 0
Esempio n. 4
0
def test_remove_missing_edge_raises_directed():
    # given
    g = DirectedGraph()
    g.add_edge(1, 2)
    g.add_edge(2, 3)
    g.add_edge(3, 1)

    # when
    with pytest.raises(DoesNotExistError):
        g.remove_edge(2, 4)
Esempio n. 5
0
def test_remove_missing_node_raises_directed():
    # given
    g = DirectedGraph()
    g.add_node(1)
    g.add_node(2)
    g.add_node(3)

    # when
    with pytest.raises(DoesNotExistError):
        g.remove_node(4)
Esempio n. 6
0
def test_remove_edge_directed():
    # given
    g = DirectedGraph()
    g.add_edge(1, 2)
    g.add_edge(2, 1)
    g.add_edge(2, 3)
    g.add_edge(3, 1)

    # when
    g.remove_edge(1, 2)

    # then
    assert (1, 2) not in g.edges
    assert (2, 1) in g.edges
    assert len(g.edges) == 3
    assert len(g.nodes) == 3
Esempio n. 7
0
def test_directed_predecessors():
    # given
    g = DirectedGraph()

    # 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.predecessors(1)) == {3, 5}
    assert set(g.predecessors(6)) == {1}
Esempio n. 8
0
def test_directed_successors():
    # given
    g = DirectedGraph()

    # 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.successors(1)) == {3, 6}
    assert set(g.successors(6)) == set()
Esempio n. 9
0
def test_directed_has_edge():
    # given
    g = DirectedGraph()

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

    # then
    assert (1, 3) in g.edges
    assert (3, 1) in g.edges
    assert (5, 1) in g.edges
    assert (1, 5) not in g.edges