Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_regular.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 | |
3 import networkx as nx | |
4 | |
5 import networkx.algorithms.regular as reg | |
6 import networkx.generators as gen | |
7 | |
8 | |
9 class TestKFactor: | |
10 def test_k_factor_trivial(self): | |
11 g = gen.cycle_graph(4) | |
12 f = reg.k_factor(g, 2) | |
13 assert g.edges == f.edges | |
14 | |
15 def test_k_factor1(self): | |
16 g = gen.grid_2d_graph(4, 4) | |
17 g_kf = reg.k_factor(g, 2) | |
18 for edge in g_kf.edges(): | |
19 assert g.has_edge(edge[0], edge[1]) | |
20 for _, degree in g_kf.degree(): | |
21 assert degree == 2 | |
22 | |
23 def test_k_factor2(self): | |
24 g = gen.complete_graph(6) | |
25 g_kf = reg.k_factor(g, 3) | |
26 for edge in g_kf.edges(): | |
27 assert g.has_edge(edge[0], edge[1]) | |
28 for _, degree in g_kf.degree(): | |
29 assert degree == 3 | |
30 | |
31 def test_k_factor3(self): | |
32 g = gen.grid_2d_graph(4, 4) | |
33 with pytest.raises(nx.NetworkXUnfeasible): | |
34 reg.k_factor(g, 3) | |
35 | |
36 def test_k_factor4(self): | |
37 g = gen.lattice.hexagonal_lattice_graph(4, 4) | |
38 # Perfect matching doesn't exist for 4,4 hexagonal lattice graph | |
39 with pytest.raises(nx.NetworkXUnfeasible): | |
40 reg.k_factor(g, 2) | |
41 | |
42 def test_k_factor5(self): | |
43 g = gen.complete_graph(6) | |
44 # small k to exercise SmallKGadget | |
45 g_kf = reg.k_factor(g, 2) | |
46 for edge in g_kf.edges(): | |
47 assert g.has_edge(edge[0], edge[1]) | |
48 for _, degree in g_kf.degree(): | |
49 assert degree == 2 | |
50 | |
51 | |
52 class TestIsRegular: | |
53 def test_is_regular1(self): | |
54 g = gen.cycle_graph(4) | |
55 assert reg.is_regular(g) | |
56 | |
57 def test_is_regular2(self): | |
58 g = gen.complete_graph(5) | |
59 assert reg.is_regular(g) | |
60 | |
61 def test_is_regular3(self): | |
62 g = gen.lollipop_graph(5, 5) | |
63 assert not reg.is_regular(g) | |
64 | |
65 | |
66 class TestIsKRegular: | |
67 def test_is_k_regular1(self): | |
68 g = gen.cycle_graph(4) | |
69 assert reg.is_k_regular(g, 2) | |
70 assert not reg.is_k_regular(g, 3) | |
71 | |
72 def test_is_k_regular2(self): | |
73 g = gen.complete_graph(5) | |
74 assert reg.is_k_regular(g, 4) | |
75 assert not reg.is_k_regular(g, 3) | |
76 assert not reg.is_k_regular(g, 6) | |
77 | |
78 def test_is_k_regular3(self): | |
79 g = gen.lollipop_graph(5, 5) | |
80 assert not reg.is_k_regular(g, 5) | |
81 assert not reg.is_k_regular(g, 6) |