Пример #1
0
def test_is_valid():
    G = Graph()
    assert not G.is_valid()
    G.add_path((Graph.SOURCE, ) + tuple(range(10)) + (Graph.SINK, ))
    assert G.is_valid()
    G.remove_node_id(G.node_id_map[5])
    assert not G.is_valid()
    G.remove_unreachable_nodes()
    assert not G.is_valid()
Пример #2
0
def test_is_valid():
    G = Graph()
    assert not G.is_valid()
    G.add_path((Graph.SOURCE,) + tuple(range(10)) + (Graph.SINK,))
    assert G.is_valid()
    G.remove_node_id(G.node_id_map[5])
    assert not G.is_valid()
    G.remove_unreachable_nodes()
    assert not G.is_valid()
Пример #3
0
def test_remove_node():
    G = Graph()
    G.add_path((Graph.SOURCE, 10, 20, 30, 40, Graph.SINK))
    G.add_path((Graph.SOURCE, 10, 30, 40, Graph.SINK))
    G.add_path((Graph.SOURCE, 10, Graph.SINK))
    assert len(G) == 4
    assert len(G.preds[G.node_id_map[20]]) == 1
    assert len(G.preds[G.node_id_map[30]]) == 2
    node_id = G.node_id_map[10]
    G.remove_node_id(G.node_id_map[10])
    assert 10 not in G.node_id_map
    assert G.nodes[node_id] == Graph.EMPTY
    assert len(G) == 3
    assert len(G.preds[G.node_id_map[20]]) == 0
    assert len(G.preds[G.node_id_map[30]]) == 1
Пример #4
0
def test_remove_node():
    G = Graph()
    G.add_path((Graph.SOURCE, 10, 20, 30, 40, Graph.SINK))
    G.add_path((Graph.SOURCE, 10, 30, 40, Graph.SINK))
    G.add_path((Graph.SOURCE, 10, Graph.SINK))
    assert len(G) == 4
    assert len(G.preds[G.node_id_map[20]]) == 1
    assert len(G.preds[G.node_id_map[30]]) == 2
    node_id = G.node_id_map[10]
    G.remove_node_id(G.node_id_map[10])
    assert 10 not in G.node_id_map
    assert G.nodes[node_id] == Graph.EMPTY
    assert len(G) == 3
    assert len(G.preds[G.node_id_map[20]]) == 0
    assert len(G.preds[G.node_id_map[30]]) == 1