comparison env/lib/python3.9/site-packages/networkx/algorithms/operators/tests/test_unary.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import pytest
2 import networkx as nx
3
4
5 def test_complement():
6 null = nx.null_graph()
7 empty1 = nx.empty_graph(1)
8 empty10 = nx.empty_graph(10)
9 K3 = nx.complete_graph(3)
10 K5 = nx.complete_graph(5)
11 K10 = nx.complete_graph(10)
12 P2 = nx.path_graph(2)
13 P3 = nx.path_graph(3)
14 P5 = nx.path_graph(5)
15 P10 = nx.path_graph(10)
16 # complement of the complete graph is empty
17
18 G = nx.complement(K3)
19 assert nx.is_isomorphic(G, nx.empty_graph(3))
20 G = nx.complement(K5)
21 assert nx.is_isomorphic(G, nx.empty_graph(5))
22 # for any G, G=complement(complement(G))
23 P3cc = nx.complement(nx.complement(P3))
24 assert nx.is_isomorphic(P3, P3cc)
25 nullcc = nx.complement(nx.complement(null))
26 assert nx.is_isomorphic(null, nullcc)
27 b = nx.bull_graph()
28 bcc = nx.complement(nx.complement(b))
29 assert nx.is_isomorphic(b, bcc)
30
31
32 def test_complement_2():
33 G1 = nx.DiGraph()
34 G1.add_edge("A", "B")
35 G1.add_edge("A", "C")
36 G1.add_edge("A", "D")
37 G1C = nx.complement(G1)
38 assert sorted(G1C.edges()) == [
39 ("B", "A"),
40 ("B", "C"),
41 ("B", "D"),
42 ("C", "A"),
43 ("C", "B"),
44 ("C", "D"),
45 ("D", "A"),
46 ("D", "B"),
47 ("D", "C"),
48 ]
49
50
51 def test_reverse1():
52 # Other tests for reverse are done by the DiGraph and MultiDigraph.
53 G1 = nx.Graph()
54 pytest.raises(nx.NetworkXError, nx.reverse, G1)