Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_graphical.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_valid_degree_sequence1(): | |
6 n = 100 | |
7 p = 0.3 | |
8 for i in range(10): | |
9 G = nx.erdos_renyi_graph(n, p) | |
10 deg = (d for n, d in G.degree()) | |
11 assert nx.is_graphical(deg, method="eg") | |
12 assert nx.is_graphical(deg, method="hh") | |
13 | |
14 | |
15 def test_valid_degree_sequence2(): | |
16 n = 100 | |
17 for i in range(10): | |
18 G = nx.barabasi_albert_graph(n, 1) | |
19 deg = (d for n, d in G.degree()) | |
20 assert nx.is_graphical(deg, method="eg") | |
21 assert nx.is_graphical(deg, method="hh") | |
22 | |
23 | |
24 def test_string_input(): | |
25 pytest.raises(nx.NetworkXException, nx.is_graphical, [], "foo") | |
26 pytest.raises(nx.NetworkXException, nx.is_graphical, ["red"], "hh") | |
27 pytest.raises(nx.NetworkXException, nx.is_graphical, ["red"], "eg") | |
28 | |
29 | |
30 def test_non_integer_input(): | |
31 pytest.raises(nx.NetworkXException, nx.is_graphical, [72.5], "eg") | |
32 pytest.raises(nx.NetworkXException, nx.is_graphical, [72.5], "hh") | |
33 | |
34 | |
35 def test_negative_input(): | |
36 assert not nx.is_graphical([-1], "hh") | |
37 assert not nx.is_graphical([-1], "eg") | |
38 | |
39 | |
40 class TestAtlas: | |
41 @classmethod | |
42 def setup_class(cls): | |
43 global atlas | |
44 # import platform | |
45 # if platform.python_implementation() == 'Jython': | |
46 # raise SkipTest('graph atlas not available under Jython.') | |
47 import networkx.generators.atlas as atlas | |
48 | |
49 cls.GAG = atlas.graph_atlas_g() | |
50 | |
51 def test_atlas(self): | |
52 for graph in self.GAG: | |
53 deg = (d for n, d in graph.degree()) | |
54 assert nx.is_graphical(deg, method="eg") | |
55 assert nx.is_graphical(deg, method="hh") | |
56 | |
57 | |
58 def test_small_graph_true(): | |
59 z = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] | |
60 assert nx.is_graphical(z, method="hh") | |
61 assert nx.is_graphical(z, method="eg") | |
62 z = [10, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2] | |
63 assert nx.is_graphical(z, method="hh") | |
64 assert nx.is_graphical(z, method="eg") | |
65 z = [1, 1, 1, 1, 1, 2, 2, 2, 3, 4] | |
66 assert nx.is_graphical(z, method="hh") | |
67 assert nx.is_graphical(z, method="eg") | |
68 | |
69 | |
70 def test_small_graph_false(): | |
71 z = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] | |
72 assert not nx.is_graphical(z, method="hh") | |
73 assert not nx.is_graphical(z, method="eg") | |
74 z = [6, 5, 4, 4, 2, 1, 1, 1] | |
75 assert not nx.is_graphical(z, method="hh") | |
76 assert not nx.is_graphical(z, method="eg") | |
77 z = [1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4] | |
78 assert not nx.is_graphical(z, method="hh") | |
79 assert not nx.is_graphical(z, method="eg") | |
80 | |
81 | |
82 def test_directed_degree_sequence(): | |
83 # Test a range of valid directed degree sequences | |
84 n, r = 100, 10 | |
85 p = 1.0 / r | |
86 for i in range(r): | |
87 G = nx.erdos_renyi_graph(n, p * (i + 1), None, True) | |
88 din = (d for n, d in G.in_degree()) | |
89 dout = (d for n, d in G.out_degree()) | |
90 assert nx.is_digraphical(din, dout) | |
91 | |
92 | |
93 def test_small_directed_sequences(): | |
94 dout = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] | |
95 din = [3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1] | |
96 assert nx.is_digraphical(din, dout) | |
97 # Test nongraphical directed sequence | |
98 dout = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] | |
99 din = [103, 102, 102, 102, 102, 102, 102, 102, 102, 102] | |
100 assert not nx.is_digraphical(din, dout) | |
101 # Test digraphical small sequence | |
102 dout = [1, 1, 1, 1, 1, 2, 2, 2, 3, 4] | |
103 din = [2, 2, 2, 2, 2, 2, 2, 2, 1, 1] | |
104 assert nx.is_digraphical(din, dout) | |
105 # Test nonmatching sum | |
106 din = [2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1] | |
107 assert not nx.is_digraphical(din, dout) | |
108 # Test for negative integer in sequence | |
109 din = [2, 2, 2, -2, 2, 2, 2, 2, 1, 1, 4] | |
110 assert not nx.is_digraphical(din, dout) | |
111 # Test for noninteger | |
112 din = dout = [1, 1, 1.1, 1] | |
113 assert not nx.is_digraphical(din, dout) | |
114 din = dout = [1, 1, "rer", 1] | |
115 assert not nx.is_digraphical(din, dout) | |
116 | |
117 | |
118 def test_multi_sequence(): | |
119 # Test nongraphical multi sequence | |
120 seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1] | |
121 assert not nx.is_multigraphical(seq) | |
122 # Test small graphical multi sequence | |
123 seq = [6, 5, 4, 4, 2, 1, 1, 1] | |
124 assert nx.is_multigraphical(seq) | |
125 # Test for negative integer in sequence | |
126 seq = [6, 5, 4, -4, 2, 1, 1, 1] | |
127 assert not nx.is_multigraphical(seq) | |
128 # Test for sequence with odd sum | |
129 seq = [1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 4] | |
130 assert not nx.is_multigraphical(seq) | |
131 # Test for noninteger | |
132 seq = [1, 1, 1.1, 1] | |
133 assert not nx.is_multigraphical(seq) | |
134 seq = [1, 1, "rer", 1] | |
135 assert not nx.is_multigraphical(seq) | |
136 | |
137 | |
138 def test_pseudo_sequence(): | |
139 # Test small valid pseudo sequence | |
140 seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1] | |
141 assert nx.is_pseudographical(seq) | |
142 # Test for sequence with odd sum | |
143 seq = [1000, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] | |
144 assert not nx.is_pseudographical(seq) | |
145 # Test for negative integer in sequence | |
146 seq = [1000, 3, 3, 3, 3, 2, 2, -2, 1, 1] | |
147 assert not nx.is_pseudographical(seq) | |
148 # Test for noninteger | |
149 seq = [1, 1, 1.1, 1] | |
150 assert not nx.is_pseudographical(seq) | |
151 seq = [1, 1, "rer", 1] | |
152 assert not nx.is_pseudographical(seq) | |
153 | |
154 | |
155 def test_numpy_degree_sequence(): | |
156 numpy = pytest.importorskip("numpy") | |
157 ds = numpy.array([1, 2, 2, 2, 1], dtype=numpy.int64) | |
158 assert nx.is_graphical(ds, "eg") | |
159 assert nx.is_graphical(ds, "hh") | |
160 ds = numpy.array([1, 2, 2, 2, 1], dtype=numpy.float64) | |
161 assert nx.is_graphical(ds, "eg") | |
162 assert nx.is_graphical(ds, "hh") | |
163 ds = numpy.array([1.1, 2, 2, 2, 1], dtype=numpy.float64) | |
164 pytest.raises(nx.NetworkXException, nx.is_graphical, ds, "eg") | |
165 pytest.raises(nx.NetworkXException, nx.is_graphical, ds, "hh") |