def test_remove_edge(): """Test to remove an edge from the network.""" net = Network() a = Node('a') b = Node('b') c = Node('c') e = Edge(a, b, uid='e') f = Edge(b, a, uid='f') g = Edge(b, c, uid='g') net.add_edge(e) net.add_edge(f) net.remove_edge(g) assert net.number_of_edges() == 2 assert isinstance(net.edges['e'], Edge) assert g not in net.edges assert net.edges['a', 'b'] in net.edges assert net.successors['a'] == {b} assert net.outgoing['a'] == {e} assert net.incident_edges['a'] == {e, f} net.remove_edge(e) assert net.number_of_edges() == 1 assert net.successors['a'] == set() assert net.outgoing['a'] == set() assert net.incident_edges['a'] == {f} net.remove_edge('f') assert net.number_of_edges() == 0 assert net.incident_edges['a'] == set() a = Node('a') b = Node('b') e = Edge(a, b, uid='e') f = Edge(a, b, uid='f') g = Edge(a, b, uid='g') net = Network(multiedges=True) net.add_edges(e, f, g) assert net.number_of_edges() == 3 assert e and f and g in net.edges['a', 'b'] net.remove_edge('a', 'b', uid='g') assert net.number_of_edges() == 2 assert g not in net.edges['a', 'b'] net.remove_edge('a', 'b') assert net.number_of_edges() == 0 assert len(net.edges['a', 'b']) == 0
def test_network_properties(): """Test network properties.""" net = Network() net.add_edge('a', 'b', uid='a-b') net.add_edge('b', 'c', uid='b-c') net.add_edge('c', 'a', uid='c-a') assert net.successors['c'] == {net.nodes['a']} assert net.incoming['a'] == {net.edges['c-a']} net.remove_edge('c-a') assert net.successors['c'] == set() assert net.incoming['a'] == set()