Skip to content

Commit

Permalink
Improve test coverage for random_clustered and update function names (#…
Browse files Browse the repository at this point in the history
…7273)

* Improve test_cov for random_clustered

* Add match

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>

* Cleanup invalid joint deg seq tests.

---------

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
  • Loading branch information
vanshika230 and rossbar committed Feb 14, 2024
1 parent 74ce63f commit c855557
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions networkx/generators/tests/test_random_clustered.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import pytest

import networkx
import networkx as nx


class TestRandomClusteredGraph:
def test_valid(self):
def test_custom_joint_degree_sequence(self):
node = [1, 1, 1, 2, 1, 2, 0, 0]
tri = [0, 0, 0, 0, 0, 1, 1, 1]
joint_degree_sequence = zip(node, tri)
G = networkx.random_clustered_graph(joint_degree_sequence)
G = nx.random_clustered_graph(joint_degree_sequence)
assert G.number_of_nodes() == 8
assert G.number_of_edges() == 7

def test_valid2(self):
G = networkx.random_clustered_graph(
[(1, 2), (2, 1), (1, 1), (1, 1), (1, 1), (2, 0)]
)
def test_tuple_joint_degree_sequence(self):
G = nx.random_clustered_graph([(1, 2), (2, 1), (1, 1), (1, 1), (1, 1), (2, 0)])
assert G.number_of_nodes() == 6
assert G.number_of_edges() == 10

def test_invalid1(self):
pytest.raises(
(TypeError, networkx.NetworkXError),
networkx.random_clustered_graph,
[[1, 1], [2, 1], [0, 1]],
)
def test_invalid_joint_degree_sequence_type(self):
with pytest.raises(nx.NetworkXError, match="Invalid degree sequence"):
nx.random_clustered_graph([[1, 1], [2, 1], [0, 1]])

def test_invalid2(self):
pytest.raises(
(TypeError, networkx.NetworkXError),
networkx.random_clustered_graph,
[[1, 1], [1, 2], [0, 1]],
)
def test_invalid_joint_degree_sequence_value(self):
with pytest.raises(nx.NetworkXError, match="Invalid degree sequence"):
nx.random_clustered_graph([[1, 1], [1, 2], [0, 1]])

def test_directed_graph_raises_error(self):
with pytest.raises(nx.NetworkXError, match="Directed Graph not supported"):
nx.random_clustered_graph(
[(1, 2), (2, 1), (1, 1), (1, 1), (1, 1), (2, 0)],
create_using=nx.DiGraph,
)

0 comments on commit c855557

Please sign in to comment.