Skip to content

Commit

Permalink
Handle the case is_multigraph and max_edges is None (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmacon authored Sep 17, 2021
1 parent 672cabd commit 4e1ea0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hypothesis_networkx/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ def graph_builder(draw,
# Correct for number of edges already made if graph is connected.
# This may mean we added more edges than originally allowed.
max_edges -= len(graph.edges)
if max_edges < 0:
max_edges = 0
if max_edges < 0:
max_edges = 0

# Likewise for min_edges
# We already added some edges, so subtract those.
min_edges -= len(graph.edges)
if min_edges < 0:
min_edges = 0
elif min_edges > max_edges:
elif max_edges is not None and min_edges > max_edges:
min_edges = max_edges

def edge_filter(edge):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def test_graph_builder(data):
assert not connected or nx.is_connected(graph)


def test_multigraph_max_edges_none():
try:
graph_builder(graph_type=nx.MultiGraph, max_edges=None).example()
except Exception:
pytest.fail()


@settings(deadline=None)
@given(st.data())
def test_node_edge_data(data):
Expand Down

0 comments on commit 4e1ea0f

Please sign in to comment.