summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_math.py15
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.