summaryrefslogtreecommitdiff
path: root/numpy/doc/swig
diff options
context:
space:
mode:
authorwfspotz@sandia.gov <wfspotz@sandia.gov@localhost>2007-04-06 18:00:17 +0000
committerwfspotz@sandia.gov <wfspotz@sandia.gov@localhost>2007-04-06 18:00:17 +0000
commit3322fd159715d2f3c0568cf954ea234bad8c1275 (patch)
tree2cecabf80a3c5026de51222e392bb73c247bea49 /numpy/doc/swig
parent836762a5d9836a2aff328966ae2e015872f36d32 (diff)
downloadnumpy-3322fd159715d2f3c0568cf954ea234bad8c1275.tar.gz
Added more testing of 2D typemaps, specifically error checkings
Diffstat (limited to 'numpy/doc/swig')
-rwxr-xr-xnumpy/doc/swig/testMatrix.py130
1 files changed, 128 insertions, 2 deletions
diff --git a/numpy/doc/swig/testMatrix.py b/numpy/doc/swig/testMatrix.py
index c157fb4f1..cce16b792 100755
--- a/numpy/doc/swig/testMatrix.py
+++ b/numpy/doc/swig/testMatrix.py
@@ -27,6 +27,7 @@ class MatrixTestCase(unittest.TestCase):
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 @@ class MatrixTestCase(unittest.TestCase):
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 @@ class MatrixTestCase(unittest.TestCase):
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 @@ class MatrixTestCase(unittest.TestCase):
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 @@ class MatrixTestCase(unittest.TestCase):
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 @@ class MatrixTestCase(unittest.TestCase):
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 @@ class MatrixTestCase(unittest.TestCase):
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, "... ",