diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-06-17 16:57:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-17 16:57:27 +0300 |
commit | 231aad38493c871dd32930a21d256cbacd2ae20c (patch) | |
tree | 93c8e378e647443dcbcbc25b2c35e9052bcbef31 /Lib/test/test_math.py | |
parent | 1ce2656f13e726b3b99d4c968926908cff1f460a (diff) | |
download | cpython-git-231aad38493c871dd32930a21d256cbacd2ae20c.tar.gz |
bpo-37315: Deprecate accepting floats in math.factorial(). (GH-14147)
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r-- | Lib/test/test_math.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index adefa07a40..f25913941b 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -501,21 +501,25 @@ class MathTests(unittest.TestCase): def testFactorial(self): self.assertEqual(math.factorial(0), 1) - self.assertEqual(math.factorial(0.0), 1) total = 1 for i in range(1, 1000): total *= i self.assertEqual(math.factorial(i), total) - self.assertEqual(math.factorial(float(i)), total) self.assertEqual(math.factorial(i), py_factorial(i)) self.assertRaises(ValueError, math.factorial, -1) - self.assertRaises(ValueError, math.factorial, -1.0) self.assertRaises(ValueError, math.factorial, -10**100) - self.assertRaises(ValueError, math.factorial, -1e100) - self.assertRaises(ValueError, math.factorial, math.pi) def testFactorialNonIntegers(self): - self.assertRaises(TypeError, math.factorial, decimal.Decimal(5.2)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(math.factorial(5.0), 120) + with self.assertWarns(DeprecationWarning): + self.assertRaises(ValueError, math.factorial, 5.2) + with self.assertWarns(DeprecationWarning): + self.assertRaises(ValueError, math.factorial, -1.0) + with self.assertWarns(DeprecationWarning): + self.assertRaises(ValueError, math.factorial, -1e100) + self.assertRaises(TypeError, math.factorial, decimal.Decimal('5')) + self.assertRaises(TypeError, math.factorial, decimal.Decimal('5.2')) self.assertRaises(TypeError, math.factorial, "5") # Other implementations may place different upper bounds. @@ -524,7 +528,8 @@ class MathTests(unittest.TestCase): # Currently raises ValueError for inputs that are too large # to fit into a C long. self.assertRaises(OverflowError, math.factorial, 10**100) - self.assertRaises(OverflowError, math.factorial, 1e100) + with self.assertWarns(DeprecationWarning): + self.assertRaises(OverflowError, math.factorial, 1e100) def testFloor(self): self.assertRaises(TypeError, math.floor) |