Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve fixes for k-components tests. #6

Open
wants to merge 1 commit into
base: fixesfortests-3.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions networkx/algorithms/approximation/tests/test_kcomponents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Test for approximation to k-components algorithm
from nose.tools import assert_equal, assert_true, assert_false, assert_raises, raises
from nose.tools import assert_equal, assert_true, assert_false
from nose.tools import assert_raises, raises, assert_greater_equal
import networkx as nx
from networkx.algorithms.approximation import k_components
from networkx.algorithms.approximation.kcomponents import _AntiGraph, _same
Expand Down Expand Up @@ -122,7 +123,7 @@ def _check_connectivity(G):
for component in components:
C = G.subgraph(component)
K = nx.node_connectivity(C)
assert_true(K >= k)
assert_greater_equal(K, k)

def test_torrents_and_ferraro_graph():
G = torrents_and_ferraro_graph()
Expand Down Expand Up @@ -151,19 +152,20 @@ def test_example_1_detail_3_and_4():
result = k_components(G)
# In this example graph there are 8 3-components, 4 with 15 nodes
# and 4 with 5 nodes.
assert_true(len(result[3]) == 8)
assert_true(len([c for c in result[3] if len(c) == 15]) == 4)
assert_true(len([c for c in result[3] if len(c) == 5]) == 4)
assert_equal(len(result[3]), 8)
assert_equal(len([c for c in result[3] if len(c) == 15]), 4)
assert_equal(len([c for c in result[3] if len(c) == 5]), 4)
# There are also 8 4-components all with 5 nodes.
assert_true(len(result[4]) == 8)
assert_equal(len(result[4]), 8)
assert_true(all(len(c) == 5 for c in result[4]))
# Finally check that the k-components detected have actually node
# connectivity >= k.
for k, components in result.items():
if k < 3:
continue
for component in components:
assert_true(nx.node_connectivity(G.subgraph(component)) >= k)
K = nx.node_connectivity(G.subgraph(component))
assert_greater_equal(K, k)

@raises(nx.NetworkXNotImplemented)
def test_directed():
Expand Down
16 changes: 9 additions & 7 deletions networkx/algorithms/connectivity/tests/test_kcomponents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Test for Moody and White k-components algorithm
from nose.tools import assert_equal, assert_true, raises
from nose.tools import assert_equal, assert_true, raises, assert_greater_equal
import networkx as nx
from networkx.algorithms.connectivity.kcomponents import (
build_k_number_dict,
Expand Down Expand Up @@ -87,7 +87,8 @@ def _check_connectivity(G):
continue
for component in components:
C = G.subgraph(component)
assert_true(nx.node_connectivity(C) >= k)
K = nx.node_connectivity(C)
assert_greater_equal(K, k)

def test_torrents_and_ferraro_graph():
G = torrents_and_ferraro_graph()
Expand Down Expand Up @@ -130,19 +131,20 @@ def test_torrents_and_ferraro_detail_3_and_4():
result = nx.k_components(G)
# In this example graph there are 8 3-components, 4 with 15 nodes
# and 4 with 5 nodes.
assert_true(len(result[3]) == 8)
assert_true(len([c for c in result[3] if len(c) == 15]) == 4)
assert_true(len([c for c in result[3] if len(c) == 5]) == 4)
assert_equal(len(result[3]), 8)
assert_equal(len([c for c in result[3] if len(c) == 15]), 4)
assert_equal(len([c for c in result[3] if len(c) == 5]), 4)
# There are also 8 4-components all with 5 nodes.
assert_true(len(result[4]) == 8)
assert_equal(len(result[4]), 8)
assert_true(all(len(c) == 5 for c in result[4]))
# Finally check that the k-components detected have actually node
# connectivity >= k.
for k, components in result.items():
if k < 3:
continue
for component in components:
assert_true(nx.node_connectivity(G.subgraph(component)) >= k)
K = nx.node_connectivity(G.subgraph(component))
assert_greater_equal(K, k)

def test_davis_southern_women():
G = nx.davis_southern_women_graph()
Expand Down