diff options
author | Alan McIntyre <alan.mcintyre@local> | 2008-07-22 18:18:42 +0000 |
---|---|---|
committer | Alan McIntyre <alan.mcintyre@local> | 2008-07-22 18:18:42 +0000 |
commit | 856861c4e59c945aac844dd172fa9612623e858b (patch) | |
tree | 6a9b45a449e0a5f7e1681e3bffd19bd701910b93 /numpy/lib | |
parent | b5e26c40f2766890b600bd8b68eb01b4ec9f902b (diff) | |
download | numpy-856861c4e59c945aac844dd172fa9612623e858b.tar.gz |
Added tests to improve coverage of numpy.lib.
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/tests/test_arraysetops.py | 6 | ||||
-rw-r--r-- | numpy/lib/tests/test_format.py | 42 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 13 |
3 files changed, 60 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py index bbfaeb1fa..37a052861 100644 --- a/numpy/lib/tests/test_arraysetops.py +++ b/numpy/lib/tests/test_arraysetops.py @@ -14,6 +14,12 @@ class TestAso(TestCase): 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 ): diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index a09d4e21a..a655e490c 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -280,7 +280,7 @@ import shutil 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 @@ def test_read_version_1_0_bad_magic(): 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() diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index cab212a9a..3cc607f93 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -287,6 +287,19 @@ class TestDiff(TestCase): 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] |