From 6b9ecd80b91ad4c2ded3536ac34d21d09ba33bc8 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Sun, 3 Mar 2013 21:43:56 +1100 Subject: [PATCH] Add raise and labeled image tests --- skimage/morphology/tests/test_misc.py | 36 +++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/skimage/morphology/tests/test_misc.py b/skimage/morphology/tests/test_misc.py index f27b1a45..4b6e6e01 100644 --- a/skimage/morphology/tests/test_misc.py +++ b/skimage/morphology/tests/test_misc.py @@ -1,10 +1,12 @@ import numpy as np -from numpy.testing import assert_array_equal, assert_equal +from numpy.testing import assert_array_equal, assert_equal, assert_raises from skimage.morphology import remove_small_objects test_image = np.array([[0, 0, 0, 1, 0], [1, 1, 1, 0, 0], [1, 1, 1, 0, 1]], bool) + + def test_one_connectivity(): expected = np.array([[0, 0, 0, 0, 0], [1, 1, 1, 0, 0], @@ -12,19 +14,43 @@ def test_one_connectivity(): observed = remove_small_objects(test_image, min_size=6) assert_array_equal(observed, expected) + def test_two_connectivity(): expected = np.array([[0, 0, 0, 1, 0], [1, 1, 1, 0, 0], [1, 1, 1, 0, 0]], bool) - observed = remove_small_objects(test_image, min_size=7, - connectivity=2) + observed = remove_small_objects(test_image, min_size=7, connectivity=2) assert_array_equal(observed, expected) + def test_in_place(): - observed = remove_small_objects(test_image, min_size=6, - in_place=True) + observed = remove_small_objects(test_image, min_size=6, in_place=True) assert_equal(observed is test_image, True, "remove_small_objects in_place argument failed.") + +def test_labeled_image(): + labeled_image = np.array([[2, 2, 2, 0, 1], + [2, 2, 2, 0, 1], + [2, 0, 0, 0, 0], + [0, 0, 3, 3, 3]], dtype=int) + expected = np.array([[2, 2, 2, 0, 0], + [2, 2, 2, 0, 0], + [2, 0, 0, 0, 0], + [0, 0, 3, 3, 3]], dtype=int) + observed = remove_small_objects(labeled_image, min_size=3) + assert_array_equal(observed, expected) + + +def test_float_input(): + float_test = np.random.rand(5, 5) + assert_raises(TypeError, remove_small_objects, float_test) + + +def test_negative_input(): + negative_int = np.random.randint(-4, -1, size=(5, 5)) + assert_raises(ValueError, remove_small_objects, negative_int) + + if __name__ == "__main__": np.testing.run_module_suite()