### comparison env/lib/python3.9/site-packages/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py @ 0:4f3585e2f14bdraftdefaulttip

author shellac Mon, 22 Mar 2021 18:12:50 +0000
comparison
equal inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import pytest
2
3 np = pytest.importorskip("numpy")
4 scipy = pytest.importorskip("scipy")
5
6 import networkx as nx
7 from networkx.testing import almost_equal
8
9 from networkx import edge_current_flow_betweenness_centrality as edge_current_flow
10
11 from networkx import (
12 edge_current_flow_betweenness_centrality_subset as edge_current_flow_subset,
13 )
14
15
16 class TestFlowBetweennessCentrality:
17 def test_K4_normalized(self):
18 """Betweenness centrality: K4"""
19 G = nx.complete_graph(4)
20 b = nx.current_flow_betweenness_centrality_subset(
21 G, list(G), list(G), normalized=True
22 )
24 for n in sorted(G):
26
27 def test_K4(self):
28 """Betweenness centrality: K4"""
29 G = nx.complete_graph(4)
30 b = nx.current_flow_betweenness_centrality_subset(
31 G, list(G), list(G), normalized=True
32 )
34 for n in sorted(G):
36 # test weighted network
38 b = nx.current_flow_betweenness_centrality_subset(
39 G, list(G), list(G), normalized=True, weight=None
40 )
41 for n in sorted(G):
43 b = nx.current_flow_betweenness_centrality_subset(
44 G, list(G), list(G), normalized=True
45 )
47 for n in sorted(G):
49 b = nx.current_flow_betweenness_centrality_subset(
50 G, list(G), list(G), normalized=True, weight="other"
51 )
53 G, normalized=True, weight="other"
54 )
55 for n in sorted(G):
57
58 def test_P4_normalized(self):
59 """Betweenness centrality: P4 normalized"""
60 G = nx.path_graph(4)
61 b = nx.current_flow_betweenness_centrality_subset(
62 G, list(G), list(G), normalized=True
63 )
65 for n in sorted(G):
67
68 def test_P4(self):
69 """Betweenness centrality: P4"""
70 G = nx.path_graph(4)
71 b = nx.current_flow_betweenness_centrality_subset(
72 G, list(G), list(G), normalized=True
73 )
75 for n in sorted(G):
77
78 def test_star(self):
79 """Betweenness centrality: star """
80 G = nx.Graph()
81 nx.add_star(G, ["a", "b", "c", "d"])
82 b = nx.current_flow_betweenness_centrality_subset(
83 G, list(G), list(G), normalized=True
84 )
86 for n in sorted(G):
88
89
90 # class TestWeightedFlowBetweennessCentrality():
91 # pass
92
93
94 class TestEdgeFlowBetweennessCentrality:
95 def test_K4_normalized(self):
96 """Betweenness centrality: K4"""
97 G = nx.complete_graph(4)
98 b = edge_current_flow_subset(G, list(G), list(G), normalized=True)
100 for (s, t), v1 in b_answer.items():
101 v2 = b.get((s, t), b.get((t, s)))
102 assert almost_equal(v1, v2)
103
104 def test_K4(self):
105 """Betweenness centrality: K4"""
106 G = nx.complete_graph(4)
107 b = edge_current_flow_subset(G, list(G), list(G), normalized=False)
109 for (s, t), v1 in b_answer.items():
110 v2 = b.get((s, t), b.get((t, s)))
111 assert almost_equal(v1, v2)
112 # test weighted network
114 b = edge_current_flow_subset(G, list(G), list(G), normalized=False, weight=None)
115 # weight is None => same as unweighted network
116 for (s, t), v1 in b_answer.items():
117 v2 = b.get((s, t), b.get((t, s)))
118 assert almost_equal(v1, v2)
119
120 b = edge_current_flow_subset(G, list(G), list(G), normalized=False)
122 for (s, t), v1 in b_answer.items():
123 v2 = b.get((s, t), b.get((t, s)))
124 assert almost_equal(v1, v2)
125
126 b = edge_current_flow_subset(
127 G, list(G), list(G), normalized=False, weight="other"
128 )
129 b_answer = edge_current_flow(G, normalized=False, weight="other")
130 for (s, t), v1 in b_answer.items():
131 v2 = b.get((s, t), b.get((t, s)))
132 assert almost_equal(v1, v2)
133
134 def test_C4(self):
135 """Edge betweenness centrality: C4"""
136 G = nx.cycle_graph(4)
137 b = edge_current_flow_subset(G, list(G), list(G), normalized=True)