diff options
| author | Aric Hagberg <aric.hagberg@gmail.com> | 2011-12-07 17:57:10 -0700 |
|---|---|---|
| committer | Aric Hagberg <aric.hagberg@gmail.com> | 2011-12-07 17:57:10 -0700 |
| commit | 4331cbc4eacf11d62b2ccf38efdfbec6edd65895 (patch) | |
| tree | a50b20d5b22c4a8523f5249c9b49119d5be3b757 | |
| parent | c9188c78da82cbe49e8f47871194597c48b81328 (diff) | |
| download | networkx-4331cbc4eacf11d62b2ccf38efdfbec6edd65895.tar.gz | |
Raise error if k < 2.
Addresses #652
| -rw-r--r-- | networkx/algorithms/community/kclique.py | 4 | ||||
| -rw-r--r-- | networkx/algorithms/community/tests/test_kclique.py | 4 |
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)) |
