-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_module.py
73 lines (63 loc) · 3.22 KB
/
test_module.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
69
70
71
72
73
import unittest
from arithmetic_arranger import arithmetic_arranger
# the test case
class UnitTests(unittest.TestCase):
def test_arrangement(self):
actual = arithmetic_arranger(
["3 + 855", "3801 - 2", "45 + 43", "123 + 49"])
expected = " 3 3801 45 123\n+ 855 - 2 + 43 + 49\n----- ------ ---- -----"
self.assertEqual(
actual, expected,
'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]'
)
actual = arithmetic_arranger(
["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"])
expected = " 11 3801 1 123 1\n+ 4 - 2999 + 2 + 49 - 9380\n---- ------ --- ----- ------"
self.assertEqual(
actual, expected,
'Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]'
)
def test_too_many_problems(self):
actual = arithmetic_arranger([
"44 + 815", "909 - 2", "45 + 43", "123 + 49", "888 + 40",
"653 + 87"
])
expected = "Error: Too many problems."
self.assertEqual(
actual, expected,
'Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."'
)
def test_incorrect_operator(self):
actual = arithmetic_arranger(
["3 / 855", "3801 - 2", "45 + 43", "123 + 49"])
expected = "Error: Operator must be '+' or '-'."
self.assertEqual(
actual, expected,
'''Expected calling "arithmetic_arranger()" with a problem that uses the "/" operator to return "Error: Operator must be '+' or '-'."'''
)
def test_too_many_digits(self):
actual = arithmetic_arranger(
["24 + 85215", "3801 - 2", "45 + 43", "123 + 49"])
expected = "Error: Numbers cannot be more than four digits."
self.assertEqual(
actual, expected,
'Expected calling "arithmetic_arranger()" with a problem that has a number over 4 digits long to return "Error: Numbers cannot be more than four digits."'
)
def test_only_digits(self):
actual = arithmetic_arranger(
["98 + 3g5", "3801 - 2", "45 + 43", "123 + 49"])
expected = "Error: Numbers must only contain digits."
self.assertEqual(
actual, expected,
'Expected calling "arithmetic_arranger()" with a problem that contains a letter character in the number to return "Error: Numbers must only contain digits."'
)
def test_solutions(self):
actual = arithmetic_arranger(
["32 - 698", "1 - 3801", "45 + 43", "123 + 49"], True)
expected = " 32 1 45 123\n- 698 - 3801 + 43 + 49\n----- ------ ---- -----\n -666 -3800 88 172"
self.assertEqual(
actual, expected,
'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithemetic problems and a second argument of `True`.'
)
if __name__ == "__main__":
unittest.main()