summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOkite chimaobi Samuel <okitesamuel@gmail.com>2022-11-08 22:32:11 +0100
committerGitHub <noreply@github.com>2022-11-08 13:32:11 -0800
commit12b6fb057aa6e8256bfe1231dbeb9ce3c74be01b (patch)
treee193c0275ffdd8d9be5ec07104597e55a82c1294
parent36d3412be941bc4fcae615da54d32b86fa0b8fba (diff)
downloadnetworkx-12b6fb057aa6e8256bfe1231dbeb9ce3c74be01b.tar.gz
Improve test coverage for current_flow_betweenness module (#6143)
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
-rw-r--r--networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py b/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py
index e9f5179a..4e3d4385 100644
--- a/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py
+++ b/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py
@@ -134,6 +134,11 @@ class TestApproximateFlowBetweennessCentrality:
for n in sorted(G):
np.testing.assert_allclose(b[n], b_answer[n], atol=epsilon)
+ def test_lower_kmax(self):
+ G = nx.complete_graph(4)
+ with pytest.raises(nx.NetworkXError, match="Increase kmax or epsilon"):
+ nx.approximate_current_flow_betweenness_centrality(G, kmax=4)
+
class TestWeightedFlowBetweennessCentrality:
pass
@@ -175,3 +180,18 @@ class TestEdgeFlowBetweennessCentrality:
for (s, t), v1 in b_answer.items():
v2 = b.get((s, t), b.get((t, s)))
assert v1 == pytest.approx(v2, abs=1e-7)
+
+
+@pytest.mark.parametrize(
+ "centrality_func",
+ (
+ nx.current_flow_betweenness_centrality,
+ nx.edge_current_flow_betweenness_centrality,
+ nx.approximate_current_flow_betweenness_centrality,
+ ),
+)
+def test_unconnected_graphs_betweenness_centrality(centrality_func):
+ G = nx.Graph([(1, 2), (3, 4)])
+ G.add_node(5)
+ with pytest.raises(nx.NetworkXError, match="Graph not connected"):
+ centrality_func(G)