summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/tests/test_numeric.py104
1 files changed, 58 insertions, 46 deletions
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index a559da1b3..174a12c31 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -1224,43 +1224,14 @@ class TestIsclose(object):
rtol = 1e-5
atol = 1e-8
- def test_ip_isclose(self):
+ def setup(self):
atol = self.atol
rtol = self.rtol
-
- tests = [([inf, 0], [inf, atol*2]),
- ([atol, 1, 1e6*(1 + 2*rtol) + atol], [0, nan, 1e6]),
- (arange(3), [0, 1, 2.1]),
- (nan, [nan, nan, nan]),
- ([0], [atol, inf, -inf, nan]),
- (0, [atol, inf, -inf, nan]),
- ]
- results = [[True, False],
- [True, False, False],
- [True, True, False],
- [False, False, False],
- [True, False, False, False],
- [True, False, False, False],
- ]
-
- for (x, y), result in zip(tests, results):
- yield (assert_array_equal, isclose(x, y), result)
-
- def tst_all_isclose(self, x, y):
- assert_(all(isclose(x, y)), "%s and %s not close" % (x, y))
-
- def tst_none_isclose(self, x, y):
- msg = "%s and %s shouldn't be close"
- assert_(not any(isclose(x, y)), msg % (x, y))
-
- def test_ip_all_isclose(self):
arr = array([100,1000])
aran = arange(125).reshape((5,5,5))
- atol = self.atol
- rtol = self.rtol
-
- data = [([1, 0], [1, 0]),
+ self.all_close_tests = [
+ ([1, 0], [1, 0]),
([atol], [0]),
([1], [1 + rtol + atol]),
(arr, arr + arr*rtol),
@@ -1268,18 +1239,10 @@ class TestIsclose(object):
(aran, aran + aran*rtol),
(inf, inf),
(inf, [inf]),
- ([inf, -inf], [inf, -inf])]
-
- for (x,y) in data:
- yield (self.tst_all_isclose, x, y)
-
- def test_ip_none_isclose(self):
- aran = arange(125).reshape((5,5,5))
-
- atol = self.atol
- rtol = self.rtol
-
- data = [([inf, 0], [1, inf]),
+ ([inf, -inf], [inf, -inf]),
+ ]
+ self.none_close_tests = [
+ ([inf, 0], [1, inf]),
([inf, -inf], [1, 0]),
([inf, inf], [1, -inf]),
([inf, inf], [1, 0]),
@@ -1287,11 +1250,60 @@ class TestIsclose(object):
([atol*2], [0]),
([1], [1 + rtol + atol*2]),
(aran, aran + rtol*1.1*aran + atol*1.1),
- (array([inf, 1]), array([0, inf]))]
+ (array([inf, 1]), array([0, inf])),
+ ]
+ self.some_close_tests = [
+ ([inf, 0], [inf, atol*2]),
+ ([atol, 1, 1e6*(1 + 2*rtol) + atol], [0, nan, 1e6]),
+ (arange(3), [0, 1, 2.1]),
+ (nan, [nan, nan, nan]),
+ ([0], [atol, inf, -inf, nan]),
+ (0, [atol, inf, -inf, nan]),
+ ]
+ self.some_close_results = [
+ [True, False],
+ [True, False, False],
+ [True, True, False],
+ [False, False, False],
+ [True, False, False, False],
+ [True, False, False, False],
+ ]
- for (x,y) in data:
+ def test_ip_isclose(self):
+ self.setup()
+ tests = self.some_close_tests
+ results = self.some_close_results
+ for (x, y), result in zip(tests, results):
+ yield (assert_array_equal, isclose(x, y), result)
+
+ def tst_all_isclose(self, x, y):
+ assert_(all(isclose(x, y)), "%s and %s not close" % (x, y))
+
+ def tst_none_isclose(self, x, y):
+ msg = "%s and %s shouldn't be close"
+ assert_(not any(isclose(x, y)), msg % (x, y))
+
+ def tst_isclose_allclose(self, x, y):
+ msg = "isclose.all() and allclose aren't same for %s and %s"
+ assert_array_equal(isclose(x, y).all(), allclose(x, y), msg % (x, y))
+
+ def test_ip_all_isclose(self):
+ self.setup()
+ for (x,y) in self.all_close_tests:
+ yield (self.tst_all_isclose, x, y)
+
+ def test_ip_none_isclose(self):
+ self.setup()
+ for (x,y) in self.none_close_tests:
yield (self.tst_none_isclose, x, y)
+ def test_ip_isclose_allclose(self):
+ self.setup()
+ tests = (self.all_close_tests + self.none_close_tests +
+ self.some_close_tests)
+ for (x, y) in tests:
+ yield (self.tst_isclose_allclose, x, y)
+
def test_equal_nan(self):
assert_array_equal(isclose(nan, nan, equal_nan=True), [True])
arr = array([1.0, nan])