-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermutation_test.py
68 lines (53 loc) · 2.45 KB
/
permutation_test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import unittest
from permutation import PermutationCalc
# general permutation calculation
class PermutationTest(unittest.TestCase):
def test_permutation(self):
permutation = PermutationCalc()
number_of_objects = 7
objects_chosen = 2
expected_output = 42
actual_output = PermutationCalc.calc_permutation(permutation, number_of_objects, objects_chosen)
self.assertEqual(expected_output, actual_output, 'Permutation of 7 choose 2 is 42')
# one object is selected
def test_permutation2(self):
permutation = PermutationCalc()
number_of_objects = 11
objects_chosen = 1
expected_output = 11
actual_output = PermutationCalc.calc_permutation(permutation, number_of_objects, objects_chosen)
self.assertEqual(expected_output, actual_output, 'Permutation of 11 choose 1 is 11')
# all objects are selected
def test_permutation3(self):
permutation = PermutationCalc()
number_of_objects = 8
objects_chosen = 8
expected_output = 40320
actual_output = PermutationCalc.calc_permutation(permutation, number_of_objects, objects_chosen)
self.assertEqual(expected_output, actual_output, 'Permutation of 8 choose 8 is 40320')
# no object is selected
def test_permutation4(self):
permutation = PermutationCalc()
number_of_objects = 16
objects_chosen = 0
expected_output = 1
actual_output = PermutationCalc.calc_permutation(permutation, number_of_objects, objects_chosen)
self.assertEqual(expected_output, actual_output, 'Permutation of 16 choose 0 is 1')
# objects chosen is larger than objects available
def test_permutation5(self):
permutation = PermutationCalc()
number_of_objects = 16
objects_chosen = 18
expected_output = None
actual_output = PermutationCalc.calc_permutation(permutation, number_of_objects, objects_chosen)
self.assertEqual(expected_output, actual_output, 'Objects less than chosen failed.')
# nonsense test
def test_permutation6(self):
permutation = PermutationCalc()
number_of_objects = 16
objects_chosen = 'han solo'
expected_output = None
actual_output = PermutationCalc.calc_permutation(permutation, number_of_objects, objects_chosen)
self.assertEqual(expected_output, actual_output, 'nonsense test failed')
if __name__ == '__main__':
unittest.main()