Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/tests/test_efficiency.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 """Unit tests for the :mod:`networkx.algorithms.efficiency` module.""" | |
2 | |
3 import networkx as nx | |
4 | |
5 | |
6 class TestEfficiency: | |
7 def setup_method(self): | |
8 # G1 is a disconnected graph | |
9 self.G1 = nx.Graph() | |
10 self.G1.add_nodes_from([1, 2, 3]) | |
11 # G2 is a cycle graph | |
12 self.G2 = nx.cycle_graph(4) | |
13 # G3 is the triangle graph with one additional edge | |
14 self.G3 = nx.lollipop_graph(3, 1) | |
15 | |
16 def test_efficiency_disconnected_nodes(self): | |
17 """ | |
18 When nodes are disconnected, efficiency is 0 | |
19 """ | |
20 assert nx.efficiency(self.G1, 1, 2) == 0 | |
21 | |
22 def test_local_efficiency_disconnected_graph(self): | |
23 """ | |
24 In a disconnected graph the efficiency is 0 | |
25 """ | |
26 assert nx.local_efficiency(self.G1) == 0 | |
27 | |
28 def test_efficiency(self): | |
29 assert nx.efficiency(self.G2, 0, 1) == 1 | |
30 assert nx.efficiency(self.G2, 0, 2) == 1 / 2 | |
31 | |
32 def test_global_efficiency(self): | |
33 assert nx.global_efficiency(self.G2) == 5 / 6 | |
34 | |
35 def test_global_efficiency_complete_graph(self): | |
36 """ | |
37 Tests that the average global efficiency of the complete graph is one. | |
38 """ | |
39 for n in range(2, 10): | |
40 G = nx.complete_graph(n) | |
41 assert nx.global_efficiency(G) == 1 | |
42 | |
43 def test_local_efficiency_complete_graph(self): | |
44 """ | |
45 Test that the local efficiency for a complete graph with at least 3 | |
46 nodes should be one. For a graph with only 2 nodes, the induced | |
47 subgraph has no edges. | |
48 """ | |
49 for n in range(3, 10): | |
50 G = nx.complete_graph(n) | |
51 assert nx.local_efficiency(G) == 1 | |
52 | |
53 def test_using_ego_graph(self): | |
54 """ | |
55 Test that the ego graph is used when computing local efficiency. | |
56 For more information, see GitHub issue #2710. | |
57 """ | |
58 assert nx.local_efficiency(self.G3) == 7 / 12 |