diff options
author | Raymond Hettinger <python@rcn.com> | 2008-06-09 06:54:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-06-09 06:54:45 (GMT) |
commit | ecbdd2e9b0a5af20a2b8784ac91338739b99ce3d (patch) | |
tree | 1cc2a450f85ce75d3c9a13741a755d44640a6821 /Lib/test/test_math.py | |
parent | dd96db63f689e2f0d8ae5a1436b3b3395eec7de5 (diff) | |
download | cpython-ecbdd2e9b0a5af20a2b8784ac91338739b99ce3d.zip cpython-ecbdd2e9b0a5af20a2b8784ac91338739b99ce3d.tar.gz cpython-ecbdd2e9b0a5af20a2b8784ac91338739b99ce3d.tar.bz2 |
Issue #2138: Add math.factorial().
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r-- | Lib/test/test_math.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 426ca7b..3123954 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -6,6 +6,7 @@ import unittest import math import os import sys +import random eps = 1E-05 NAN = float('nan') @@ -277,6 +278,20 @@ class MathTests(unittest.TestCase): self.ftest('fabs(0)', math.fabs(0), 0) self.ftest('fabs(1)', math.fabs(1), 1) + def testFactorial(self): + def fact(n): + result = 1 + for i in range(1, int(n)+1): + result *= i + return result + values = range(10) + [50, 100, 500] + random.shuffle(values) + for x in range(10): + for cast in (int, long, float): + self.assertEqual(math.factorial(cast(x)), fact(x), (x, fact(x), math.factorial(x))) + self.assertRaises(ValueError, math.factorial, -1) + self.assertRaises(ValueError, math.factorial, math.pi) + def testFloor(self): self.assertRaises(TypeError, math.floor) # These types will be int in py3k. |