Skip to content

Commit d444c96

Browse files
author
Iván Sánchez
committed
Added tests of functions to be implemented later
1 parent 77d796d commit d444c96

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

test.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,38 @@ def test_isPrime():
2323
else:
2424
print ("FOUND ", fails, " ERRORS")
2525

26-
functions = ('isPrime')
26+
27+
def test_factorial():
28+
print "Testing factorial "
29+
fails = 0
30+
factorials = [(5, 120), (10, 3628800), (7, 5040), (12, 479001600)]
31+
for f in factorials:
32+
if mathtools.factorial(f[0]) == f[1]:
33+
print '+ ', # Pass the test
34+
else:
35+
fails += 1
36+
print '- ',
37+
if not fails:
38+
print "TEST OK"
39+
else:
40+
print "FOUND ", fails, " ERRORS"
41+
42+
def test_fib():
43+
print "Testing fib "
44+
fails = 0
45+
fib = [(1, 1), (0, 0), (3, 2), (4, 3), (6, 8), (7, 13), (20, 6765)]
46+
for f in fib:
47+
if mathtools.fib(f[0]) == f[1]:
48+
print '+ ', # Pass the test
49+
else:
50+
fails += 1
51+
print '- ',
52+
if not fails:
53+
print "TEST OK"
54+
else:
55+
print "FOUND ", fails, " ERRORS"
56+
57+
functions = ('isPrime', 'factorial', 'fib')
2758
for f in functions:
2859
if hasattr(mathtools, f):
2960
globals()['test_'+f]()

0 commit comments

Comments
 (0)