[Numpy-svn] r4966 - trunk/numpy/core/tests

numpy-svn@scip... numpy-svn@scip...
Sat Apr 5 17:35:00 CDT 2008


Author: stefan
Date: 2008-04-05 17:34:51 -0500 (Sat, 05 Apr 2008)
New Revision: 4966

Modified:
   trunk/numpy/core/tests/test_multiarray.py
   trunk/numpy/core/tests/test_scalarmath.py
Log:
Add tests for changeset 4822 [patch by Anne Archibald].


Modified: trunk/numpy/core/tests/test_multiarray.py
===================================================================
--- trunk/numpy/core/tests/test_multiarray.py	2008-04-05 22:28:10 UTC (rev 4965)
+++ trunk/numpy/core/tests/test_multiarray.py	2008-04-05 22:34:51 UTC (rev 4966)
@@ -217,6 +217,50 @@
         x = array(2)
         self.failUnlessRaises(ValueError, add, x, [1], x)
 
+class TestScalarIndexing(NumpyTestCase):
+    def setUp(self):
+        self.d = array([0,1])[0], 
+
+    def check_ellipsis_subscript(self):
+        a, = self.d
+        self.failUnlessEqual(a[...], 0)
+        self.failUnlessEqual(a[...].shape,())
+
+    def check_empty_subscript(self):
+        a, = self.d
+        self.failUnlessEqual(a[()], 0)
+        self.failUnlessEqual(a[()].shape,())
+
+    def check_invalid_subscript(self):
+        a, = self.d
+        self.failUnlessRaises(IndexError, lambda x: x[0], a)
+        self.failUnlessRaises(IndexError, lambda x: x[array([], int)], a)
+
+    def check_invalid_subscript_assignment(self):
+        a, = self.d
+        def assign(x, i, v):
+            x[i] = v
+        self.failUnlessRaises(TypeError, assign, a, 0, 42)
+
+    def check_newaxis(self):
+        a, = self.d
+        self.failUnlessEqual(a[newaxis].shape, (1,))
+        self.failUnlessEqual(a[..., newaxis].shape, (1,))
+        self.failUnlessEqual(a[newaxis, ...].shape, (1,))
+        self.failUnlessEqual(a[..., newaxis].shape, (1,))
+        self.failUnlessEqual(a[newaxis, ..., newaxis].shape, (1,1))
+        self.failUnlessEqual(a[..., newaxis, newaxis].shape, (1,1))
+        self.failUnlessEqual(a[newaxis, newaxis, ...].shape, (1,1))
+        self.failUnlessEqual(a[(newaxis,)*10].shape, (1,)*10)
+
+    def check_invalid_newaxis(self):
+        a, = self.d
+        def subscript(x, i): x[i]
+        self.failUnlessRaises(IndexError, subscript, a, (newaxis, 0))
+        self.failUnlessRaises(IndexError, subscript, a, (newaxis,)*50)
+
+
+
 class TestCreation(NumpyTestCase):
     def check_from_attribute(self):
         class x(object):

Modified: trunk/numpy/core/tests/test_scalarmath.py
===================================================================
--- trunk/numpy/core/tests/test_scalarmath.py	2008-04-05 22:28:10 UTC (rev 4965)
+++ trunk/numpy/core/tests/test_scalarmath.py	2008-04-05 22:34:51 UTC (rev 4966)
@@ -72,15 +72,6 @@
 #            val2 = eval(val_repr)
 #            assert_equal( val, val2 )
 
-class TestIndexing(NumpyTestCase):
-    def test_basic(self):
-        for t in types:
-            value = t(1)
-            x = value
-            assert_array_equal(x[...],value)
-            assert_array_equal(x[()],value)
-            assert_equal(x[None,...].shape,(1,))
-
 class TestRepr(NumpyTestCase):
     def check_float_repr(self):
         from numpy import nan, inf



More information about the Numpy-svn mailing list