-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_module.py
67 lines (48 loc) · 2.85 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
import unittest
import arithmetic_arranger
class MyTestCase(unittest.TestCase):
def test_well_formatted_problems(self):
given_data = ['32 + 698', '3801 + 2', '45 + 43', '123 + 49']
expected_result = ''' 32 3801 45 123
+ 698 + 2 + 43 + 49
----- ------ ---- -----'''
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
def test_well_formatted_problems_with_answers(self):
given_data = ["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"]
expected_result = ''' 32 1 9999 523
+ 8 - 3801 + 9999 - 49
---- ------ ------ -----
40 -3800 19998 474'''
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data, True), expected_result)
def test_too_many_problems(self):
given_data = ['32 + 698', '3801 + 2', '45 + 43', '123 + 49', '3801 + 2', '45 + 43', '123 + 49']
expected_result = 'Error: Too many problems.'
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
def test_wrong_operator(self):
expected_result = "Error: Operator must be '+' or '-'."
given_data = ['32 + 698', '3801 d 2', '45 + 43']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
given_data = ['32 ++ 698', '3801 - 2', '45 + 43']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
given_data = ['32 * 698', '3801 - 2', '45 + 43']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
given_data = ['32 + 698', '3801 - 2', '45 / 43']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
def test_operands_with_non_digit_characters(self):
expected_result = "Error: Numbers must only contain digits."
given_data = ['a32 + 698']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
given_data = ['32 + 698z']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
given_data = ['aa + xyz']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
def test_operands_with_more_than_4_digits(self):
expected_result = "Error: Numbers cannot be more than four digits."
given_data = ['11132 + 698']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
given_data = ['32 + 69111']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
given_data = ['12345 + 678901']
self.assertEqual(arithmetic_arranger.arithmetic_arranger(given_data), expected_result)
if __name__ == '__main__':
unittest.main()