summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorDenis Laxalde <denis@laxalde.org>2012-05-08 15:06:29 -0400
committerDenis Laxalde <denis@laxalde.org>2012-05-08 15:34:19 -0400
commit5bc0a84022c2c65addf306f50eef6f37244ae595 (patch)
tree813f6b5d52727c72218b847d83ac2b28dfcd706e /numpy
parentc869d124d08665b703539c9b2f14ec6ffbae0be0 (diff)
downloadnumpy-5bc0a84022c2c65addf306f50eef6f37244ae595.tar.gz
TST: add tests for roll function
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_numeric.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 5233d0f88..9153f0d90 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -1570,5 +1570,27 @@ class TestStringFunction(object):
np.set_string_function(None, repr=False)
assert_equal(str(a), "[1]")
+class TestRoll(TestCase):
+ def test_roll1d(self):
+ x = np.arange(10)
+ xr = np.roll(x, 2)
+ assert_equal(xr, np.array([8, 9, 0, 1, 2, 3, 4, 5, 6, 7]))
+
+ def test_roll2d(self):
+ x2 = np.reshape(np.arange(10), (2,5))
+ x2r = np.roll(x2, 1)
+ assert_equal(x2r, np.array([[9, 0, 1, 2, 3], [4, 5, 6, 7, 8]]))
+
+ x2r = np.roll(x2, 1, axis=0)
+ assert_equal(x2r, np.array([[5, 6, 7, 8, 9], [0, 1, 2, 3, 4]]))
+
+ x2r = np.roll(x2, 1, axis=1)
+ assert_equal(x2r, np.array([[4, 0, 1, 2, 3], [9, 5, 6, 7, 8]]))
+
+ def test_roll_empty(self):
+ x = np.array([])
+ assert_equal(np.roll(x, 1), np.array([]))
+
+
if __name__ == "__main__":
run_module_suite()