Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/generators/tests/test_small.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 from networkx.algorithms.isomorphism.isomorph import graph_could_be_isomorphic | |
4 | |
5 is_isomorphic = graph_could_be_isomorphic | |
6 | |
7 """Generators - Small | |
8 ===================== | |
9 | |
10 Some small graphs | |
11 """ | |
12 | |
13 null = nx.null_graph() | |
14 | |
15 | |
16 class TestGeneratorsSmall: | |
17 def test_make_small_graph(self): | |
18 d = ["adjacencylist", "Bull Graph", 5, [[2, 3], [1, 3, 4], [1, 2, 5], [2], [3]]] | |
19 G = nx.make_small_graph(d) | |
20 assert is_isomorphic(G, nx.bull_graph()) | |
21 | |
22 # Test small graph creation error with wrong ltype | |
23 d[0] = "erroneouslist" | |
24 pytest.raises(nx.NetworkXError, nx.make_small_graph, graph_description=d) | |
25 | |
26 def test__LCF_graph(self): | |
27 # If n<=0, then return the null_graph | |
28 G = nx.LCF_graph(-10, [1, 2], 100) | |
29 assert is_isomorphic(G, null) | |
30 G = nx.LCF_graph(0, [1, 2], 3) | |
31 assert is_isomorphic(G, null) | |
32 G = nx.LCF_graph(0, [1, 2], 10) | |
33 assert is_isomorphic(G, null) | |
34 | |
35 # Test that LCF(n,[],0) == cycle_graph(n) | |
36 for a, b, c in [(5, [], 0), (10, [], 0), (5, [], 1), (10, [], 10)]: | |
37 G = nx.LCF_graph(a, b, c) | |
38 assert is_isomorphic(G, nx.cycle_graph(a)) | |
39 | |
40 # Generate the utility graph K_{3,3} | |
41 G = nx.LCF_graph(6, [3, -3], 3) | |
42 utility_graph = nx.complete_bipartite_graph(3, 3) | |
43 assert is_isomorphic(G, utility_graph) | |
44 | |
45 def test_properties_named_small_graphs(self): | |
46 G = nx.bull_graph() | |
47 assert G.number_of_nodes() == 5 | |
48 assert G.number_of_edges() == 5 | |
49 assert sorted(d for n, d in G.degree()) == [1, 1, 2, 3, 3] | |
50 assert nx.diameter(G) == 3 | |
51 assert nx.radius(G) == 2 | |
52 | |
53 G = nx.chvatal_graph() | |
54 assert G.number_of_nodes() == 12 | |
55 assert G.number_of_edges() == 24 | |
56 assert list(d for n, d in G.degree()) == 12 * [4] | |
57 assert nx.diameter(G) == 2 | |
58 assert nx.radius(G) == 2 | |
59 | |
60 G = nx.cubical_graph() | |
61 assert G.number_of_nodes() == 8 | |
62 assert G.number_of_edges() == 12 | |
63 assert list(d for n, d in G.degree()) == 8 * [3] | |
64 assert nx.diameter(G) == 3 | |
65 assert nx.radius(G) == 3 | |
66 | |
67 G = nx.desargues_graph() | |
68 assert G.number_of_nodes() == 20 | |
69 assert G.number_of_edges() == 30 | |
70 assert list(d for n, d in G.degree()) == 20 * [3] | |
71 | |
72 G = nx.diamond_graph() | |
73 assert G.number_of_nodes() == 4 | |
74 assert sorted(d for n, d in G.degree()) == [2, 2, 3, 3] | |
75 assert nx.diameter(G) == 2 | |
76 assert nx.radius(G) == 1 | |
77 | |
78 G = nx.dodecahedral_graph() | |
79 assert G.number_of_nodes() == 20 | |
80 assert G.number_of_edges() == 30 | |
81 assert list(d for n, d in G.degree()) == 20 * [3] | |
82 assert nx.diameter(G) == 5 | |
83 assert nx.radius(G) == 5 | |
84 | |
85 G = nx.frucht_graph() | |
86 assert G.number_of_nodes() == 12 | |
87 assert G.number_of_edges() == 18 | |
88 assert list(d for n, d in G.degree()) == 12 * [3] | |
89 assert nx.diameter(G) == 4 | |
90 assert nx.radius(G) == 3 | |
91 | |
92 G = nx.heawood_graph() | |
93 assert G.number_of_nodes() == 14 | |
94 assert G.number_of_edges() == 21 | |
95 assert list(d for n, d in G.degree()) == 14 * [3] | |
96 assert nx.diameter(G) == 3 | |
97 assert nx.radius(G) == 3 | |
98 | |
99 G = nx.hoffman_singleton_graph() | |
100 assert G.number_of_nodes() == 50 | |
101 assert G.number_of_edges() == 175 | |
102 assert list(d for n, d in G.degree()) == 50 * [7] | |
103 assert nx.diameter(G) == 2 | |
104 assert nx.radius(G) == 2 | |
105 | |
106 G = nx.house_graph() | |
107 assert G.number_of_nodes() == 5 | |
108 assert G.number_of_edges() == 6 | |
109 assert sorted(d for n, d in G.degree()) == [2, 2, 2, 3, 3] | |
110 assert nx.diameter(G) == 2 | |
111 assert nx.radius(G) == 2 | |
112 | |
113 G = nx.house_x_graph() | |
114 assert G.number_of_nodes() == 5 | |
115 assert G.number_of_edges() == 8 | |
116 assert sorted(d for n, d in G.degree()) == [2, 3, 3, 4, 4] | |
117 assert nx.diameter(G) == 2 | |
118 assert nx.radius(G) == 1 | |
119 | |
120 G = nx.icosahedral_graph() | |
121 assert G.number_of_nodes() == 12 | |
122 assert G.number_of_edges() == 30 | |
123 assert list(d for n, d in G.degree()) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5] | |
124 assert nx.diameter(G) == 3 | |
125 assert nx.radius(G) == 3 | |
126 | |
127 G = nx.krackhardt_kite_graph() | |
128 assert G.number_of_nodes() == 10 | |
129 assert G.number_of_edges() == 18 | |
130 assert sorted(d for n, d in G.degree()) == [1, 2, 3, 3, 3, 4, 4, 5, 5, 6] | |
131 | |
132 G = nx.moebius_kantor_graph() | |
133 assert G.number_of_nodes() == 16 | |
134 assert G.number_of_edges() == 24 | |
135 assert list(d for n, d in G.degree()) == 16 * [3] | |
136 assert nx.diameter(G) == 4 | |
137 | |
138 G = nx.octahedral_graph() | |
139 assert G.number_of_nodes() == 6 | |
140 assert G.number_of_edges() == 12 | |
141 assert list(d for n, d in G.degree()) == 6 * [4] | |
142 assert nx.diameter(G) == 2 | |
143 assert nx.radius(G) == 2 | |
144 | |
145 G = nx.pappus_graph() | |
146 assert G.number_of_nodes() == 18 | |
147 assert G.number_of_edges() == 27 | |
148 assert list(d for n, d in G.degree()) == 18 * [3] | |
149 assert nx.diameter(G) == 4 | |
150 | |
151 G = nx.petersen_graph() | |
152 assert G.number_of_nodes() == 10 | |
153 assert G.number_of_edges() == 15 | |
154 assert list(d for n, d in G.degree()) == 10 * [3] | |
155 assert nx.diameter(G) == 2 | |
156 assert nx.radius(G) == 2 | |
157 | |
158 G = nx.sedgewick_maze_graph() | |
159 assert G.number_of_nodes() == 8 | |
160 assert G.number_of_edges() == 10 | |
161 assert sorted(d for n, d in G.degree()) == [1, 2, 2, 2, 3, 3, 3, 4] | |
162 | |
163 G = nx.tetrahedral_graph() | |
164 assert G.number_of_nodes() == 4 | |
165 assert G.number_of_edges() == 6 | |
166 assert list(d for n, d in G.degree()) == [3, 3, 3, 3] | |
167 assert nx.diameter(G) == 1 | |
168 assert nx.radius(G) == 1 | |
169 | |
170 G = nx.truncated_cube_graph() | |
171 assert G.number_of_nodes() == 24 | |
172 assert G.number_of_edges() == 36 | |
173 assert list(d for n, d in G.degree()) == 24 * [3] | |
174 | |
175 G = nx.truncated_tetrahedron_graph() | |
176 assert G.number_of_nodes() == 12 | |
177 assert G.number_of_edges() == 18 | |
178 assert list(d for n, d in G.degree()) == 12 * [3] | |
179 | |
180 G = nx.tutte_graph() | |
181 assert G.number_of_nodes() == 46 | |
182 assert G.number_of_edges() == 69 | |
183 assert list(d for n, d in G.degree()) == 46 * [3] | |
184 | |
185 # Test create_using with directed or multigraphs on small graphs | |
186 pytest.raises(nx.NetworkXError, nx.tutte_graph, create_using=nx.DiGraph) | |
187 MG = nx.tutte_graph(create_using=nx.MultiGraph) | |
188 assert sorted(MG.edges()) == sorted(G.edges()) |