diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-07-11 17:38:24 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-07-11 17:38:24 (GMT) |
commit | 8e0c9968731ac7f1d94bddff348544c70833b52b (patch) | |
tree | af0d4866d6dbae9e9b9003435956c6f2f7141dea /Lib/test | |
parent | 3e7428995f9d09493640326104c70a26c7cdab07 (diff) | |
download | cpython-8e0c9968731ac7f1d94bddff348544c70833b52b.zip cpython-8e0c9968731ac7f1d94bddff348544c70833b52b.tar.gz cpython-8e0c9968731ac7f1d94bddff348544c70833b52b.tar.bz2 |
Issue #9165: Add math.isfinite and cmath.isfinite.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_cmath.py | 9 | ||||
-rw-r--r-- | Lib/test/test_math.py | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index e6c80d2..a589f8d 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -442,6 +442,15 @@ class CMathTests(unittest.TestCase): self.assertCEqual(rect(1, pi/2), (0, 1.)) self.assertCEqual(rect(1, -pi/2), (0, -1.)) + def test_isfinite(self): + real_vals = [float('-inf'), -2.3, -0.0, + 0.0, 2.3, float('inf'), float('nan')] + for x in real_vals: + for y in real_vals: + z = complex(x, y) + self.assertEquals(cmath.isfinite(z), + math.isfinite(x) and math.isfinite(y)) + def test_isnan(self): self.assertFalse(cmath.isnan(1)) self.assertFalse(cmath.isnan(1j)) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 12e7f98..90bd363 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -915,6 +915,15 @@ class MathTests(unittest.TestCase): self.assertRaises(TypeError, math.trunc, 1, 2) self.assertRaises(TypeError, math.trunc, TestNoTrunc()) + def testIsfinite(self): + self.assertTrue(math.isfinite(0.0)) + self.assertTrue(math.isfinite(-0.0)) + self.assertTrue(math.isfinite(1.0)) + self.assertTrue(math.isfinite(-1.0)) + self.assertFalse(math.isfinite(float("nan"))) + self.assertFalse(math.isfinite(float("inf"))) + self.assertFalse(math.isfinite(float("-inf"))) + def testIsnan(self): self.assertTrue(math.isnan(float("nan"))) self.assertTrue(math.isnan(float("inf")* 0.)) |