summaryrefslogtreecommitdiff
path: root/numpy/testing/tests/test_utils.py
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-07-28 22:31:01 +0000
committerPauli Virtanen <pav@iki.fi>2010-07-28 22:31:01 +0000
commit1c02b2038a902dedc3d26ebc278dac8d4cb7f12f (patch)
tree047d46fe429335d3c0a3d94f878363a6eb4c5a9e /numpy/testing/tests/test_utils.py
parent67668c8c5764b8fadbd7eed68f978846fe93310e (diff)
downloadnumpy-1c02b2038a902dedc3d26ebc278dac8d4cb7f12f.tar.gz
ENH: testing: add assert_tol_equal for testing array equality with specified tolerances
Diffstat (limited to 'numpy/testing/tests/test_utils.py')
-rw-r--r--numpy/testing/tests/test_utils.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py
index fabf7a2e0..5106c1184 100644
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -336,6 +336,29 @@ class TestWarns(unittest.TestCase):
if failed:
raise AssertionError("wrong warning caught by assert_warn")
+class TestAssertAllclose(unittest.TestCase):
+ def test_simple(self):
+ x = 1e-3
+ y = 1e-9
+
+ assert_allclose(x, y, atol=1)
+ self.assertRaises(AssertionError, assert_allclose, x, y)
+
+ a = np.array([x, y, x, y])
+ b = np.array([x, y, x, x])
+
+ assert_allclose(a, b, atol=1)
+ self.assertRaises(AssertionError, assert_allclose, a, b)
+
+ b[-1] = y * (1 + 1e-8)
+ assert_allclose(a, b)
+ self.assertRaises(AssertionError, assert_allclose, a, b,
+ rtol=1e-9)
+
+ assert_allclose(6, 10, rtol=0.5)
+ self.assertRaises(AssertionError, assert_allclose, 10, 6, rtol=0.5)
+
+
class TestArrayAlmostEqualNulp(unittest.TestCase):
def test_simple(self):
dev = np.random.randn(10)