aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/networkx/algorithms/community/tests/test_kclique.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/networkx/algorithms/community/tests/test_kclique.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are hereHEADmaster
Diffstat (limited to '.venv/lib/python3.12/site-packages/networkx/algorithms/community/tests/test_kclique.py')
-rw-r--r--.venv/lib/python3.12/site-packages/networkx/algorithms/community/tests/test_kclique.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/networkx/algorithms/community/tests/test_kclique.py b/.venv/lib/python3.12/site-packages/networkx/algorithms/community/tests/test_kclique.py
new file mode 100644
index 00000000..aa0b7e82
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/networkx/algorithms/community/tests/test_kclique.py
@@ -0,0 +1,91 @@
+from itertools import combinations
+
+import pytest
+
+import networkx as nx
+
+
+def test_overlapping_K5():
+ G = nx.Graph()
+ G.add_edges_from(combinations(range(5), 2)) # Add a five clique
+ G.add_edges_from(combinations(range(2, 7), 2)) # Add another five clique
+ c = list(nx.community.k_clique_communities(G, 4))
+ assert c == [frozenset(range(7))]
+ c = set(nx.community.k_clique_communities(G, 5))
+ assert c == {frozenset(range(5)), frozenset(range(2, 7))}
+
+
+def test_isolated_K5():
+ G = nx.Graph()
+ G.add_edges_from(combinations(range(5), 2)) # Add a five clique
+ G.add_edges_from(combinations(range(5, 10), 2)) # Add another five clique
+ c = set(nx.community.k_clique_communities(G, 5))
+ assert c == {frozenset(range(5)), frozenset(range(5, 10))}
+
+
+class TestZacharyKarateClub:
+ def setup_method(self):
+ self.G = nx.karate_club_graph()
+
+ def _check_communities(self, k, expected):
+ communities = set(nx.community.k_clique_communities(self.G, k))
+ assert communities == expected
+
+ def test_k2(self):
+ # clique percolation with k=2 is just connected components
+ expected = {frozenset(self.G)}
+ self._check_communities(2, expected)
+
+ def test_k3(self):
+ comm1 = [
+ 0,
+ 1,
+ 2,
+ 3,
+ 7,
+ 8,
+ 12,
+ 13,
+ 14,
+ 15,
+ 17,
+ 18,
+ 19,
+ 20,
+ 21,
+ 22,
+ 23,
+ 26,
+ 27,
+ 28,
+ 29,
+ 30,
+ 31,
+ 32,
+ 33,
+ ]
+ comm2 = [0, 4, 5, 6, 10, 16]
+ comm3 = [24, 25, 31]
+ expected = {frozenset(comm1), frozenset(comm2), frozenset(comm3)}
+ self._check_communities(3, expected)
+
+ def test_k4(self):
+ expected = {
+ frozenset([0, 1, 2, 3, 7, 13]),
+ frozenset([8, 32, 30, 33]),
+ frozenset([32, 33, 29, 23]),
+ }
+ self._check_communities(4, expected)
+
+ def test_k5(self):
+ expected = {frozenset([0, 1, 2, 3, 7, 13])}
+ self._check_communities(5, expected)
+
+ def test_k6(self):
+ expected = set()
+ self._check_communities(6, expected)
+
+
+def test_bad_k():
+ with pytest.raises(nx.NetworkXError):
+ list(nx.community.k_clique_communities(nx.Graph(), 1))