Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/community/tests/test_asyn_fluid.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 from networkx import Graph, NetworkXError | |
3 from networkx.algorithms.community.asyn_fluid import asyn_fluidc | |
4 | |
5 | |
6 def test_exceptions(): | |
7 test = Graph() | |
8 test.add_node("a") | |
9 pytest.raises(NetworkXError, asyn_fluidc, test, "hi") | |
10 pytest.raises(NetworkXError, asyn_fluidc, test, -1) | |
11 pytest.raises(NetworkXError, asyn_fluidc, test, 3) | |
12 test.add_node("b") | |
13 pytest.raises(NetworkXError, asyn_fluidc, test, 1) | |
14 | |
15 | |
16 def test_single_node(): | |
17 test = Graph() | |
18 | |
19 test.add_node("a") | |
20 | |
21 # ground truth | |
22 ground_truth = {frozenset(["a"])} | |
23 | |
24 communities = asyn_fluidc(test, 1) | |
25 result = {frozenset(c) for c in communities} | |
26 assert result == ground_truth | |
27 | |
28 | |
29 def test_two_nodes(): | |
30 test = Graph() | |
31 | |
32 test.add_edge("a", "b") | |
33 | |
34 # ground truth | |
35 ground_truth = {frozenset(["a"]), frozenset(["b"])} | |
36 | |
37 communities = asyn_fluidc(test, 2) | |
38 result = {frozenset(c) for c in communities} | |
39 assert result == ground_truth | |
40 | |
41 | |
42 def test_two_clique_communities(): | |
43 test = Graph() | |
44 | |
45 # c1 | |
46 test.add_edge("a", "b") | |
47 test.add_edge("a", "c") | |
48 test.add_edge("b", "c") | |
49 | |
50 # connection | |
51 test.add_edge("c", "d") | |
52 | |
53 # c2 | |
54 test.add_edge("d", "e") | |
55 test.add_edge("d", "f") | |
56 test.add_edge("f", "e") | |
57 | |
58 # ground truth | |
59 ground_truth = {frozenset(["a", "c", "b"]), frozenset(["e", "d", "f"])} | |
60 | |
61 communities = asyn_fluidc(test, 2, seed=7) | |
62 result = {frozenset(c) for c in communities} | |
63 assert result == ground_truth | |
64 | |
65 | |
66 def test_five_clique_ring(): | |
67 test = Graph() | |
68 | |
69 # c1 | |
70 test.add_edge("1a", "1b") | |
71 test.add_edge("1a", "1c") | |
72 test.add_edge("1a", "1d") | |
73 test.add_edge("1b", "1c") | |
74 test.add_edge("1b", "1d") | |
75 test.add_edge("1c", "1d") | |
76 | |
77 # c2 | |
78 test.add_edge("2a", "2b") | |
79 test.add_edge("2a", "2c") | |
80 test.add_edge("2a", "2d") | |
81 test.add_edge("2b", "2c") | |
82 test.add_edge("2b", "2d") | |
83 test.add_edge("2c", "2d") | |
84 | |
85 # c3 | |
86 test.add_edge("3a", "3b") | |
87 test.add_edge("3a", "3c") | |
88 test.add_edge("3a", "3d") | |
89 test.add_edge("3b", "3c") | |
90 test.add_edge("3b", "3d") | |
91 test.add_edge("3c", "3d") | |
92 | |
93 # c4 | |
94 test.add_edge("4a", "4b") | |
95 test.add_edge("4a", "4c") | |
96 test.add_edge("4a", "4d") | |
97 test.add_edge("4b", "4c") | |
98 test.add_edge("4b", "4d") | |
99 test.add_edge("4c", "4d") | |
100 | |
101 # c5 | |
102 test.add_edge("5a", "5b") | |
103 test.add_edge("5a", "5c") | |
104 test.add_edge("5a", "5d") | |
105 test.add_edge("5b", "5c") | |
106 test.add_edge("5b", "5d") | |
107 test.add_edge("5c", "5d") | |
108 | |
109 # connections | |
110 test.add_edge("1a", "2c") | |
111 test.add_edge("2a", "3c") | |
112 test.add_edge("3a", "4c") | |
113 test.add_edge("4a", "5c") | |
114 test.add_edge("5a", "1c") | |
115 | |
116 # ground truth | |
117 ground_truth = { | |
118 frozenset(["1a", "1b", "1c", "1d"]), | |
119 frozenset(["2a", "2b", "2c", "2d"]), | |
120 frozenset(["3a", "3b", "3c", "3d"]), | |
121 frozenset(["4a", "4b", "4c", "4d"]), | |
122 frozenset(["5a", "5b", "5c", "5d"]), | |
123 } | |
124 | |
125 communities = asyn_fluidc(test, 5, seed=9) | |
126 result = {frozenset(c) for c in communities} | |
127 assert result == ground_truth |