-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursive_square_unittest.py
More file actions
executable file
·41 lines (31 loc) · 1.29 KB
/
recursive_square_unittest.py
File metadata and controls
executable file
·41 lines (31 loc) · 1.29 KB
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
#!/bin/env python3
"""Test recursive square algorithm implementation."""
import unittest
from recursive_square import iterative_square, recursive_square, recursive_square_tail
class SquareTestCommon():
def setUp(self):
self.range_start = -100
self.range_end = 100 + 1
self.function = None
def test(self):
self.assertIsNotNone(self.function)
#print('{:>4} --> {:>4} {:>4} {:>4}'.format('N', 'BP', 'FP', 'Square'))
for N in range(self.range_start, self.range_end):
with self.subTest(N=N):
bwd_prog, fwd_prog, computed_N = self.function(N)
#print('{:>4} --> {:>4} {:>4} {:>4}'.format(N, bwd_prog, fwd_prog, computed_N))
self.assertEqual(computed_N, N**2)
class RecursiveSquareTest(unittest.TestCase, SquareTestCommon):
def setUp(self):
SquareTestCommon.setUp(self)
self.function = recursive_square
class RecursiveSquareTailTest(unittest.TestCase, SquareTestCommon):
def setUp(self):
SquareTestCommon.setUp(self)
self.function = recursive_square_tail
class IterativeSquareTest(unittest.TestCase, SquareTestCommon):
def setUp(self):
SquareTestCommon.setUp(self)
self.function = iterative_square
if __name__ == '__main__':
unittest.main()