summaryrefslogtreecommitdiff
path: root/Lib/test/test_math.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-01-28 13:59:56 -0800
committerGitHub <noreply@github.com>2019-01-28 13:59:56 -0800
commit808180c206fbde390d9dbdf24a8989fc8a6446ec (patch)
tree2e433b434572696ff09dcfa9c78bb84eef5054b3 /Lib/test/test_math.py
parentea446409cd5f1364beafd5e5255da6799993f285 (diff)
downloadcpython-git-808180c206fbde390d9dbdf24a8989fc8a6446ec.tar.gz
Fast path for int inputs to math.dist() and math.hypot() (GH-11692)
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r--Lib/test/test_math.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index b476a39e0a..f9b11f3f74 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -766,6 +766,9 @@ class MathTests(unittest.TestCase):
hypot(x=1)
with self.assertRaises(TypeError): # Reject values without __float__
hypot(1.1, 'string', 2.2)
+ int_too_big_for_float = 10 ** (sys.float_info.max_10_exp + 5)
+ with self.assertRaises((ValueError, OverflowError)):
+ hypot(1, int_too_big_for_float)
# Any infinity gives positive infinity.
self.assertEqual(hypot(INF), INF)
@@ -805,7 +808,8 @@ class MathTests(unittest.TestCase):
dist = math.dist
sqrt = math.sqrt
- # Simple exact case
+ # Simple exact cases
+ self.assertEqual(dist((1.0, 2.0, 3.0), (4.0, 2.0, -1.0)), 5.0)
self.assertEqual(dist((1, 2, 3), (4, 2, -1)), 5.0)
# Test different numbers of arguments (from zero to nine)
@@ -869,6 +873,11 @@ class MathTests(unittest.TestCase):
dist((1, 2, 3), (4, 5, 6, 7))
with self.assertRaises(TypeError): # Rejects invalid types
dist("abc", "xyz")
+ int_too_big_for_float = 10 ** (sys.float_info.max_10_exp + 5)
+ with self.assertRaises((ValueError, OverflowError)):
+ dist((1, int_too_big_for_float), (2, 3))
+ with self.assertRaises((ValueError, OverflowError)):
+ dist((2, 3), (1, int_too_big_for_float))
# Verify that the one dimensional case is equivalent to abs()
for i in range(20):