[Numpy-svn] r3675 - trunk/numpy/doc/swig

numpy-svn@scip... numpy-svn@scip...
Fri Apr 6 13:00:21 CDT 2007


Author: wfspotz@sandia.gov
Date: 2007-04-06 13:00:17 -0500 (Fri, 06 Apr 2007)
New Revision: 3675

Modified:
   trunk/numpy/doc/swig/testMatrix.py
Log:
Added more testing of 2D typemaps, specifically error checkings

Modified: trunk/numpy/doc/swig/testMatrix.py
===================================================================
--- trunk/numpy/doc/swig/testMatrix.py	2007-04-06 17:33:48 UTC (rev 3674)
+++ trunk/numpy/doc/swig/testMatrix.py	2007-04-06 18:00:17 UTC (rev 3675)
@@ -27,6 +27,7 @@
         self.typeStr  = "double"
         self.typeCode = "d"
 
+    # Test (type IN_ARRAY2[ANY][ANY]) typemap
     def testDet(self):
         "Test det function"
         print >>sys.stderr, self.typeStr, "... ",
@@ -34,6 +35,30 @@
         matrix = [[8,7],[6,9]]
         self.assertEquals(det(matrix), 30)
 
+    # Test (type IN_ARRAY2[ANY][ANY]) typemap
+    def testDetWrongDim(self):
+        "Test det function with wrong dimensions"
+        print >>sys.stderr, self.typeStr, "... ",
+        det = Matrix.__dict__[self.typeStr + "Det"]
+        matrix = [8,7]
+        self.assertRaises(TypeError, det, matrix)
+
+    # Test (type IN_ARRAY2[ANY][ANY]) typemap
+    def testDetWrongSize(self):
+        "Test det function with wrong size"
+        print >>sys.stderr, self.typeStr, "... ",
+        det = Matrix.__dict__[self.typeStr + "Det"]
+        matrix = [[8,7,6], [5,4,3], [2,1,0]]
+        self.assertRaises(TypeError, det, matrix)
+
+    # Test (type IN_ARRAY2[ANY][ANY]) typemap
+    def testDetNonContainer(self):
+        "Test det function with non-container"
+        print >>sys.stderr, self.typeStr, "... ",
+        det = Matrix.__dict__[self.typeStr + "Det"]
+        self.assertRaises(TypeError, det, None)
+
+    # Test (type* IN_ARRAY2, int DIM1, int DIM2) typemap
     def testMax(self):
         "Test max function"
         print >>sys.stderr, self.typeStr, "... ",
@@ -41,18 +66,21 @@
         matrix = [[6,5,4],[3,2,1]]
         self.assertEquals(max(matrix), 6)
 
+    # Test (type* IN_ARRAY2, int DIM1, int DIM2) typemap
     def testMaxNonContainer(self):
-        "Test max function with None"
+        "Test max function with non-container"
         print >>sys.stderr, self.typeStr, "... ",
         max = Matrix.__dict__[self.typeStr + "Max"]
         self.assertRaises(TypeError, max, None)
 
+    # Test (type* IN_ARRAY2, int DIM1, int DIM2) typemap
     def testMaxWrongDim(self):
-        "Test max function with a 1D array"
+        "Test max function with wrong dimensions"
         print >>sys.stderr, self.typeStr, "... ",
         max = Matrix.__dict__[self.typeStr + "Max"]
         self.assertRaises(TypeError, max, [0, 1, 2, 3])
 
+    # Test (int DIM1, int DIM2, type* IN_ARRAY2) typemap
     def testMin(self):
         "Test min function"
         print >>sys.stderr, self.typeStr, "... ",
@@ -60,6 +88,21 @@
         matrix = [[9,8],[7,6],[5,4]]
         self.assertEquals(min(matrix), 4)
 
+    # Test (int DIM1, int DIM2, type* IN_ARRAY2) typemap
+    def testMinWrongDim(self):
+        "Test min function with wrong dimensions"
+        print >>sys.stderr, self.typeStr, "... ",
+        min = Matrix.__dict__[self.typeStr + "Min"]
+        self.assertRaises(TypeError, min, [1,3,5,7,9])
+
+    # Test (int DIM1, int DIM2, type* IN_ARRAY2) typemap
+    def testMinNonContainer(self):
+        "Test min function with non-container"
+        print >>sys.stderr, self.typeStr, "... ",
+        min = Matrix.__dict__[self.typeStr + "Min"]
+        self.assertRaises(TypeError, min, False)
+
+    # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap
     def testScale(self):
         "Test scale function"
         print >>sys.stderr, self.typeStr, "... ",
@@ -68,6 +111,39 @@
         scale(matrix,4)
         self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True)
 
+    # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap
+    def testScaleWrongDim(self):
+        "Test scale function with wrong dimensions"
+        print >>sys.stderr, self.typeStr, "... ",
+        scale = Matrix.__dict__[self.typeStr + "Scale"]
+        matrix = N.array([1,2,2,1],self.typeCode)
+        self.assertRaises(TypeError, scale, matrix)
+
+    # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap
+    def testScaleWrongSize(self):
+        "Test scale function with wrong size"
+        print >>sys.stderr, self.typeStr, "... ",
+        scale = Matrix.__dict__[self.typeStr + "Scale"]
+        matrix = N.array([[1,2],[2,1]],self.typeCode)
+        self.assertRaises(TypeError, scale, matrix)
+
+    # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap
+    def testScaleWrongType(self):
+        "Test scale function with wrong type"
+        print >>sys.stderr, self.typeStr, "... ",
+        scale = Matrix.__dict__[self.typeStr + "Scale"]
+        matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'c')
+        self.assertRaises(TypeError, scale, matrix)
+
+    # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap
+    def testScaleNonArray(self):
+        "Test scale function with non-array"
+        print >>sys.stderr, self.typeStr, "... ",
+        scale = Matrix.__dict__[self.typeStr + "Scale"]
+        matrix = [[1,2,3],[2,1,2],[3,2,1]]
+        self.assertRaises(TypeError, scale, matrix)
+
+    # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap
     def testFloor(self):
         "Test floor function"
         print >>sys.stderr, self.typeStr, "... ",
@@ -76,6 +152,31 @@
         floor(matrix,7)
         N.testing.assert_array_equal(matrix, N.array([[7,7],[8,9]]))
 
+    # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap
+    def testFloorWrongDim(self):
+        "Test floor function with wrong dimensions"
+        print >>sys.stderr, self.typeStr, "... ",
+        floor = Matrix.__dict__[self.typeStr + "Floor"]
+        matrix = N.array([6,7,8,9],self.typeCode)
+        self.assertRaises(TypeError, floor, matrix)
+
+    # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap
+    def testFloorWrongType(self):
+        "Test floor function with wrong type"
+        print >>sys.stderr, self.typeStr, "... ",
+        floor = Matrix.__dict__[self.typeStr + "Floor"]
+        matrix = N.array([[6,7], [8,9]],'c')
+        self.assertRaises(TypeError, floor, matrix)
+
+    # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap
+    def testFloorNonArray(self):
+        "Test floor function with non-array"
+        print >>sys.stderr, self.typeStr, "... ",
+        floor = Matrix.__dict__[self.typeStr + "Floor"]
+        matrix = [[6,7], [8,9]]
+        self.assertRaises(TypeError, floor, matrix)
+
+    # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap
     def testCeil(self):
         "Test ceil function"
         print >>sys.stderr, self.typeStr, "... ",
@@ -84,6 +185,31 @@
         ceil(matrix,3)
         N.testing.assert_array_equal(matrix, N.array([[1,2],[3,3]]))
 
+    # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap
+    def testCeilWrongDim(self):
+        "Test ceil function with wrong dimensions"
+        print >>sys.stderr, self.typeStr, "... ",
+        ceil = Matrix.__dict__[self.typeStr + "Ceil"]
+        matrix = N.array([1,2,3,4],self.typeCode)
+        self.assertRaises(TypeError, ceil, matrix)
+
+    # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap
+    def testCeilWrongType(self):
+        "Test ceil function with wrong dimensions"
+        print >>sys.stderr, self.typeStr, "... ",
+        ceil = Matrix.__dict__[self.typeStr + "Ceil"]
+        matrix = N.array([[1,2], [3,4]],'c')
+        self.assertRaises(TypeError, ceil, matrix)
+
+    # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap
+    def testCeilNonArray(self):
+        "Test ceil function with non-array"
+        print >>sys.stderr, self.typeStr, "... ",
+        ceil = Matrix.__dict__[self.typeStr + "Ceil"]
+        matrix = [[1,2], [3,4]]
+        self.assertRaises(TypeError, ceil, matrix)
+
+    # Test (type ARGOUT_ARRAY2[ANY][ANY]) typemap
     def testLUSplit(self):
         "Test luSplit function"
         print >>sys.stderr, self.typeStr, "... ",



More information about the Numpy-svn mailing list