comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_richclub.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_richclub():
6 G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)])
7 rc = nx.richclub.rich_club_coefficient(G, normalized=False)
8 assert rc == {0: 12.0 / 30, 1: 8.0 / 12}
9
10 # test single value
11 rc0 = nx.richclub.rich_club_coefficient(G, normalized=False)[0]
12 assert rc0 == 12.0 / 30.0
13
14
15 def test_richclub_seed():
16 G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)])
17 rcNorm = nx.richclub.rich_club_coefficient(G, Q=2, seed=1)
18 assert rcNorm == {0: 1.0, 1: 1.0}
19
20
21 def test_richclub_normalized():
22 G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3), (1, 4), (4, 5)])
23 rcNorm = nx.richclub.rich_club_coefficient(G, Q=2)
24 assert rcNorm == {0: 1.0, 1: 1.0}
25
26
27 def test_richclub2():
28 T = nx.balanced_tree(2, 10)
29 rc = nx.richclub.rich_club_coefficient(T, normalized=False)
30 assert rc == {
31 0: 4092 / (2047 * 2046.0),
32 1: (2044.0 / (1023 * 1022)),
33 2: (2040.0 / (1022 * 1021)),
34 }
35
36
37 def test_richclub3():
38 # tests edgecase
39 G = nx.karate_club_graph()
40 rc = nx.rich_club_coefficient(G, normalized=False)
41 assert rc == {
42 0: 156.0 / 1122,
43 1: 154.0 / 1056,
44 2: 110.0 / 462,
45 3: 78.0 / 240,
46 4: 44.0 / 90,
47 5: 22.0 / 42,
48 6: 10.0 / 20,
49 7: 10.0 / 20,
50 8: 10.0 / 20,
51 9: 6.0 / 12,
52 10: 2.0 / 6,
53 11: 2.0 / 6,
54 12: 0.0,
55 13: 0.0,
56 14: 0.0,
57 15: 0.0,
58 }
59
60
61 def test_richclub4():
62 G = nx.Graph()
63 G.add_edges_from(
64 [(0, 1), (0, 2), (0, 3), (0, 4), (4, 5), (5, 9), (6, 9), (7, 9), (8, 9)]
65 )
66 rc = nx.rich_club_coefficient(G, normalized=False)
67 assert rc == {0: 18 / 90.0, 1: 6 / 12.0, 2: 0.0, 3: 0.0}
68
69
70 def test_richclub_exception():
71 with pytest.raises(nx.NetworkXNotImplemented):
72 G = nx.DiGraph()
73 nx.rich_club_coefficient(G)
74
75
76 def test_rich_club_exception2():
77 with pytest.raises(nx.NetworkXNotImplemented):
78 G = nx.MultiGraph()
79 nx.rich_club_coefficient(G)
80
81
82 # def test_richclub2_normalized():
83 # T = nx.balanced_tree(2,10)
84 # rcNorm = nx.richclub.rich_club_coefficient(T,Q=2)
85 # assert_true(rcNorm[0] ==1.0 and rcNorm[1] < 0.9 and rcNorm[2] < 0.9)