From eaa2aec3cc3423c60cdad604b054af1a58b7b810 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 6 Jan 2015 17:58:18 +1100 Subject: [PATCH] Add test functions for crop --- skimage/util/tests/test_arraypad.py | 42 +++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/skimage/util/tests/test_arraypad.py b/skimage/util/tests/test_arraypad.py index eb8554b1..df4f0b5e 100644 --- a/skimage/util/tests/test_arraypad.py +++ b/skimage/util/tests/test_arraypad.py @@ -5,8 +5,8 @@ from __future__ import division, absolute_import, print_function import numpy as np from numpy.testing import (assert_array_equal, assert_raises, assert_allclose, - TestCase) -from skimage.util import pad + assert_equal, TestCase) +from skimage.util import pad, crop class TestConditionalShortcuts(TestCase): @@ -1043,5 +1043,43 @@ class TypeError1(TestCase): **kwargs) +def test_multi_crop(): + arr = np.arange(45).reshape(9, 5) + out = crop(arr, (1, 2), (2, 1)) + assert_array_equal(out[0], [7, 8]) + assert_array_equal(out[-1], [32, 33]) + assert_equal(out.shape, (6, 2)) + + +def test_pair_crop(): + arr = np.arange(45).reshape(9, 5) + out = crop(arr, (1, 2)) + assert_array_equal(out[0], [6, 7]) + assert_array_equal(out[-1], [31, 32]) + assert_equal(out.shape, (6, 2)) + + +def test_int_crop(): + arr = np.arange(45).reshape(9, 5) + out = crop(arr, 1) + assert_array_equal(out[0], [6, 7, 8]) + assert_array_equal(out[-1], [36, 37, 38]) + assert_equal(out.shape, (7, 3)) + + +def test_copy_crop(): + arr = np.arange(45).reshape(9, 5) + out0 = crop(arr, 1, copy=True) + assert out0.c_contiguous + out0[0, 0] = 100 + assert not np.any(arr == 100) + assert not np.may_share_memory(arr, out0) + + out1 = crop(arr, 1) + out1[0, 0] = 100 + assert arr[1, 1] == 100 + assert np.may_share_memory(arr, out1) + + if __name__ == "__main__": np.testing.run_module_suite()