[Numpy-svn] r5501 - trunk/numpy/lib/tests

numpy-svn@scip... numpy-svn@scip...
Tue Jul 22 13:18:47 CDT 2008


Author: alan.mcintyre
Date: 2008-07-22 13:18:42 -0500 (Tue, 22 Jul 2008)
New Revision: 5501

Modified:
   trunk/numpy/lib/tests/test_arraysetops.py
   trunk/numpy/lib/tests/test_format.py
   trunk/numpy/lib/tests/test_function_base.py
Log:
Added tests to improve coverage of numpy.lib.


Modified: trunk/numpy/lib/tests/test_arraysetops.py
===================================================================
--- trunk/numpy/lib/tests/test_arraysetops.py	2008-07-22 16:40:24 UTC (rev 5500)
+++ trunk/numpy/lib/tests/test_arraysetops.py	2008-07-22 18:18:42 UTC (rev 5501)
@@ -14,6 +14,12 @@
         c = unique1d( a )
         assert_array_equal( c, ec )
 
+        d, c = unique1d( a, True )
+        ed = np.array( [2, 3, 0, 1] )
+        
+        assert_array_equal( d,ed )
+        assert_array_equal( c, ec )
+
         assert_array_equal([], unique1d([]))
 
     def test_intersect1d( self ):

Modified: trunk/numpy/lib/tests/test_format.py
===================================================================
--- trunk/numpy/lib/tests/test_format.py	2008-07-22 16:40:24 UTC (rev 5500)
+++ trunk/numpy/lib/tests/test_format.py	2008-07-22 18:18:42 UTC (rev 5501)
@@ -280,7 +280,7 @@
 import tempfile
 
 import numpy as np
-from numpy.testing import assert_array_equal, raises
+from numpy.testing import *
 
 from numpy.lib import format
 
@@ -506,6 +506,46 @@
         f = StringIO(magic)
         yield raises(ValueError)(format.read_array), f
 
+def test_bad_magic_args():
+    assert_raises(ValueError, format.magic, -1, 1)
+    assert_raises(ValueError, format.magic, 256, 1)
+    assert_raises(ValueError, format.magic, 1, -1)
+    assert_raises(ValueError, format.magic, 1, 256)
 
+def test_large_header():
+    s = StringIO()
+    d = {'a':1,'b':2}
+    format.write_array_header_1_0(s,d)
+
+    s = StringIO()
+    d = {'a':1,'b':2,'c':'x'*256*256}
+    assert_raises(ValueError, format.write_array_header_1_0, s, d)
+
+def test_bad_header():
+    # header of length less than 2 should fail
+    s = StringIO()
+    assert_raises(ValueError, format.read_array_header_1_0, s)
+    s = StringIO('1')
+    assert_raises(ValueError, format.read_array_header_1_0, s)
+
+    # header shorter than indicated size should fail
+    s = StringIO('\x01\x00')
+    assert_raises(ValueError, format.read_array_header_1_0, s)
+
+    # headers without the exact keys required should fail
+    d = {"shape":(1,2),
+         "descr":"x"}
+    s = StringIO()
+    format.write_array_header_1_0(s,d)
+    assert_raises(ValueError, format.read_array_header_1_0, s)
+
+    d = {"shape":(1,2),
+         "fortran_order":False,
+         "descr":"x",
+         "extrakey":-1}
+    s = StringIO()
+    format.write_array_header_1_0(s,d)
+    assert_raises(ValueError, format.read_array_header_1_0, s)
+
 if __name__ == "__main__":
     run_module_suite()

Modified: trunk/numpy/lib/tests/test_function_base.py
===================================================================
--- trunk/numpy/lib/tests/test_function_base.py	2008-07-22 16:40:24 UTC (rev 5500)
+++ trunk/numpy/lib/tests/test_function_base.py	2008-07-22 18:18:42 UTC (rev 5501)
@@ -287,6 +287,19 @@
         assert_array_equal(diff(x,axis=0),out3)
         assert_array_equal(diff(x,n=2,axis=0),out4)
 
+class TestGradient(TestCase):
+    def test_basic(self):
+        x = array([[1,1],[3,4]])
+        dx = [array([[2.,3.],[2.,3.]]),
+              array([[0.,0.],[1.,1.]])]
+        assert_array_equal(gradient(x), dx)
+
+    def test_badargs(self):
+        # for 2D array, gradient can take 0,1, or 2 extra args
+        x = array([[1,1],[3,4]])
+        assert_raises(SyntaxError, gradient, x, array([1.,1.]), 
+                      array([1.,1.]), array([1.,1.]))
+
 class TestAngle(TestCase):
     def test_basic(self):
         x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]



More information about the Numpy-svn mailing list