-
Notifications
You must be signed in to change notification settings - Fork 62
/
example7.py
42 lines (31 loc) · 1.04 KB
/
example7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# ch19/example7.py
import unittest
from concurrencytest import ConcurrentTestSuite, fork_for_tests
def fib(i):
if i in [0, 1]:
return i
a, b = 0, 1
n = 1
while n < i:
a, b = b, a + b
n += 1
return b
class FibTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(FibTest, self).__init__(*args, **kwargs)
self.mod = 10 ** 10
def test_start_values(self):
self.assertEqual(fib(0), 0)
self.assertEqual(fib(1), 1)
def test_big_value_v1(self):
self.assertEqual(fib(499990) % self.mod, 9998843695)
def test_big_value_v2(self):
self.assertEqual(fib(499995) % self.mod, 1798328130)
def test_big_value_v3(self):
self.assertEqual(fib(500000) % self.mod, 9780453125)
if __name__ == '__main__':
runner = unittest.TextTestRunner()
# multiprocessing testing
suite = unittest.TestLoader().loadTestsFromTestCase(FibTest)
concurrent_suite = ConcurrentTestSuite(suite, fork_for_tests(4))
runner.run(concurrent_suite)