Skip to content

Commit 57baf05

Browse files
committed
Add tests for centrality edge cases
1 parent f308527 commit 57baf05

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,19 @@ def test_epsilon_validation(self):
181181

182182
def test_normalization_edge_case_small_graph(self):
183183
G = nx.path_graph(2)
184-
with pytest.raises(nx.NetworkXError, match="Graph has fewer than 3 nodes"):
185-
approximate_cfbc(G, normalized=True)
186184

187-
result = approximate_cfbc(G, normalized=False, seed=42)
188-
assert len(result) == 2
185+
result_norm = approximate_cfbc(G, normalized=True, seed=42)
186+
result_unnorm = approximate_cfbc(G, normalized=False, seed=42)
187+
188+
assert len(result_norm) == 2
189+
assert len(result_unnorm) == 2
190+
assert all(v == 0.0 for v in result_norm.values())
191+
assert all(v == 0.0 for v in result_unnorm.values())
192+
193+
G1 = nx.Graph()
194+
G1.add_node(0)
195+
result1 = approximate_cfbc(G1, normalized=True, seed=42)
196+
assert result1 == {0: 0.0}
189197

190198
def test_sample_weight_interaction_with_kmax(self):
191199
G = nx.complete_graph(4)

0 commit comments

Comments
 (0)