|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
""" |
|
3
|
|
|
test exercise 02 functions |
|
4
|
|
|
""" |
|
5
|
|
|
|
|
6
|
|
|
import unittest |
|
7
|
|
|
import exercises02 as f |
|
8
|
|
|
|
|
9
|
|
|
class Testcase(unittest.TestCase): |
|
10
|
|
|
""" |
|
11
|
|
|
Test class using python unittest |
|
12
|
|
|
""" |
|
13
|
|
|
|
|
14
|
|
|
def test_factorial1(self): |
|
15
|
|
|
""" factorial(0) should return 1""" |
|
16
|
|
|
self.assertEqual(f.factorial(0), 1) |
|
17
|
|
|
|
|
18
|
|
|
def test_factorial2(self): |
|
19
|
|
|
""" factorial(5) should return 120""" |
|
20
|
|
|
self.assertEqual(f.factorial(5), 120) |
|
21
|
|
|
|
|
22
|
|
|
def test_factorial3(self): |
|
23
|
|
|
""" factorial(10) should return 3628800""" |
|
24
|
|
|
self.assertEqual(f.factorial(10), 3628800) |
|
25
|
|
|
|
|
26
|
|
|
def test_binomial1(self): |
|
27
|
|
|
""" bin(40, 100, 0.5) should return 0.010 """ |
|
28
|
|
|
self.assertEqual(f.bin(40, 100, 0.5), 0.011) |
|
29
|
|
|
|
|
30
|
|
|
def test_binomial2(self): |
|
31
|
|
|
""" bin(150, 200, 0.75) should return 0.065 """ |
|
32
|
|
|
self.assertEqual(f.bin(150, 200, 0.75), 0.065) |
|
33
|
|
|
|
|
34
|
|
|
def test_cumulative_binomial1(self): |
|
35
|
|
|
""" cumulative_bin(40, 100, 0.5) should return 0.028 """ |
|
36
|
|
|
self.assertEqual(f.cumulative_bin(40, 100, 0.5), 0.028) |
|
37
|
|
|
|
|
38
|
|
|
def test_cumulative_binomial2(self): |
|
39
|
|
|
""" cumulative_bin(150, 200, 0.75) should return 0.527 """ |
|
40
|
|
|
self.assertEqual(f.cumulative_bin(150, 200, 0.75), 0.527) |
|
41
|
|
|
|
|
42
|
|
|
if __name__ == '__main__': |
|
43
|
|
|
unittest.main() |
|
44
|
|
|
|