Permalink
Browse files

TST: add regression test for connected components, see ticket 1876.

Backport of PR-484.
  • Loading branch information...
jakevdp authored and rgommers committed Mar 26, 2013
1 parent 8f33418 commit c812d1def5643a118a0e89cd2e3d4f254f8eacf7
Showing with 19 additions and 6 deletions.
  1. +19 −6 scipy/sparse/csgraph/tests/test_connected_components.py
@@ -1,7 +1,7 @@
from __future__ import division, print_function, absolute_import
import numpy as np
-from numpy.testing import assert_, assert_array_almost_equal
+from numpy.testing import assert_equal, assert_array_almost_equal
from scipy.sparse import csgraph
def test_weak_connections():
@@ -16,7 +16,7 @@ def test_weak_connections():
csgraph.connected_components(X, directed=True,
connection='weak')
- assert_(n_components == 2)
+ assert_equal(n_components, 2)
assert_array_almost_equal(labels, [0, 0, 1])
def test_strong_connections():
@@ -33,7 +33,7 @@ def test_strong_connections():
csgraph.connected_components(X, directed=True,
connection='strong')
- assert_(n_components == 3)
+ assert_equal(n_components, 3)
labels.sort()
assert_array_almost_equal(labels, [0, 1, 2])
@@ -42,7 +42,7 @@ def test_strong_connections():
csgraph.connected_components(X, directed=True,
connection='strong')
- assert_(n_components == 2)
+ assert_equal(n_components, 2)
labels.sort()
assert_array_almost_equal(labels, [0, 0, 1])
@@ -56,7 +56,7 @@ def test_strong_connections2():
n_components, labels =\
csgraph.connected_components(X, directed=True,
connection='strong')
- assert_(n_components == 5)
+ assert_equal(n_components, 5)
labels.sort()
assert_array_almost_equal(labels, [0, 1, 2, 2, 3, 4])
@@ -70,6 +70,19 @@ def test_weak_connections2():
n_components, labels =\
csgraph.connected_components(X, directed=True,
connection='weak')
- assert_(n_components == 2)
+ assert_equal(n_components, 2)
labels.sort()
assert_array_almost_equal(labels, [0, 0, 1, 1, 1, 1])
+
+def test_ticket1876():
+ # Regression test: this failed in the original implementation
+ # There should be two strongly-connected components; previously gave one
+ g = np.array([[0, 1, 1, 0],
+ [1, 0, 0, 1],
+ [0, 0, 0, 1],
+ [0, 0, 1, 0]])
+ n_components, labels = csgraph.connected_components(g, connection='strong')
+
+ assert_equal(n_components, 2)
+ assert_equal(labels[0], labels[1])
+ assert_equal(labels[2], labels[3])

0 comments on commit c812d1d

Please sign in to comment.