### annotate env/lib/python3.9/site-packages/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py @ 0:4f3585e2f14bdraftdefaulttip

author shellac Mon, 22 Mar 2021 18:12:50 +0000
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
shellac
parents:
diff changeset
1 import networkx as nx
shellac
parents:
diff changeset
2 from networkx.algorithms.approximation import average_clustering
shellac
parents:
diff changeset
3
shellac
parents:
diff changeset
4 # This approximation has to be be exact in regular graphs
shellac
parents:
diff changeset
5 # with no triangles or with all possible triangles.
shellac
parents:
diff changeset
6
shellac
parents:
diff changeset
7
shellac
parents:
diff changeset
8 def test_petersen():
shellac
parents:
diff changeset
9 # Actual coefficient is 0
shellac
parents:
diff changeset
10 G = nx.petersen_graph()
shellac
parents:
diff changeset
11 assert average_clustering(G, trials=int(len(G) / 2)) == nx.average_clustering(G)
shellac
parents:
diff changeset
12
shellac
parents:
diff changeset
13
shellac
parents:
diff changeset
14 def test_petersen_seed():
shellac
parents:
diff changeset
15 # Actual coefficient is 0
shellac
parents:
diff changeset
16 G = nx.petersen_graph()
shellac
parents:
diff changeset
17 assert average_clustering(
shellac
parents:
diff changeset
18 G, trials=int(len(G) / 2), seed=1
shellac
parents:
diff changeset
19 ) == nx.average_clustering(G)
shellac
parents:
diff changeset
20
shellac
parents:
diff changeset
21
shellac
parents:
diff changeset
22 def test_tetrahedral():
shellac
parents:
diff changeset
23 # Actual coefficient is 1
shellac
parents:
diff changeset
24 G = nx.tetrahedral_graph()
shellac
parents:
diff changeset
25 assert average_clustering(G, trials=int(len(G) / 2)) == nx.average_clustering(G)
shellac
parents:
diff changeset
26
shellac
parents:
diff changeset
27
shellac
parents:
diff changeset
28 def test_dodecahedral():
shellac
parents:
diff changeset
29 # Actual coefficient is 0
shellac
parents:
diff changeset
30 G = nx.dodecahedral_graph()
shellac
parents:
diff changeset
31 assert average_clustering(G, trials=int(len(G) / 2)) == nx.average_clustering(G)
shellac
parents:
diff changeset
32
shellac
parents:
diff changeset
33
shellac
parents:
diff changeset
34 def test_empty():
shellac
parents:
diff changeset
35 G = nx.empty_graph(5)
shellac
parents:
diff changeset
36 assert average_clustering(G, trials=int(len(G) / 2)) == 0
shellac
parents:
diff changeset
37
shellac
parents:
diff changeset
38
shellac
parents:
diff changeset
39 def test_complete():
shellac
parents:
diff changeset
40 G = nx.complete_graph(5)
shellac
parents:
diff changeset
41 assert average_clustering(G, trials=int(len(G) / 2)) == 1