diff --git a/tests/algorithms/test_assortativity.py b/tests/algorithms/test_assortativity.py index 6fea746a0..02a5a6b34 100644 --- a/tests/algorithms/test_assortativity.py +++ b/tests/algorithms/test_assortativity.py @@ -71,6 +71,12 @@ def test_degree_assortativity(edgelist1, edgelist5): with pytest.raises(XGIError): xgi.degree_assortativity(H) + # test wrong kind + with pytest.raises(XGIError): + xgi.degree_assortativity(H1, kind="no-idea") + with pytest.raises(XGIError): + xgi.degree_assortativity(H1, kind="no-idea", exact=True) + def test_choose_degrees(edgelist1, edgelist6): H1 = xgi.Hypergraph(edgelist1) diff --git a/xgi/algorithms/assortativity.py b/xgi/algorithms/assortativity.py index b37fc683b..6e9dd7468 100644 --- a/xgi/algorithms/assortativity.py +++ b/xgi/algorithms/assortativity.py @@ -136,6 +136,8 @@ def degree_assortativity(H, kind="uniform", exact=False, num_samples=1000): for d in permutations(_choose_degrees(members[e], k, "top-bottom"), 2) # permutations is so that k1 and k2 have the same variance ] + else: + raise XGIError("Invalid type of degree assortativity!") else: edges = [e for e in H.edges if len(H.edges.members(e)) > 1] k1k2 = [ @@ -202,6 +204,6 @@ def _choose_degrees(e, k, kind="uniform"): return sorted([k[i] for i in e])[:: len(e) - 1] else: - raise XGIError("Invalid choice function!") + raise XGIError("Invalid type of degree assortativity!") else: raise XGIError("Edge must have more than one member!")