diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2014-04-10 13:29:39 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2014-04-10 13:29:39 (GMT) |
commit | 5990d2864c73e1abc951c1d17741eab3e1b30be1 (patch) | |
tree | 8d0dc09622cce43651638572d87f6df9149ff935 /Lib/test/test_math.py | |
parent | 6ed7c20ce5b01b69abbc01b9a22bdd9983db9c01 (diff) | |
download | cpython-5990d2864c73e1abc951c1d17741eab3e1b30be1.zip cpython-5990d2864c73e1abc951c1d17741eab3e1b30be1.tar.gz cpython-5990d2864c73e1abc951c1d17741eab3e1b30be1.tar.bz2 |
Issue #20539: Improve math.factorial error messages and types for large inputs.
- Better message for the OverflowError in large positive inputs.
- Changed exception type from OverflowError to ValueError for large negative inputs.
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r-- | Lib/test/test_math.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 48f84ba..c9f3f16 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -422,9 +422,17 @@ class MathTests(unittest.TestCase): 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) - self.assertRaises(OverflowError, math.factorial, sys.maxsize+1) - self.assertRaises(OverflowError, math.factorial, 10e100) + + # Other implementations may place different upper bounds. + @support.cpython_only + def testFactorialHugeInputs(self): + # 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) def testFloor(self): self.assertRaises(TypeError, math.floor) |