[Numpy-svn] r4983 - trunk/numpy/testing/tests

numpy-svn@scip... numpy-svn@scip...
Mon Apr 7 19:06:59 CDT 2008


Author: cdavid
Date: 2008-04-07 19:06:57 -0500 (Mon, 07 Apr 2008)
New Revision: 4983

Modified:
   trunk/numpy/testing/tests/test_utils.py
Log:
Add basic tests for assert_array_almost_equal.

Modified: trunk/numpy/testing/tests/test_utils.py
===================================================================
--- trunk/numpy/testing/tests/test_utils.py	2008-04-07 23:59:17 UTC (rev 4982)
+++ trunk/numpy/testing/tests/test_utils.py	2008-04-08 00:06:57 UTC (rev 4983)
@@ -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,39 +47,10 @@
 
         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]])
+class TestEqual(_GenericTest):
+    def __init__(self):
+        _GenericTest.__init__(self, assert_array_equal)
 
-        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)
-
     def test_generic_rank1(self):
         """Test rank 1 array for all dtypes."""
         def foo(t):
@@ -114,3 +88,41 @@
         # 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)



More information about the Numpy-svn mailing list