Improve test coverage of find_contours

This commit is contained in:
Johannes Schönberger
2012-10-13 23:28:29 -07:00
committed by Stefan van der Walt
parent 65fdc2a3b0
commit 95d66ac5a6
2 changed files with 36 additions and 28 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ def find_contours(array, level,
"""
array = np.asarray(array, dtype=np.double)
if array.ndim != 2:
raise RuntimeError('Only 2D arrays are supported.')
raise TypeError('Only 2D arrays are supported.')
level = float(level)
if (fully_connected not in _param_options or
positive_orientation not in _param_options):
+35 -27
View File
@@ -21,34 +21,37 @@ r = np.sqrt(x**2 + y**2)
def test_binary():
contours = find_contours(a, 0.5)
ref = [[6. , 1.5],
[5. , 1.5],
[4. , 1.5],
[3. , 1.5],
[2. , 1.5],
[1.5, 2. ],
[1.5, 3. ],
[1.5, 4. ],
[1.5, 5. ],
[1.5, 6. ],
[1. , 6.5],
[0.5, 6. ],
[0.5, 5. ],
[0.5, 4. ],
[0.5, 3. ],
[0.5, 2. ],
[0.5, 1. ],
[1. , 0.5],
[2. , 0.5],
[3. , 0.5],
[4. , 0.5],
[5. , 0.5],
[6. , 0.5],
[6.5, 1. ],
[6. , 1.5]]
contours = find_contours(a, 0.5, positive_orientation='high')
assert len(contours) == 1
assert_array_equal(contours[0],
[[6. , 1.5],
[5. , 1.5],
[4. , 1.5],
[3. , 1.5],
[2. , 1.5],
[1.5, 2. ],
[1.5, 3. ],
[1.5, 4. ],
[1.5, 5. ],
[1.5, 6. ],
[1. , 6.5],
[0.5, 6. ],
[0.5, 5. ],
[0.5, 4. ],
[0.5, 3. ],
[0.5, 2. ],
[0.5, 1. ],
[1. , 0.5],
[2. , 0.5],
[3. , 0.5],
[4. , 0.5],
[5. , 0.5],
[6. , 0.5],
[6.5, 1. ],
[6. , 1.5]])
assert_array_equal(contours[0][::-1], ref)
def test_float():
@@ -70,6 +73,11 @@ def test_memory_order():
assert len(contours) == 1
def test_invalid_input():
assert_raises(ValueError, find_contours, r, 0.5, 'foo', 'bar')
assert_raises(TypeError, find_contours, r[..., None], 0.5)
if __name__ == '__main__':
from numpy.testing import run_module_suite
run_module_suite()