summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networkx/algorithms/community/kclique.py4
-rw-r--r--networkx/algorithms/community/tests/test_kclique.py4
2 files changed, 7 insertions, 1 deletions
diff --git a/networkx/algorithms/community/kclique.py b/networkx/algorithms/community/kclique.py
index 1d241209..dc95b58f 100644
--- a/networkx/algorithms/community/kclique.py
+++ b/networkx/algorithms/community/kclique.py
@@ -11,7 +11,7 @@ __author__ = """\n""".join(['Conrad Lee <conradlee@gmail.com>',
__all__ = ['k_clique_communities']
def k_clique_communities(G, k, cliques=None):
- """Find k-clique communities in graph using percolation method.
+ """Find k-clique communities in graph using the percolation method.
A k-clique community is the union of all cliques of size k that
can be reached through adjacent (sharing k-1 nodes) k-cliques.
@@ -48,6 +48,8 @@ def k_clique_communities(G, k, cliques=None):
in nature and society Nature 435, 814-818, 2005,
doi:10.1038/nature03607
"""
+ if k < 2:
+ raise nx.NetworkXError("k=%d, k must be greater than 1."%k)
if cliques is None:
cliques = nx.find_cliques(G)
cliques = [frozenset(c) for c in cliques if len(c) >= k]
diff --git a/networkx/algorithms/community/tests/test_kclique.py b/networkx/algorithms/community/tests/test_kclique.py
index 60be1754..8debca68 100644
--- a/networkx/algorithms/community/tests/test_kclique.py
+++ b/networkx/algorithms/community/tests/test_kclique.py
@@ -40,3 +40,7 @@ def test_zachary():
assert set(k_clique_communities(z, 4)) == zachary_k4_ground_truth
assert set(k_clique_communities(z, 5)) == zachary_k5_ground_truth
assert set(k_clique_communities(z, 6)) == zachary_k6_ground_truth
+
+@raises(nx.NetworkXError)
+def test_bad_k():
+ c = list(k_clique_communities(nx.Graph(),1))