diff options
author | wfspotz@sandia.gov <wfspotz@sandia.gov@localhost> | 2007-04-05 22:20:15 +0000 |
---|---|---|
committer | wfspotz@sandia.gov <wfspotz@sandia.gov@localhost> | 2007-04-05 22:20:15 +0000 |
commit | c6992ef6631a74e204d124dd3e4c9fddc2be01a4 (patch) | |
tree | d470f7f132833e476a6620a39cc12a36fbe32d3f | |
parent | 85171803c141f9be21ce91e18957605d819641e0 (diff) | |
download | numpy-c6992ef6631a74e204d124dd3e4c9fddc2be01a4.tar.gz |
Removed test1D.py, test2D.py and test3D.py in favor of testVector.py, testMatrix.py and testTensor.py because these new tests use inheritance to duplicate same tests for different data types
-rw-r--r-- | numpy/doc/swig/Makefile | 6 | ||||
-rw-r--r-- | numpy/doc/swig/README | 12 | ||||
-rwxr-xr-x | numpy/doc/swig/test1D.py | 719 | ||||
-rwxr-xr-x | numpy/doc/swig/test2D.py | 626 | ||||
-rwxr-xr-x | numpy/doc/swig/test3D.py | 795 | ||||
-rwxr-xr-x | numpy/doc/swig/testMatrix.py | 215 | ||||
-rwxr-xr-x | numpy/doc/swig/testTensor.py | 244 | ||||
-rwxr-xr-x | numpy/doc/swig/testVector.py | 226 |
8 files changed, 694 insertions, 2149 deletions
diff --git a/numpy/doc/swig/Makefile b/numpy/doc/swig/Makefile index 593ebe01c..e6403c009 100644 --- a/numpy/doc/swig/Makefile +++ b/numpy/doc/swig/Makefile @@ -27,9 +27,9 @@ all: $(WRAPPERS) Vector.cxx Vector.h Matrix.cxx Matrix.h Tensor.cxx Tensor.h ./setup.py build test: all - test1D.py - test2D.py - test3D.py + testVector.py + testMatrix.py + testTensor.py doc: html pdf diff --git a/numpy/doc/swig/README b/numpy/doc/swig/README index c1e1a997c..40d7f9636 100644 --- a/numpy/doc/swig/README +++ b/numpy/doc/swig/README @@ -14,17 +14,17 @@ to do with numpy.i. The files related to testing are:: Vector.h Vector.cxx Vector.i - test1D.py + testVector.py Matrix.h Matrix.cxx Matrix.i - test2D.py + testMatrix.py Tensor.h Tensor.cxx Tensor.i - test3D.py + testTensor.py The header files contain prototypes for functions that illustrate the wrapping issues we wish to address. Right now, this consists of @@ -83,9 +83,9 @@ types. The source files Vector.cxx, Matrix.cxx and Tensor.cxx contain the actual implementations of the functions described in Vector.h, -Matrix.h and Tensor.h. The python scripts test1D.py, test2D.py and -test3D.py test the resulting python wrappers using the unittest -module. +Matrix.h and Tensor.h. The python scripts testVector.py, +testMatrix.py and testTensor.py test the resulting python wrappers +using the unittest module. The SWIG interface files Vector.i, Matrix.i and Tensor.i are used to generate the wrapper code. The SWIG_FILE_WITH_INIT macro allows diff --git a/numpy/doc/swig/test1D.py b/numpy/doc/swig/test1D.py deleted file mode 100755 index b1909c5b7..000000000 --- a/numpy/doc/swig/test1D.py +++ /dev/null @@ -1,719 +0,0 @@ -#! /usr/bin/env python - -# System imports -from distutils.util import get_platform -import os -import sys -import unittest - -# Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] -if major == 0: BadListError = TypeError -else: BadListError = ValueError - -# Add the distutils-generated build directory to the python search path and then -# import the extension module -libDir = "lib.%s-%s" % (get_platform(), sys.version[:3]) -sys.path.insert(0,os.path.join("build", libDir)) -import Vector - -###################################################################### - -class VectorTestCase(unittest.TestCase): - - #################################################### - ### Test functions that take arrays of type BYTE ### - def testScharLength(self): - "Test scharLength function" - self.assertEquals(Vector.scharLength([5, 12, 0]), 13) - - def testScharLengthBad(self): - "Test scharLength function for wrong size" - self.assertRaises(TypeError, Vector.scharLength, [5, 12]) - - def testScharProd(self): - "Test scharProd function" - self.assertEquals(Vector.scharProd([1,2,3,4]), 24) - - def testScharProdNonContainer(self): - "Test scharProd function with None" - self.assertRaises(TypeError, Vector.scharProd, None) - - def testScharSum(self): - "Test scharSum function" - self.assertEquals(Vector.scharSum([-5,6,-7,8]), 2) - - def testScharReverse(self): - "Test scharReverse function" - vector = N.array([1,2,4],'b') - Vector.scharReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testScharOnes(self): - "Test scharOnes function" - myArray = N.zeros(5,'b') - Vector.scharOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testScharZeros(self): - "Test scharZeros function" - myArray = N.ones(5,'b') - Vector.scharZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testScharEOSplit(self): - "Test scharEOSplit function" - even, odd = Vector.scharEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testScharTwos(self): - "Test scharTwos function" - twos = Vector.scharTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testScharThrees(self): - "Test scharThrees function" - threes = Vector.scharThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ##################################################### - ### Test functions that take arrays of type UBYTE ### - def testUcharLength(self): - "Test ucharLength function" - self.assertEquals(Vector.ucharLength([5, 12, 0]), 13) - - def testUcharLengthBad(self): - "Test ucharLength function for wrong size" - self.assertRaises(TypeError, Vector.ucharLength, [5, 12]) - - def testUcharProd(self): - "Test ucharProd function" - self.assertEquals(Vector.ucharProd([1,2,3,4]), 24) - - def testUcharProdNonContainer(self): - "Test ucharProd function with None" - self.assertRaises(TypeError, Vector.ucharProd, None) - - def testUcharSum(self): - "Test ucharSum function" - self.assertEquals(Vector.ucharSum([5,6,7,8]), 26) - - def testUcharReverse(self): - "Test ucharReverse function" - vector = N.array([1,2,4],'B') - Vector.ucharReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testUcharOnes(self): - "Test ucharOnes function" - myArray = N.zeros(5,'B') - Vector.ucharOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testUcharZeros(self): - "Test ucharZeros function" - myArray = N.ones(5,'B') - Vector.ucharZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testUcharEOSplit(self): - "Test ucharEOSplit function" - even, odd = Vector.ucharEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testUcharTwos(self): - "Test ucharTwos function" - twos = Vector.ucharTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testUcharThrees(self): - "Test ucharThrees function" - threes = Vector.ucharThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ##################################################### - ### Test functions that take arrays of type SHORT ### - def testShortLength(self): - "Test shortLength function" - self.assertEquals(Vector.shortLength([5, 12, 0]), 13) - - def testShortLengthBad(self): - "Test shortLength function for wrong size" - self.assertRaises(TypeError, Vector.shortLength, [5, 12]) - - def testShortProd(self): - "Test shortProd function" - self.assertEquals(Vector.shortProd([1,2,3,4]), 24) - - def testShortProdNonContainer(self): - "Test shortProd function with None" - self.assertRaises(TypeError, Vector.shortProd, None) - - def testShortSum(self): - "Test shortSum function" - self.assertEquals(Vector.shortSum([-5,6,-7,8]), 2) - - def testShortReverse(self): - "Test shortReverse function" - vector = N.array([1,2,4],'h') - Vector.shortReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testShortOnes(self): - "Test shortOnes function" - myArray = N.zeros(5,'h') - Vector.shortOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testShortZeros(self): - "Test shortZeros function" - myArray = N.ones(5,'h') - Vector.shortZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testShortEOSplit(self): - "Test shortEOSplit function" - even, odd = Vector.shortEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testShortTwos(self): - "Test shortTwos function" - twos = Vector.shortTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testShortThrees(self): - "Test shortThrees function" - threes = Vector.shortThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ###################################################### - ### Test functions that take arrays of type USHORT ### - def testUshortLength(self): - "Test ushortLength function" - self.assertEquals(Vector.ushortLength([5, 12, 0]), 13) - - def testUshortLengthBad(self): - "Test ushortLength function for wrong size" - self.assertRaises(TypeError, Vector.ushortLength, [5, 12]) - - def testUshortProd(self): - "Test ushortProd function" - self.assertEquals(Vector.ushortProd([1,2,3,4]), 24) - - def testUshortProdNonContainer(self): - "Test ushortProd function with None" - self.assertRaises(TypeError, Vector.ushortProd, None) - - def testUshortSum(self): - "Test ushortSum function" - self.assertEquals(Vector.ushortSum([5,6,7,8]), 26) - - def testUshortReverse(self): - "Test ushortReverse function" - vector = N.array([1,2,4],'H') - Vector.ushortReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testUshortOnes(self): - "Test ushortOnes function" - myArray = N.zeros(5,'H') - Vector.ushortOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testUshortZeros(self): - "Test ushortZeros function" - myArray = N.ones(5,'H') - Vector.ushortZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testUshortEOSplit(self): - "Test ushortEOSplit function" - even, odd = Vector.ushortEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testUshortTwos(self): - "Test ushortTwos function" - twos = Vector.ushortTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testUshortThrees(self): - "Test ushortThrees function" - threes = Vector.ushortThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ################################################### - ### Test functions that take arrays of type INT ### - def testIntLength(self): - "Test intLength function" - self.assertEquals(Vector.intLength([5, 12, 0]), 13) - - def testIntLengthBad(self): - "Test intLength function for wrong size" - self.assertRaises(TypeError, Vector.intLength, [5, 12]) - - def testIntProd(self): - "Test intProd function" - self.assertEquals(Vector.intProd([1,2,3,4]), 24) - - def testIntProdNonContainer(self): - "Test intProd function with None" - self.assertRaises(TypeError, Vector.intProd, None) - - def testIntSum(self): - "Test intSum function" - self.assertEquals(Vector.intSum([-5,6,-7,8]), 2) - - def testIntOnes(self): - "Test intOnes function" - myArray = N.zeros(5,'i') - Vector.intOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testIntReverse(self): - "Test intReverse function" - vector = N.array([1,2,4],'i') - Vector.intReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testIntZeros(self): - "Test intZeros function" - myArray = N.ones(5,'i') - Vector.intZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testIntEOSplit(self): - "Test intEOSplit function" - even, odd = Vector.intEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testIntTwos(self): - "Test intTwos function" - twos = Vector.intTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testIntThrees(self): - "Test intThrees function" - threes = Vector.intThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - #################################################### - ### Test functions that take arrays of type UINT ### - def testUintLength(self): - "Test uintLength function" - self.assertEquals(Vector.uintLength([5, 12, 0]), 13) - - def testUintLengthBad(self): - "Test uintLength function for wrong size" - - self.assertRaises(TypeError, Vector.uintLength, [5, 12]) - - def testUintProd(self): - "Test uintProd function" - self.assertEquals(Vector.uintProd([1,2,3,4]), 24) - - def testUintProdNonContainer(self): - "Test uintProd function with None" - self.assertRaises(TypeError, Vector.uintProd, None) - - def testUintSum(self): - "Test uintSum function" - self.assertEquals(Vector.uintSum([5,6,7,8]), 26) - - def testUintReverse(self): - "Test uintReverse function" - vector = N.array([1,2,4],'I') - Vector.uintReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testUintOnes(self): - "Test uintOnes function" - myArray = N.zeros(5,'I') - Vector.uintOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testUintZeros(self): - "Test uintZeros function" - myArray = N.ones(5,'I') - Vector.uintZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testUintEOSplit(self): - "Test uintEOSplit function" - even, odd = Vector.uintEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testUintTwos(self): - "Test uintTwos function" - twos = Vector.uintTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testUintThrees(self): - "Test uintThrees function" - threes = Vector.uintThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - #################################################### - ### Test functions that take arrays of type LONG ### - def testLongLength(self): - "Test longLength function" - self.assertEquals(Vector.longLength([5, 12, 0]), 13) - - def testLongLengthBad(self): - "Test longLength function for wrong size" - self.assertRaises(TypeError, Vector.longLength, [5, 12]) - - def testLongProd(self): - "Test longProd function" - self.assertEquals(Vector.longProd([1,2,3,4]), 24) - - def testLongProdNonContainer(self): - "Test longProd function with None" - self.assertRaises(TypeError, Vector.longProd, None) - - def testLongSum(self): - "Test longSum function" - self.assertEquals(Vector.longSum([-5,6,-7,8]), 2) - - def testLongReverse(self): - "Test longReverse function" - vector = N.array([1,2,4],'l') - Vector.longReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testLongOnes(self): - "Test longOnes function" - myArray = N.zeros(5,'l') - Vector.longOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testLongZeros(self): - "Test longZeros function" - myArray = N.ones(5,'l') - Vector.longZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testLongEOSplit(self): - "Test longEOSplit function" - even, odd = Vector.longEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testLongTwos(self): - "Test longTwos function" - twos = Vector.longTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testLongThrees(self): - "Test longThrees function" - threes = Vector.longThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ##################################################### - ### Test functions that take arrays of type ULONG ### - def testUlongLength(self): - "Test ulongLength function" - self.assertEquals(Vector.ulongLength([5, 12, 0]), 13) - - def testUlongLengthBad(self): - "Test ulongLength function for wrong size" - self.assertRaises(TypeError, Vector.ulongLength, [5, 12]) - - def testUlongProd(self): - "Test ulongProd function" - self.assertEquals(Vector.ulongProd([1,2,3,4]), 24) - - def testUlongProdNonContainer(self): - "Test ulongProd function with None" - self.assertRaises(TypeError, Vector.ulongProd, None) - - def testUlongSum(self): - "Test ulongSum function" - self.assertEquals(Vector.ulongSum([5,6,7,8]), 26) - - def testUlongReverse(self): - "Test ulongReverse function" - vector = N.array([1,2,4],'L') - Vector.ulongReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testUlongOnes(self): - "Test ulongOnes function" - myArray = N.zeros(5,'L') - Vector.ulongOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testUlongZeros(self): - "Test ulongZeros function" - myArray = N.ones(5,'L') - Vector.ulongZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testUlongEOSplit(self): - "Test ulongEOSplit function" - even, odd = Vector.ulongEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testUlongTwos(self): - "Test ulongTwos function" - twos = Vector.ulongTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testUlongThrees(self): - "Test ulongThrees function" - threes = Vector.ulongThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ######################################################## - ### Test functions that take arrays of type LONGLONG ### - def testLongLongLength(self): - "Test longLongLength function" - self.assertEquals(Vector.longLongLength([5, 12, 0]), 13) - - def testLongLongLengthBad(self): - "Test longLongLength function for wrong size" - self.assertRaises(TypeError, Vector.longLongLength, [5, 12]) - - def testLongLongProd(self): - "Test longLongProd function" - self.assertEquals(Vector.longLongProd([1,2,3,4]), 24) - - def testLongLongProdNonContainer(self): - "Test longLongProd function with None" - self.assertRaises(TypeError, Vector.longLongProd, None) - - def testLongLongSum(self): - "Test longLongSum function" - self.assertEquals(Vector.longLongSum([-5,6,-7,8]), 2) - - def testLongLongReverse(self): - "Test longLongReverse function" - vector = N.array([1,2,4],'q') - Vector.longLongReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testLongLongOnes(self): - "Test longLongOnes function" - myArray = N.zeros(5,'q') - Vector.longLongOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testLongLongZeros(self): - "Test longLongZeros function" - myArray = N.ones(5,'q') - Vector.longLongZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testLongLongEOSplit(self): - "Test longLongEOSplit function" - even, odd = Vector.longLongEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testLongLongTwos(self): - "Test longLongTwos function" - twos = Vector.longLongTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testLongLongThrees(self): - "Test longLongThrees function" - threes = Vector.longLongThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ######################################################### - ### Test functions that take arrays of type ULONGLONG ### - def testUlongLongLength(self): - "Test ulongLongLength function" - self.assertEquals(Vector.ulongLongLength([5, 12, 0]), 13) - - def testUlongLongLengthBad(self): - "Test ulongLongLength function for wrong size" - self.assertRaises(TypeError, Vector.ulongLongLength, [5, 12]) - - def testUlonglongProd(self): - "Test ulongLongProd function" - self.assertEquals(Vector.ulongLongProd([1,2,3,4]), 24) - - def testUlongLongProdNonContainer(self): - "Test ulongLongProd function with None" - self.assertRaises(TypeError, Vector.ulongLongProd, None) - - def testUlongLongSum(self): - "Test ulongLongSum function" - self.assertEquals(Vector.ulongLongSum([5,6,7,8]), 26) - - def testUlongLongReverse(self): - "Test ulongLongReverse function" - vector = N.array([1,2,4],'Q') - Vector.ulongLongReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testUlongLongOnes(self): - "Test ulongLongOnes function" - myArray = N.zeros(5,'Q') - Vector.ulongLongOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) - - def testUlongLongZeros(self): - "Test ulongLongZeros function" - myArray = N.ones(5,'Q') - Vector.ulongLongZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testUlongLongEOSplit(self): - "Test ulongLongEOSplit function" - even, odd = Vector.ulongLongEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testUlongLongTwos(self): - "Test ulongLongTwos function" - twos = Vector.ulongLongTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testUlongLongThrees(self): - "Test ulongLongThrees function" - threes = Vector.ulongLongThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ##################################################### - ### Test functions that take arrays of type FLOAT ### - def testFloatLength(self): - "Test floatLength function" - self.assertEquals(Vector.floatLength([5, 12, 0]), 13) - - def testFloatLengthBad(self): - "Test floatLength function for wrong size" - self.assertRaises(TypeError, Vector.floatLength, [5, 12]) - - def testFloatProd(self): - "Test floatProd function (to 5 decimal places)" - self.assertAlmostEquals(Vector.floatProd((1,2.718,3,4)), 32.616, 5) - - def testFloatProdBadContainer(self): - "Test floatProd function with an invalid list" - self.assertRaises(BadListError, Vector.floatProd, [3.14, "pi"]) - - def testFloatSum(self): - "Test floatSum function" - self.assertEquals(Vector.floatSum([-5,6,-7,8]), 2) - - def testFloatReverse(self): - "Test floatReverse function" - vector = N.array([1,2,4],'f') - Vector.floatReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testFloatOnes(self): - "Test floatOnes function" - myArray = N.zeros(5,'f') - Vector.floatOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1.,1.,1.,1.,1.])) - - def testFloatOnesNonArray(self): - "Test floatOnes function with a list" - self.assertRaises(TypeError, Vector.floatOnes, [True, 0, 2.718, "pi"]) - - def testFloatZeros(self): - "Test floatZeros function" - myArray = N.ones(5,'f') - Vector.floatZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testFloatEOSplit(self): - "Test floatEOSplit function" - even, odd = Vector.floatEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testFloatTwos(self): - "Test floatTwos function" - twos = Vector.floatTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testFloatThrees(self): - "Test floatThrees function" - threes = Vector.floatThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - - ###################################################### - ### Test functions that take arrays of type DOUBLE ### - def testDoubleLength(self): - "Test doubleLength function" - self.assertEquals(Vector.doubleLength([5, 12, 0]), 13) - - def testDoubleLengthBad(self): - "Test doubleLength function for wrong size" - self.assertRaises(TypeError, Vector.doubleLength, [5, 12]) - - def testDoubleProd(self): - "Test doubleProd function" - self.assertEquals(Vector.doubleProd((1,2.718,3,4)), 32.616) - - def testDoubleProdBadContainer(self): - "Test doubleProd function with an invalid list" - self.assertRaises(BadListError, Vector.doubleProd, [3.14, "pi"]) - - def testDoubleSum(self): - "Test doubleSum function" - self.assertEquals(Vector.doubleSum([-5,6,-7,8]), 2) - - def testDoubleReverse(self): - "Test doubleReverse function" - vector = N.array([1,2,4],'d') - Vector.doubleReverse(vector) - self.assertEquals((vector == [4,2,1]).all(), True) - - def testDoubleOnes(self): - "Test doubleOnes function" - myArray = N.zeros(5,'d') - Vector.doubleOnes(myArray) - N.testing.assert_array_equal(myArray, N.array([1.,1.,1.,1.,1.])) - - def testDoubleOnesNonArray(self): - "Test doubleOnes function with a list" - self.assertRaises(TypeError, Vector.doubleOnes, [True, 0, 2.718, "pi"]) - - def testDoubleZeros(self): - "Test doubleZeros function" - myArray = N.ones(5,'d') - Vector.doubleZeros(myArray) - N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) - - def testDoubleEOSplit(self): - "Test doubleEOSplit function" - even, odd = Vector.doubleEOSplit([1,2,3]) - self.assertEquals((even == [1,0,3]).all(), True) - self.assertEquals((odd == [0,2,0]).all(), True) - - def testDoubleTwos(self): - "Test doubleTwos function" - twos = Vector.doubleTwos(5) - self.assertEquals((twos == [2,2,2,2,2]).all(), True) - - def testDoubleThrees(self): - "Test doubleThrees function" - threes = Vector.doubleThrees(6) - self.assertEquals((threes == [3,3,3,3,3,3]).all(), True) - -###################################################################### - -if __name__ == "__main__": - - # Build the test suite - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(VectorTestCase)) - - # Execute the test suite - print "Testing 1D Functions of Module Vector" - print "NumPy version", N.__version__ - print - result = unittest.TextTestRunner(verbosity=2).run(suite) - sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/doc/swig/test2D.py b/numpy/doc/swig/test2D.py deleted file mode 100755 index 601e2c2b0..000000000 --- a/numpy/doc/swig/test2D.py +++ /dev/null @@ -1,626 +0,0 @@ -#! /usr/bin/env python - -# System imports -from distutils.util import get_platform -import os -import sys -import unittest - -# Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] -if major == 0: BadListError = TypeError -else: BadListError = ValueError - -# Add the distutils-generated build directory to the python search path and then -# import the extension module -libDir = "lib.%s-%s" % (get_platform(), sys.version[:3]) -sys.path.insert(0,os.path.join("build", libDir)) -import Matrix - -###################################################################### - -class MatrixTestCase(unittest.TestCase): - - #################################################### - ### Test functions that take arrays of type BYTE ### - def testScharDet(self): - "Test scharDet function" - matrix = [[6,7],[8,9]] - self.assertEquals(Matrix.scharDet(matrix), -2) - - def testScharMax(self): - "Test scharMax function" - matrix = [[-6,5,-4],[3,-2,1]] - self.assertEquals(Matrix.scharMax(matrix), 5) - - def testScharMaxNonContainer(self): - "Test scharMax function with None" - self.assertRaises(TypeError, Matrix.scharMax, None) - - def testScharMaxWrongDim(self): - "Test scharMax function with a 1D array" - self.assertRaises(TypeError, Matrix.scharMax, [0, -1, 2, -3]) - - def testScharMin(self): - "Test scharMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.scharMin(matrix), 4) - - def testScharScale(self): - "Test scharScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'b') - Matrix.scharScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testScharFloor(self): - "Test scharFloor function" - matrix = N.array([[10,-2],[-6,7]],'b') - Matrix.scharFloor(matrix,0) - N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]])) - - def testScharCeil(self): - "Test scharCeil function" - matrix = N.array([[10,-2],[-6,7]],'b') - Matrix.scharCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]])) - - def testScharLUSplit(self): - "Test scharLUSplit function" - lower, upper = Matrix.scharLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ##################################################### - ### Test functions that take arrays of type UBYTE ### - def testUcharDet(self): - "Test ucharDet function" - matrix = [[7,6],[9,8]] - self.assertEquals(Matrix.ucharDet(matrix), 2) - - def testUcharMax(self): - "Test ucharMax function" - matrix = [[6,5,4],[3,2,1]] - self.assertEquals(Matrix.ucharMax(matrix), 6) - - def testUcharMaxNonContainer(self): - "Test ucharMax function with None" - self.assertRaises(TypeError, Matrix.ucharMax, None) - - def testUcharMaxWrongDim(self): - "Test ucharMax function with a 1D array" - self.assertRaises(TypeError, Matrix.ucharMax, [0, 1, 2, 3]) - - def testUcharMin(self): - "Test ucharMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.ucharMin(matrix), 4) - - def testUcharScale(self): - "Test ucharScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'B') - Matrix.ucharScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testUcharFloor(self): - "Test ucharFloor function" - matrix = N.array([[10,2],[6,7]],'B') - Matrix.ucharFloor(matrix,7) - N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]])) - - def testUcharCeil(self): - "Test ucharCeil function" - matrix = N.array([[10,2],[6,7]],'B') - Matrix.ucharCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]])) - - def testUcharLUSplit(self): - "Test ucharLUSplit function" - lower, upper = Matrix.ucharLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ##################################################### - ### Test functions that take arrays of type SHORT ### - def testShortDet(self): - "Test shortDet function" - matrix = [[6,7],[8,9]] - self.assertEquals(Matrix.shortDet(matrix), -2) - - def testShortMax(self): - "Test shortMax function" - matrix = [[-6,5,-4],[3,-2,1]] - self.assertEquals(Matrix.shortMax(matrix), 5) - - def testShortMaxNonContainer(self): - "Test shortMax function with None" - self.assertRaises(TypeError, Matrix.shortMax, None) - - def testShortMaxWrongDim(self): - "Test shortMax function with a 1D array" - self.assertRaises(TypeError, Matrix.shortMax, [0, -1, 2, -3]) - - def testShortMin(self): - "Test shortMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.shortMin(matrix), 4) - - def testShortScale(self): - "Test shortScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'h') - Matrix.shortScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testShortFloor(self): - "Test shortFloor function" - matrix = N.array([[10,-2],[-6,7]],'h') - Matrix.shortFloor(matrix,0) - N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]])) - - def testShortCeil(self): - "Test shortCeil function" - matrix = N.array([[10,-2],[-6,7]],'h') - Matrix.shortCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]])) - - def testShortLUSplit(self): - "Test shortLUSplit function" - lower, upper = Matrix.shortLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ###################################################### - ### Test functions that take arrays of type USHORT ### - def testUshortDet(self): - "Test ushortDet function" - matrix = [[7,6],[9,8]] - self.assertEquals(Matrix.ushortDet(matrix), 2) - - def testUshortMax(self): - "Test ushortMax function" - matrix = [[6,5,4],[3,2,1]] - self.assertEquals(Matrix.ushortMax(matrix), 6) - - def testUshortMaxNonContainer(self): - "Test ushortMax function with None" - self.assertRaises(TypeError, Matrix.ushortMax, None) - - def testUshortMaxWrongDim(self): - "Test ushortMax function with a 1D array" - self.assertRaises(TypeError, Matrix.ushortMax, [0, 1, 2, 3]) - - def testUshortMin(self): - "Test ushortMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.ushortMin(matrix), 4) - - def testUshortScale(self): - "Test ushortScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'H') - Matrix.ushortScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testUshortFloor(self): - "Test ushortFloor function" - matrix = N.array([[10,2],[6,7]],'H') - Matrix.ushortFloor(matrix,7) - N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]])) - - def testUshortCeil(self): - "Test ushortCeil function" - matrix = N.array([[10,2],[6,7]],'H') - Matrix.ushortCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]])) - - def testUshortLUSplit(self): - "Test ushortLUSplit function" - lower, upper = Matrix.ushortLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ################################################### - ### Test functions that take arrays of type INT ### - def testIntDet(self): - "Test intDet function" - matrix = [[6,7],[8,9]] - self.assertEquals(Matrix.intDet(matrix), -2) - - def testIntMax(self): - "Test intMax function" - matrix = [[-6,5,-4],[3,-2,1]] - self.assertEquals(Matrix.intMax(matrix), 5) - - def testIntMaxNonContainer(self): - "Test intMax function with None" - self.assertRaises(TypeError, Matrix.intMax, None) - - def testIntMaxWrongDim(self): - "Test intMax function with a 1D array" - self.assertRaises(TypeError, Matrix.intMax, [0, -1, 2, -3]) - - def testIntMin(self): - "Test intMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.intMin(matrix), 4) - - def testIntScale(self): - "Test intScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'i') - Matrix.intScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testIntFloor(self): - "Test intFloor function" - matrix = N.array([[10,-2],[-6,7]],'i') - Matrix.intFloor(matrix,0) - N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]])) - - def testIntCeil(self): - "Test intCeil function" - matrix = N.array([[10,-2],[-6,7]],'i') - Matrix.intCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]])) - - def testIntLUSplit(self): - "Test intLUSplit function" - lower, upper = Matrix.intLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - #################################################### - ### Test functions that take arrays of type UINT ### - def testUintDet(self): - "Test uintDet function" - matrix = [[7,6],[9,8]] - self.assertEquals(Matrix.uintDet(matrix), 2) - - def testUintMax(self): - "Test uintMax function" - matrix = [[6,5,4],[3,2,1]] - self.assertEquals(Matrix.uintMax(matrix), 6) - - def testUintMaxNonContainer(self): - "Test uintMax function with None" - self.assertRaises(TypeError, Matrix.uintMax, None) - - def testUintMaxWrongDim(self): - "Test uintMax function with a 1D array" - self.assertRaises(TypeError, Matrix.uintMax, [0, 1, 2, 3]) - - def testUintMin(self): - "Test uintMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.uintMin(matrix), 4) - - def testUintScale(self): - "Test uintScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'I') - Matrix.uintScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testUintFloor(self): - "Test uintFloor function" - matrix = N.array([[10,2],[6,7]],'I') - Matrix.uintFloor(matrix,7) - N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]])) - - def testUintCeil(self): - "Test uintCeil function" - matrix = N.array([[10,2],[6,7]],'I') - Matrix.uintCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]])) - - def testUintLUSplit(self): - "Test uintLUSplit function" - lower, upper = Matrix.uintLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - #################################################### - ### Test functions that take arrays of type LONG ### - def testLongDet(self): - "Test longDet function" - matrix = [[6,7],[8,9]] - self.assertEquals(Matrix.longDet(matrix), -2) - - def testLongMax(self): - "Test longMax function" - matrix = [[-6,5,-4],[3,-2,1]] - self.assertEquals(Matrix.longMax(matrix), 5) - - def testLongMaxNonContainer(self): - "Test longMax function with None" - self.assertRaises(TypeError, Matrix.longMax, None) - - def testLongMaxWrongDim(self): - "Test longMax function with a 1D array" - self.assertRaises(TypeError, Matrix.longMax, [0, -1, 2, -3]) - - def testLongMin(self): - "Test longMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.longMin(matrix), 4) - - def testLongScale(self): - "Test longScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'l') - Matrix.longScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testLongFloor(self): - "Test longFloor function" - matrix = N.array([[10,-2],[-6,7]],'l') - Matrix.longFloor(matrix,0) - N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]])) - - def testLongCeil(self): - "Test longCeil function" - matrix = N.array([[10,-2],[-6,7]],'l') - Matrix.longCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]])) - - def testLongLUSplit(self): - "Test longLUSplit function" - lower, upper = Matrix.longLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ##################################################### - ### Test functions that take arrays of type ULONG ### - def testUlongDet(self): - "Test ulongDet function" - matrix = [[7,6],[9,8]] - self.assertEquals(Matrix.ulongDet(matrix), 2) - - def testUlongMax(self): - "Test ulongMax function" - matrix = [[6,5,4],[3,2,1]] - self.assertEquals(Matrix.ulongMax(matrix), 6) - - def testUlongMaxNonContainer(self): - "Test ulongMax function with None" - self.assertRaises(TypeError, Matrix.ulongMax, None) - - def testUlongMaxWrongDim(self): - "Test ulongMax function with a 1D array" - self.assertRaises(TypeError, Matrix.ulongMax, [0, 1, 2, 3]) - - def testUlongMin(self): - "Test ulongMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.ulongMin(matrix), 4) - - def testUlongScale(self): - "Test ulongScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'L') - Matrix.ulongScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testUlongFloor(self): - "Test ulongFloor function" - matrix = N.array([[10,2],[6,7]],'L') - Matrix.ulongFloor(matrix,7) - N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]])) - - def testUlongCeil(self): - "Test ulongCeil function" - matrix = N.array([[10,2],[6,7]],'L') - Matrix.ulongCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]])) - - def testUlongLUSplit(self): - "Test ulongLUSplit function" - lower, upper = Matrix.ulongLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ######################################################## - ### Test functions that take arrays of type LONGLONG ### - def testLongLongDet(self): - "Test longLongDet function" - matrix = [[6,7],[8,9]] - self.assertEquals(Matrix.longLongDet(matrix), -2) - - def testLongLongMax(self): - "Test longLongMax function" - matrix = [[-6,5,-4],[3,-2,1]] - self.assertEquals(Matrix.longLongMax(matrix), 5) - - def testLongLongMaxNonContainer(self): - "Test longLongMax function with None" - self.assertRaises(TypeError, Matrix.longLongMax, None) - - def testLongLongMaxWrongDim(self): - "Test longLongMax function with a 1D array" - self.assertRaises(TypeError, Matrix.longLongMax, [0, -1, 2, -3]) - - def testLongLongMin(self): - "Test longLongMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.longLongMin(matrix), 4) - - def testLongLongScale(self): - "Test longLongScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'q') - Matrix.longLongScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testLongLongFloor(self): - "Test longLongFloor function" - matrix = N.array([[10,-2],[-6,7]],'q') - Matrix.longLongFloor(matrix,0) - N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]])) - - def testLongLongCeil(self): - "Test longLongCeil function" - matrix = N.array([[10,-2],[-6,7]],'q') - Matrix.longLongCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]])) - - def testLongLongLUSplit(self): - "Test longLongLUSplit function" - lower, upper = Matrix.longLongLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ######################################################### - ### Test functions that take arrays of type ULONGLONG ### - def testUlongLongDet(self): - "Test ulongLongDet function" - matrix = [[7,6],[9,8]] - self.assertEquals(Matrix.ulongLongDet(matrix), 2) - - def testUlongLongMax(self): - "Test ulongLongMax function" - matrix = [[6,5,4],[3,2,1]] - self.assertEquals(Matrix.ulongLongMax(matrix), 6) - - def testUlongLongMaxNonContainer(self): - "Test ulongLongMax function with None" - self.assertRaises(TypeError, Matrix.ulongLongMax, None) - - def testUlongLongMaxWrongDim(self): - "Test ulongLongMax function with a 1D array" - self.assertRaises(TypeError, Matrix.ulongLongMax, [0, 1, 2, 3]) - - def testUlongLongMin(self): - "Test ulongLongMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.ulongLongMin(matrix), 4) - - def testUlongLongScale(self): - "Test ulongLongScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'Q') - Matrix.ulongLongScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testUlongLongFloor(self): - "Test ulongLongFloor function" - matrix = N.array([[10,2],[6,7]],'Q') - Matrix.ulongLongFloor(matrix,7) - N.testing.assert_array_equal(matrix, N.array([[10,7],[7,7]])) - - def testUlongLongCeil(self): - "Test ulongLongCeil function" - matrix = N.array([[10,2],[6,7]],'Q') - Matrix.ulongLongCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,2],[5,5]])) - - def testUlongLongLUSplit(self): - "Test ulongLongLUSplit function" - lower, upper = Matrix.ulongLongLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ##################################################### - ### Test functions that take arrays of type FLOAT ### - def testFloatDet(self): - "Test floatDet function" - matrix = [[6,7],[8,9]] - self.assertEquals(Matrix.floatDet(matrix), -2) - - def testFloatMax(self): - "Test floatMax function" - matrix = [[-6,5,-4],[3.14,-2.718,1]] - self.assertEquals(Matrix.floatMax(matrix), 5.0) - - def testFloatMaxNonContainer(self): - "Test floatMax function with None" - self.assertRaises(TypeError, Matrix.floatMax, None) - - def testFloatMaxWrongDim(self): - "Test floatMax function with a 1D array" - self.assertRaises(TypeError, Matrix.floatMax, [0.0, -1, 2.718, -3.14]) - - def testFloatMin(self): - "Test floatMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.floatMin(matrix), 4) - - def testFloatScale(self): - "Test floatScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'f') - Matrix.floatScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testFloatFloor(self): - "Test floatFloor function" - matrix = N.array([[10,-2],[-6,7]],'f') - Matrix.floatFloor(matrix,0) - N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]])) - - def testFloatCeil(self): - "Test floatCeil function" - matrix = N.array([[10,-2],[-6,7]],'f') - Matrix.floatCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]])) - - def testFloatLUSplit(self): - "Test floatLUSplit function" - lower, upper = Matrix.floatLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - - ###################################################### - ### Test functions that take arrays of type DOUBLE ### - def testDoubleDet(self): - "Test doubleDet function" - matrix = [[6,7],[8,9]] - self.assertEquals(Matrix.doubleDet(matrix), -2) - - def testDoubleMax(self): - "Test doubleMax function" - matrix = [[-6,5,-4],[3.14,-2.718,1]] - self.assertEquals(Matrix.doubleMax(matrix), 5.0) - - def testDoubleMaxNonContainer(self): - "Test doubleMax function with None" - self.assertRaises(TypeError, Matrix.doubleMax, None) - - def testDoubleMaxWrongDim(self): - "Test doubleMax function with a 1D array" - self.assertRaises(TypeError, Matrix.doubleMax, [0.0, -1, 2.718, -3.14]) - - def testDoubleMin(self): - "Test doubleMin function" - matrix = [[9,8],[7,6],[5,4]] - self.assertEquals(Matrix.doubleMin(matrix), 4) - - def testDoubleScale(self): - "Test doubleScale function" - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'d') - Matrix.doubleScale(matrix,4) - self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) - - def testDoubleFloor(self): - "Test doubleFloor function" - matrix = N.array([[10,-2],[-6,7]],'d') - Matrix.doubleFloor(matrix,0) - N.testing.assert_array_equal(matrix, N.array([[10,0],[0,7]])) - - def testDoubleCeil(self): - "Test doubleCeil function" - matrix = N.array([[10,-2],[-6,7]],'d') - Matrix.doubleCeil(matrix,5) - N.testing.assert_array_equal(matrix, N.array([[5,-2],[-6,5]])) - - def testDoubleLUSplit(self): - "Test doubleLUSplit function" - lower, upper = Matrix.doubleLUSplit([[1,2,3],[4,5,6],[7,8,9]]) - self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) - self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) - -###################################################################### - -if __name__ == "__main__": - - # Build the test suite - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(MatrixTestCase)) - - # Execute the test suite - print "Testing 2D Functions of Module Matrix" - print "NumPy version", N.__version__ - print - result = unittest.TextTestRunner(verbosity=2).run(suite) - sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/doc/swig/test3D.py b/numpy/doc/swig/test3D.py deleted file mode 100755 index ca1b90356..000000000 --- a/numpy/doc/swig/test3D.py +++ /dev/null @@ -1,795 +0,0 @@ -#! /usr/bin/env python - -# System imports -from distutils.util import get_platform -import os -import sys -import unittest - -# Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] -if major == 0: BadListError = TypeError -else: BadListError = ValueError - -# Add the distutils-generated build directory to the python search path and then -# import the extension module -libDir = "lib.%s-%s" % (get_platform(), sys.version[:3]) -sys.path.insert(0,os.path.join("build", libDir)) -import Tensor - -###################################################################### - -class TensorTestCase(unittest.TestCase): - - #################################################### - ### Test functions that take arrays of type BYTE ### - def testScharNorm(self): - "Test scharNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.scharNorm(tensor), 1) - - def testScharMax(self): - "Test scharMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.scharMax(tensor), 8) - - def testScharMaxNonContainer(self): - "Test scharMax function with None" - self.assertRaises(TypeError, Tensor.scharMax, None) - - def testScharMaxWrongDim(self): - "Test scharMax function with a 1D array" - self.assertRaises(TypeError, Tensor.scharMax, [0, -1, 2, -3]) - - def testScharMin(self): - "Test scharMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.scharMin(tensor), 2) - - def testScharScale(self): - "Test scharScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'b') - Tensor.scharScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testScharFloor(self): - "Test scharFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'b') - Tensor.scharFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testScharCeil(self): - "Test scharCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'b') - Tensor.scharCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testScharLUSplit(self): - "Test scharLUSplit function" - lower, upper = Tensor.scharLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ##################################################### - ### Test functions that take arrays of type UBYTE ### - def testUcharNorm(self): - "Test ucharNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.ucharNorm(tensor), 1) - - def testUcharMax(self): - "Test ucharMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.ucharMax(tensor), 8) - - def testUcharMaxNonContainer(self): - "Test ucharMax function with None" - self.assertRaises(TypeError, Tensor.ucharMax, None) - - def testUcharMaxWrongDim(self): - "Test ucharMax function with a 1D array" - self.assertRaises(TypeError, Tensor.ucharMax, [0, -1, 2, -3]) - - def testUcharMin(self): - "Test ucharMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.ucharMin(tensor), 2) - - def testUcharScale(self): - "Test ucharScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'B') - Tensor.ucharScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testUcharFloor(self): - "Test ucharFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'B') - Tensor.ucharFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testUcharCeil(self): - "Test ucharCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'B') - Tensor.ucharCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testUcharLUSplit(self): - "Test ucharLUSplit function" - lower, upper = Tensor.ucharLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ##################################################### - ### Test functions that take arrays of type SHORT ### - def testShortNorm(self): - "Test shortNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.shortNorm(tensor), 1) - - def testShortMax(self): - "Test shortMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.shortMax(tensor), 8) - - def testShortMaxNonContainer(self): - "Test shortMax function with None" - self.assertRaises(TypeError, Tensor.shortMax, None) - - def testShortMaxWrongDim(self): - "Test shortMax function with a 1D array" - self.assertRaises(TypeError, Tensor.shortMax, [0, -1, 2, -3]) - - def testShortMin(self): - "Test shortMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.shortMin(tensor), 2) - - def testShortScale(self): - "Test shortScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'h') - Tensor.shortScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testShortFloor(self): - "Test shortFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'h') - Tensor.shortFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testShortCeil(self): - "Test shortCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'h') - Tensor.shortCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testShortLUSplit(self): - "Test shortLUSplit function" - lower, upper = Tensor.shortLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ###################################################### - ### Test functions that take arrays of type USHORT ### - def testUshortNorm(self): - "Test ushortNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.ushortNorm(tensor), 1) - - def testUshortMax(self): - "Test ushortMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.ushortMax(tensor), 8) - - def testUshortMaxNonContainer(self): - "Test ushortMax function with None" - self.assertRaises(TypeError, Tensor.ushortMax, None) - - def testUshortMaxWrongDim(self): - "Test ushortMax function with a 1D array" - self.assertRaises(TypeError, Tensor.ushortMax, [0, -1, 2, -3]) - - def testUshortMin(self): - "Test ushortMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.ushortMin(tensor), 2) - - def testUshortScale(self): - "Test ushortScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'H') - Tensor.ushortScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testUshortFloor(self): - "Test ushortFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'H') - Tensor.ushortFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testUshortCeil(self): - "Test ushortCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'H') - Tensor.ushortCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testUshortLUSplit(self): - "Test ushortLUSplit function" - lower, upper = Tensor.ushortLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ################################################### - ### Test functions that take arrays of type INT ### - def testIntNorm(self): - "Test intNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.intNorm(tensor), 1) - - def testIntMax(self): - "Test intMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.intMax(tensor), 8) - - def testIntMaxNonContainer(self): - "Test intMax function with None" - self.assertRaises(TypeError, Tensor.intMax, None) - - def testIntMaxWrongDim(self): - "Test intMax function with a 1D array" - self.assertRaises(TypeError, Tensor.intMax, [0, -1, 2, -3]) - - def testIntMin(self): - "Test intMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.intMin(tensor), 2) - - def testIntScale(self): - "Test intScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'i') - Tensor.intScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testIntFloor(self): - "Test intFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'i') - Tensor.intFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testIntCeil(self): - "Test intCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'i') - Tensor.intCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testIntLUSplit(self): - "Test intLUSplit function" - lower, upper = Tensor.intLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - #################################################### - ### Test functions that take arrays of type UINT ### - def testUintNorm(self): - "Test uintNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.uintNorm(tensor), 1) - - def testUintMax(self): - "Test uintMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.uintMax(tensor), 8) - - def testUintMaxNonContainer(self): - "Test uintMax function with None" - self.assertRaises(TypeError, Tensor.uintMax, None) - - def testUintMaxWrongDim(self): - "Test uintMax function with a 1D array" - self.assertRaises(TypeError, Tensor.uintMax, [0, -1, 2, -3]) - - def testUintMin(self): - "Test uintMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.uintMin(tensor), 2) - - def testUintScale(self): - "Test uintScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'I') - Tensor.uintScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testUintFloor(self): - "Test uintFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'I') - Tensor.uintFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testUintCeil(self): - "Test uintCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'I') - Tensor.uintCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testUintLUSplit(self): - "Test uintLUSplit function" - lower, upper = Tensor.uintLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - #################################################### - ### Test functions that take arrays of type LONG ### - def testLongNorm(self): - "Test longNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.longNorm(tensor), 1) - - def testLongMax(self): - "Test longMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.longMax(tensor), 8) - - def testLongMaxNonContainer(self): - "Test longMax function with None" - self.assertRaises(TypeError, Tensor.longMax, None) - - def testLongMaxWrongDim(self): - "Test longMax function with a 1D array" - self.assertRaises(TypeError, Tensor.longMax, [0, -1, 2, -3]) - - def testLongMin(self): - "Test longMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.longMin(tensor), 2) - - def testLongScale(self): - "Test longScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'l') - Tensor.longScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testLongFloor(self): - "Test longFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'l') - Tensor.longFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testLongCeil(self): - "Test longCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'l') - Tensor.longCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testLongLUSplit(self): - "Test longLUSplit function" - lower, upper = Tensor.longLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ##################################################### - ### Test functions that take arrays of type ULONG ### - def testUlongNorm(self): - "Test ulongNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.ulongNorm(tensor), 1) - - def testUlongMax(self): - "Test ulongMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.ulongMax(tensor), 8) - - def testUlongMaxNonContainer(self): - "Test ulongMax function with None" - self.assertRaises(TypeError, Tensor.ulongMax, None) - - def testUlongMaxWrongDim(self): - "Test ulongMax function with a 1D array" - self.assertRaises(TypeError, Tensor.ulongMax, [0, -1, 2, -3]) - - def testUlongMin(self): - "Test ulongMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.ulongMin(tensor), 2) - - def testUlongScale(self): - "Test ulongScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'L') - Tensor.ulongScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testUlongFloor(self): - "Test ulongFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'L') - Tensor.ulongFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testUlongCeil(self): - "Test ulongCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'L') - Tensor.ulongCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testUlongLUSplit(self): - "Test ulongLUSplit function" - lower, upper = Tensor.ulongLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ######################################################## - ### Test functions that take arrays of type LONGLONG ### - def testLongLongNorm(self): - "Test longLongNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.longLongNorm(tensor), 1) - - def testLongLongMax(self): - "Test longLongMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.longLongMax(tensor), 8) - - def testLongLongMaxNonContainer(self): - "Test longLongMax function with None" - self.assertRaises(TypeError, Tensor.longLongMax, None) - - def testLongLongMaxWrongDim(self): - "Test longLongMax function with a 1D array" - self.assertRaises(TypeError, Tensor.longLongMax, [0, -1, 2, -3]) - - def testLongLongMin(self): - "Test longLongMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.longLongMin(tensor), 2) - - def testLongLongScale(self): - "Test longLongScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'q') - Tensor.longLongScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testLongLongFloor(self): - "Test longLongFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'q') - Tensor.longLongFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testLongLongCeil(self): - "Test longLongCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'q') - Tensor.longLongCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testLongLongLUSplit(self): - "Test longLongLUSplit function" - lower, upper = Tensor.longLongLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ######################################################### - ### Test functions that take arrays of type ULONGLONG ### - def testUlongLongNorm(self): - "Test ulongLongNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertEquals(Tensor.ulongLongNorm(tensor), 1) - - def testUlongLongMax(self): - "Test ulongLongMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.ulongLongMax(tensor), 8) - - def testUlongLongMaxNonContainer(self): - "Test ulongLongMax function with None" - self.assertRaises(TypeError, Tensor.ulongLongMax, None) - - def testUlongLongMaxWrongDim(self): - "Test ulongLongMax function with a 1D array" - self.assertRaises(TypeError, Tensor.ulongLongMax, [0, -1, 2, -3]) - - def testUlongLongMin(self): - "Test ulongLongMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.ulongLongMin(tensor), 2) - - def testUlongLongScale(self): - "Test ulongLongScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'Q') - Tensor.ulongLongScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testUlongLongFloor(self): - "Test ulongLongFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'Q') - Tensor.ulongLongFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testUlongLongCeil(self): - "Test ulongLongCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'Q') - Tensor.ulongLongCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testUlongLongLUSplit(self): - "Test ulongLongLUSplit function" - lower, upper = Tensor.ulongLongLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ##################################################### - ### Test functions that take arrays of type FLOAT ### - def testFloatNorm(self): - "Test floatNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertAlmostEquals(Tensor.floatNorm(tensor), 1.870828, 5) - # 1.8708286933869707 - - def testFloatMax(self): - "Test floatMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.floatMax(tensor), 8) - - def testFloatMaxNonContainer(self): - "Test floatMax function with None" - self.assertRaises(TypeError, Tensor.floatMax, None) - - def testFloatMaxWrongDim(self): - "Test floatMax function with a 1D array" - self.assertRaises(TypeError, Tensor.floatMax, [0, -1, 2, -3]) - - def testFloatMin(self): - "Test floatMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.floatMin(tensor), 2) - - def testFloatScale(self): - "Test floatScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'f') - Tensor.floatScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testFloatFloor(self): - "Test floatFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'f') - Tensor.floatFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testFloatCeil(self): - "Test floatCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'f') - Tensor.floatCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testFloatLUSplit(self): - "Test floatLUSplit function" - lower, upper = Tensor.floatLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - - ###################################################### - ### Test functions that take arrays of type DOUBLE ### - def testDoubleNorm(self): - "Test doubleNorm function" - tensor = [[[0,1], [2,3]], - [[3,2], [1,0]]] - self.assertAlmostEquals(Tensor.doubleNorm(tensor), 1.8708286933869) - - def testDoubleMax(self): - "Test doubleMax function" - tensor = [[[1,2], [3,4]], - [[5,6], [7,8]]] - self.assertEquals(Tensor.doubleMax(tensor), 8) - - def testDoubleMaxNonContainer(self): - "Test doubleMax function with None" - self.assertRaises(TypeError, Tensor.doubleMax, None) - - def testDoubleMaxWrongDim(self): - "Test doubleMax function with a 1D array" - self.assertRaises(TypeError, Tensor.doubleMax, [0, -1, 2, -3]) - - def testDoubleMin(self): - "Test doubleMin function" - tensor = [[[9,8], [7,6]], - [[5,4], [3,2]]] - self.assertEquals(Tensor.doubleMin(tensor), 2) - - def testDoubleScale(self): - "Test doubleScale function" - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], - [[0,1,0], [1,0,1], [0,1,0]], - [[1,0,1], [0,1,0], [1,0,1]]],'d') - Tensor.doubleScale(tensor,4) - self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], - [[0,4,0], [4,0,4], [0,4,0]], - [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) - - def testDoubleFloor(self): - "Test doubleFloor function" - tensor = N.array([[[1,2], [3,4]], - [[5,6], [7,8]]],'d') - Tensor.doubleFloor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], - [[5,6], [7,8]]])) - - def testDoubleCeil(self): - "Test doubleCeil function" - tensor = N.array([[[9,8], [7,6]], - [[5,4], [3,2]]],'d') - Tensor.doubleCeil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], - [[5,4], [3,2]]])) - - def testDoubleLUSplit(self): - "Test doubleLUSplit function" - lower, upper = Tensor.doubleLUSplit([[[1,1], [1,1]], - [[1,1], [1,1]]]) - self.assertEquals((lower == [[[1,1], [1,0]], - [[1,0], [0,0]]]).all(), True) - self.assertEquals((upper == [[[0,0], [0,1]], - [[0,1], [1,1]]]).all(), True) - -###################################################################### - -if __name__ == "__main__": - - # Build the test suite - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TensorTestCase)) - - # Execute the test suite - print "Testing 3D Functions of Module Tensor" - print "NumPy version", N.__version__ - print - result = unittest.TextTestRunner(verbosity=2).run(suite) - sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/doc/swig/testMatrix.py b/numpy/doc/swig/testMatrix.py new file mode 100755 index 000000000..c157fb4f1 --- /dev/null +++ b/numpy/doc/swig/testMatrix.py @@ -0,0 +1,215 @@ +#! /usr/bin/env python + +# System imports +from distutils.util import get_platform +import os +import sys +import unittest + +# Import NumPy +import numpy as N +major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +if major == 0: BadListError = TypeError +else: BadListError = ValueError + +# Add the distutils-generated build directory to the python search path and then +# import the extension module +libDir = "lib.%s-%s" % (get_platform(), sys.version[:3]) +sys.path.insert(0,os.path.join("build", libDir)) +import Matrix + +###################################################################### + +class MatrixTestCase(unittest.TestCase): + + def __init__(self, methodName="runTests"): + unittest.TestCase.__init__(self, methodName) + self.typeStr = "double" + self.typeCode = "d" + + def testDet(self): + "Test det function" + print >>sys.stderr, self.typeStr, "... ", + det = Matrix.__dict__[self.typeStr + "Det"] + matrix = [[8,7],[6,9]] + self.assertEquals(det(matrix), 30) + + def testMax(self): + "Test max function" + print >>sys.stderr, self.typeStr, "... ", + max = Matrix.__dict__[self.typeStr + "Max"] + matrix = [[6,5,4],[3,2,1]] + self.assertEquals(max(matrix), 6) + + def testMaxNonContainer(self): + "Test max function with None" + print >>sys.stderr, self.typeStr, "... ", + max = Matrix.__dict__[self.typeStr + "Max"] + self.assertRaises(TypeError, max, None) + + def testMaxWrongDim(self): + "Test max function with a 1D array" + print >>sys.stderr, self.typeStr, "... ", + max = Matrix.__dict__[self.typeStr + "Max"] + self.assertRaises(TypeError, max, [0, 1, 2, 3]) + + def testMin(self): + "Test min function" + print >>sys.stderr, self.typeStr, "... ", + min = Matrix.__dict__[self.typeStr + "Min"] + matrix = [[9,8],[7,6],[5,4]] + self.assertEquals(min(matrix), 4) + + def testScale(self): + "Test scale function" + print >>sys.stderr, self.typeStr, "... ", + scale = Matrix.__dict__[self.typeStr + "Scale"] + matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],self.typeCode) + scale(matrix,4) + self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) + + def testFloor(self): + "Test floor function" + print >>sys.stderr, self.typeStr, "... ", + floor = Matrix.__dict__[self.typeStr + "Floor"] + matrix = N.array([[6,7],[8,9]],self.typeCode) + floor(matrix,7) + N.testing.assert_array_equal(matrix, N.array([[7,7],[8,9]])) + + def testCeil(self): + "Test ceil function" + print >>sys.stderr, self.typeStr, "... ", + ceil = Matrix.__dict__[self.typeStr + "Ceil"] + matrix = N.array([[1,2],[3,4]],self.typeCode) + ceil(matrix,3) + N.testing.assert_array_equal(matrix, N.array([[1,2],[3,3]])) + + def testLUSplit(self): + "Test luSplit function" + print >>sys.stderr, self.typeStr, "... ", + luSplit = Matrix.__dict__[self.typeStr + "LUSplit"] + lower, upper = luSplit([[1,2,3],[4,5,6],[7,8,9]]) + self.assertEquals((lower == [[1,0,0],[4,5,0],[7,8,9]]).all(), True) + self.assertEquals((upper == [[0,2,3],[0,0,6],[0,0,0]]).all(), True) + +###################################################################### + +class scharTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "schar" + self.typeCode = "b" + +###################################################################### + +class ucharTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "uchar" + self.typeCode = "B" + +###################################################################### + +class shortTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "short" + self.typeCode = "h" + +###################################################################### + +class ushortTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "ushort" + self.typeCode = "H" + +###################################################################### + +class intTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "int" + self.typeCode = "i" + +###################################################################### + +class uintTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "uint" + self.typeCode = "I" + +###################################################################### + +class longTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "long" + self.typeCode = "l" + +###################################################################### + +class ulongTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "ulong" + self.typeCode = "L" + +###################################################################### + +class longLongTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "longLong" + self.typeCode = "q" + +###################################################################### + +class ulongLongTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "ulongLong" + self.typeCode = "Q" + +###################################################################### + +class floatTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "float" + self.typeCode = "f" + +###################################################################### + +class doubleTestCase(MatrixTestCase): + def __init__(self, methodName="runTest"): + MatrixTestCase.__init__(self, methodName) + self.typeStr = "double" + self.typeCode = "d" + +###################################################################### + +if __name__ == "__main__": + + # Build the test suite + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite( scharTestCase)) + suite.addTest(unittest.makeSuite( ucharTestCase)) + suite.addTest(unittest.makeSuite( shortTestCase)) + suite.addTest(unittest.makeSuite( ushortTestCase)) + suite.addTest(unittest.makeSuite( intTestCase)) + suite.addTest(unittest.makeSuite( uintTestCase)) + suite.addTest(unittest.makeSuite( longTestCase)) + suite.addTest(unittest.makeSuite( ulongTestCase)) + suite.addTest(unittest.makeSuite( longLongTestCase)) + suite.addTest(unittest.makeSuite(ulongLongTestCase)) + suite.addTest(unittest.makeSuite( floatTestCase)) + suite.addTest(unittest.makeSuite( doubleTestCase)) + + # Execute the test suite + print "Testing 2D Functions of Module Matrix" + print "NumPy version", N.__version__ + print + result = unittest.TextTestRunner(verbosity=2).run(suite) + sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/doc/swig/testTensor.py b/numpy/doc/swig/testTensor.py new file mode 100755 index 000000000..aaa56f178 --- /dev/null +++ b/numpy/doc/swig/testTensor.py @@ -0,0 +1,244 @@ +#! /usr/bin/env python + +# System imports +from distutils.util import get_platform +from math import sqrt +import os +import sys +import unittest + +# Import NumPy +import numpy as N +major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +if major == 0: BadListError = TypeError +else: BadListError = ValueError + +# Add the distutils-generated build directory to the python search path and then +# import the extension module +libDir = "lib.%s-%s" % (get_platform(), sys.version[:3]) +sys.path.insert(0,os.path.join("build", libDir)) +import Tensor + +###################################################################### + +class TensorTestCase(unittest.TestCase): + + def __init__(self, methodName="runTests"): + unittest.TestCase.__init__(self, methodName) + self.typeStr = "double" + self.typeCode = "d" + self.result = sqrt(28.0/8) + + def testNorm(self): + "Test norm function" + print >>sys.stderr, self.typeStr, "... ", + norm = Tensor.__dict__[self.typeStr + "Norm"] + tensor = [[[0,1], [2,3]], + [[3,2], [1,0]]] + if isinstance(self.result, int): + self.assertEquals(norm(tensor), self.result) + else: + self.assertAlmostEqual(norm(tensor), self.result, 6) + + def testMax(self): + "Test max function" + print >>sys.stderr, self.typeStr, "... ", + max = Tensor.__dict__[self.typeStr + "Max"] + tensor = [[[1,2], [3,4]], + [[5,6], [7,8]]] + self.assertEquals(max(tensor), 8) + + def testMaxNonContainer(self): + "Test max function with None" + print >>sys.stderr, self.typeStr, "... ", + max = Tensor.__dict__[self.typeStr + "Max"] + self.assertRaises(TypeError, max, None) + + def testMaxWrongDim(self): + "Test max function with a 1D array" + print >>sys.stderr, self.typeStr, "... ", + max = Tensor.__dict__[self.typeStr + "Max"] + self.assertRaises(TypeError, max, [0, -1, 2, -3]) + + def testMin(self): + "Test min function" + print >>sys.stderr, self.typeStr, "... ", + min = Tensor.__dict__[self.typeStr + "Min"] + tensor = [[[9,8], [7,6]], + [[5,4], [3,2]]] + self.assertEquals(min(tensor), 2) + + def testScale(self): + "Test scale function" + print >>sys.stderr, self.typeStr, "... ", + scale = Tensor.__dict__[self.typeStr + "Scale"] + tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], + [[0,1,0], [1,0,1], [0,1,0]], + [[1,0,1], [0,1,0], [1,0,1]]],self.typeCode) + scale(tensor,4) + self.assertEquals((tensor == [[[4,0,4], [0,4,0], [4,0,4]], + [[0,4,0], [4,0,4], [0,4,0]], + [[4,0,4], [0,4,0], [4,0,4]]]).all(), True) + + def testFloor(self): + "Test floor function" + print >>sys.stderr, self.typeStr, "... ", + floor = Tensor.__dict__[self.typeStr + "Floor"] + tensor = N.array([[[1,2], [3,4]], + [[5,6], [7,8]]],self.typeCode) + floor(tensor,4) + N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], + [[5,6], [7,8]]])) + + def testCeil(self): + "Test ceil function" + print >>sys.stderr, self.typeStr, "... ", + ceil = Tensor.__dict__[self.typeStr + "Ceil"] + tensor = N.array([[[9,8], [7,6]], + [[5,4], [3,2]]],self.typeCode) + ceil(tensor,5) + N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], + [[5,4], [3,2]]])) + + def testLUSplit(self): + "Test luSplit function" + print >>sys.stderr, self.typeStr, "... ", + luSplit = Tensor.__dict__[self.typeStr + "LUSplit"] + lower, upper = luSplit([[[1,1], [1,1]], + [[1,1], [1,1]]]) + self.assertEquals((lower == [[[1,1], [1,0]], + [[1,0], [0,0]]]).all(), True) + self.assertEquals((upper == [[[0,0], [0,1]], + [[0,1], [1,1]]]).all(), True) + +###################################################################### + +class scharTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "schar" + self.typeCode = "b" + self.result = int(self.result) + +###################################################################### + +class ucharTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "uchar" + self.typeCode = "B" + self.result = int(self.result) + +###################################################################### + +class shortTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "short" + self.typeCode = "h" + self.result = int(self.result) + +###################################################################### + +class ushortTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "ushort" + self.typeCode = "H" + self.result = int(self.result) + +###################################################################### + +class intTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "int" + self.typeCode = "i" + self.result = int(self.result) + +###################################################################### + +class uintTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "uint" + self.typeCode = "I" + self.result = int(self.result) + +###################################################################### + +class longTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "long" + self.typeCode = "l" + self.result = int(self.result) + +###################################################################### + +class ulongTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "ulong" + self.typeCode = "L" + self.result = int(self.result) + +###################################################################### + +class longLongTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "longLong" + self.typeCode = "q" + self.result = int(self.result) + +###################################################################### + +class ulongLongTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "ulongLong" + self.typeCode = "Q" + self.result = int(self.result) + +###################################################################### + +class floatTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "float" + self.typeCode = "f" + +###################################################################### + +class doubleTestCase(TensorTestCase): + def __init__(self, methodName="runTest"): + TensorTestCase.__init__(self, methodName) + self.typeStr = "double" + self.typeCode = "d" + +###################################################################### + +if __name__ == "__main__": + + # Build the test suite + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite( scharTestCase)) + suite.addTest(unittest.makeSuite( ucharTestCase)) + suite.addTest(unittest.makeSuite( shortTestCase)) + suite.addTest(unittest.makeSuite( ushortTestCase)) + suite.addTest(unittest.makeSuite( intTestCase)) + suite.addTest(unittest.makeSuite( uintTestCase)) + suite.addTest(unittest.makeSuite( longTestCase)) + suite.addTest(unittest.makeSuite( ulongTestCase)) + suite.addTest(unittest.makeSuite( longLongTestCase)) + suite.addTest(unittest.makeSuite(ulongLongTestCase)) + suite.addTest(unittest.makeSuite( floatTestCase)) + suite.addTest(unittest.makeSuite( doubleTestCase)) + + # Execute the test suite + print "Testing 3D Functions of Module Tensor" + print "NumPy version", N.__version__ + print + result = unittest.TextTestRunner(verbosity=2).run(suite) + sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/doc/swig/testVector.py b/numpy/doc/swig/testVector.py new file mode 100755 index 000000000..dfb49795d --- /dev/null +++ b/numpy/doc/swig/testVector.py @@ -0,0 +1,226 @@ +#! /usr/bin/env python + +# System imports +from distutils.util import get_platform +import os +import sys +import unittest + +# Import NumPy +import numpy as N +major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +if major == 0: BadListError = TypeError +else: BadListError = ValueError + +# Add the distutils-generated build directory to the python search path and then +# import the extension module +libDir = "lib.%s-%s" % (get_platform(), sys.version[:3]) +sys.path.insert(0,os.path.join("build", libDir)) +import Vector + +###################################################################### + +class VectorTestCase(unittest.TestCase): + + def __init__(self, methodName="runTest"): + unittest.TestCase.__init__(self, methodName) + self.typeStr = "double" + self.typeCode = "d" + + def testLength(self): + "Test length function" + print >>sys.stderr, self.typeStr, "... ", + length = Vector.__dict__[self.typeStr + "Length"] + self.assertEquals(length([5, 12, 0]), 13) + + def testLengthBad(self): + "Test length function for wrong size" + print >>sys.stderr, self.typeStr, "... ", + length = Vector.__dict__[self.typeStr + "Length"] + self.assertRaises(TypeError, length, [5, 12]) + + def testProd(self): + "Test prod function" + print >>sys.stderr, self.typeStr, "... ", + prod = Vector.__dict__[self.typeStr + "Prod"] + self.assertEquals(prod([1,2,3,4]), 24) + + def testProdNonContainer(self): + "Test prod function with None" + print >>sys.stderr, self.typeStr, "... ", + prod = Vector.__dict__[self.typeStr + "Prod"] + self.assertRaises(TypeError, prod, None) + + def testSum(self): + "Test sum function" + print >>sys.stderr, self.typeStr, "... ", + sum = Vector.__dict__[self.typeStr + "Sum"] + self.assertEquals(sum([5,6,7,8]), 26) + + def testReverse(self): + "Test reverse function" + print >>sys.stderr, self.typeStr, "... ", + reverse = Vector.__dict__[self.typeStr + "Reverse"] + vector = N.array([1,2,4],self.typeCode) + reverse(vector) + self.assertEquals((vector == [4,2,1]).all(), True) + + def testOnes(self): + "Test ones function" + print >>sys.stderr, self.typeStr, "... ", + ones = Vector.__dict__[self.typeStr + "Ones"] + myArray = N.zeros(5,self.typeCode) + ones(myArray) + N.testing.assert_array_equal(myArray, N.array([1,1,1,1,1])) + + def testZeros(self): + "Test zeros function" + print >>sys.stderr, self.typeStr, "... ", + zeros = Vector.__dict__[self.typeStr + "Zeros"] + myArray = N.ones(5,self.typeCode) + zeros(myArray) + N.testing.assert_array_equal(myArray, N.array([0,0,0,0,0])) + + def testEOSplit(self): + "Test eoSplit function" + print >>sys.stderr, self.typeStr, "... ", + eoSplit = Vector.__dict__[self.typeStr + "EOSplit"] + even, odd = eoSplit([1,2,3]) + self.assertEquals((even == [1,0,3]).all(), True) + self.assertEquals((odd == [0,2,0]).all(), True) + + def testTwos(self): + "Test twos function" + print >>sys.stderr, self.typeStr, "... ", + twos = Vector.__dict__[self.typeStr + "Twos"] + vector = twos(5) + self.assertEquals((vector == [2,2,2,2,2]).all(), True) + + def testThrees(self): + "Test threes function" + print >>sys.stderr, self.typeStr, "... ", + threes = Vector.__dict__[self.typeStr + "Threes"] + vector = threes(6) + self.assertEquals((vector == [3,3,3,3,3,3]).all(), True) + +###################################################################### + +class scharTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "schar" + self.typeCode = "b" + +###################################################################### + +class ucharTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "uchar" + self.typeCode = "B" + +###################################################################### + +class shortTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "short" + self.typeCode = "h" + +###################################################################### + +class ushortTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "ushort" + self.typeCode = "H" + +###################################################################### + +class intTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "int" + self.typeCode = "i" + +###################################################################### + +class uintTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "uint" + self.typeCode = "I" + +###################################################################### + +class longTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "long" + self.typeCode = "l" + +###################################################################### + +class ulongTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "ulong" + self.typeCode = "L" + +###################################################################### + +class longLongTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "longLong" + self.typeCode = "q" + +###################################################################### + +class ulongLongTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "ulongLong" + self.typeCode = "Q" + +###################################################################### + +class floatTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "float" + self.typeCode = "f" + +###################################################################### + +class doubleTestCase(VectorTestCase): + def __init__(self, methodName="runTest"): + VectorTestCase.__init__(self, methodName) + self.typeStr = "double" + self.typeCode = "d" + +###################################################################### + +if __name__ == "__main__": + + # Build the test suite + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite( scharTestCase)) + suite.addTest(unittest.makeSuite( ucharTestCase)) + suite.addTest(unittest.makeSuite( shortTestCase)) + suite.addTest(unittest.makeSuite( ushortTestCase)) + suite.addTest(unittest.makeSuite( intTestCase)) + suite.addTest(unittest.makeSuite( uintTestCase)) + suite.addTest(unittest.makeSuite( longTestCase)) + suite.addTest(unittest.makeSuite( ulongTestCase)) + suite.addTest(unittest.makeSuite( longLongTestCase)) + suite.addTest(unittest.makeSuite(ulongLongTestCase)) + suite.addTest(unittest.makeSuite( floatTestCase)) + suite.addTest(unittest.makeSuite( doubleTestCase)) + + # Execute the test suite + print "Testing 1D Functions of Module Vector" + print "NumPy version", N.__version__ + print + result = unittest.TextTestRunner(verbosity=2).run(suite) + sys.exit(len(result.errors) + len(result.failures)) |