diff options
author | David Cournapeau <cournape@gmail.com> | 2008-04-08 00:06:57 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2008-04-08 00:06:57 +0000 |
commit | bfc33fd7cfef5f74d73f6df0282660e26d761942 (patch) | |
tree | 8a79e024eea28fa90dd27694316e0357c44a08a3 /numpy/testing/tests/test_utils.py | |
parent | 7e107ac18375868d8a430329c9d1237b4aaa684e (diff) | |
download | numpy-bfc33fd7cfef5f74d73f6df0282660e26d761942.tar.gz |
Add basic tests for assert_array_almost_equal.
Diffstat (limited to 'numpy/testing/tests/test_utils.py')
-rw-r--r-- | numpy/testing/tests/test_utils.py | 82 |
1 files changed, 47 insertions, 35 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 4688f4955..154c3f03e 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -1,14 +1,17 @@ import numpy as N from numpy.testing.utils import * -class TestEqual: +class _GenericTest: + def __init__(self, assert_func): + self._assert_func = assert_func + def _test_equal(self, a, b): - assert_array_equal(a, b) + self._assert_func(a, b) def _test_not_equal(self, a, b): passed = False try: - assert_array_equal(a, b) + self._assert_func(a, b) passed = True except AssertionError: pass @@ -44,38 +47,9 @@ class TestEqual: self._test_not_equal(a, b) - def test_nan_array(self): - """Test two arrays with different shapes are found not equal.""" - a = N.array([1, 2]) - b = N.array([[1, 2], [1, 2]]) - - self._test_not_equal(a, b) - - def test_string_arrays(self): - """Test two arrays with different shapes are found not equal.""" - a = N.array(['floupi', 'floupa']) - b = N.array(['floupi', 'floupa']) - - self._test_equal(a, b) - - c = N.array(['floupipi', 'floupa']) - - self._test_not_equal(c, b) - - def test_recarrays(self): - """Test record arrays.""" - a = N.empty(2, [('floupi', N.float), ('floupa', N.float)]) - a['floupi'] = [1, 2] - a['floupa'] = [1, 2] - b = a.copy() - - self._test_equal(a, b) - - c = N.empty(2, [('floupipi', N.float), ('floupa', N.float)]) - c['floupipi'] = a['floupi'].copy() - c['floupa'] = a['floupa'].copy() - - self._test_not_equal(c, b) +class TestEqual(_GenericTest): + def __init__(self): + _GenericTest.__init__(self, assert_array_equal) def test_generic_rank1(self): """Test rank 1 array for all dtypes.""" @@ -114,3 +88,41 @@ class TestEqual: # Test strings for t in ['S1', 'U1']: foo(t) + + def test_nan_array(self): + """Test two arrays with different shapes are found not equal.""" + a = N.array([1, 2]) + b = N.array([[1, 2], [1, 2]]) + + self._test_not_equal(a, b) + + def test_string_arrays(self): + """Test two arrays with different shapes are found not equal.""" + a = N.array(['floupi', 'floupa']) + b = N.array(['floupi', 'floupa']) + + self._test_equal(a, b) + + c = N.array(['floupipi', 'floupa']) + + self._test_not_equal(c, b) + + def test_recarrays(self): + """Test record arrays.""" + a = N.empty(2, [('floupi', N.float), ('floupa', N.float)]) + a['floupi'] = [1, 2] + a['floupa'] = [1, 2] + b = a.copy() + + self._test_equal(a, b) + + c = N.empty(2, [('floupipi', N.float), ('floupa', N.float)]) + c['floupipi'] = a['floupi'].copy() + c['floupa'] = a['floupa'].copy() + + self._test_not_equal(c, b) + + +class TestAlmostEqual(_GenericTest): + def __init__(self): + _GenericTest.__init__(self, assert_array_almost_equal) |