forked from serfer2/kata_TDD_01
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_string_adder.py
More file actions
138 lines (121 loc) · 3.65 KB
/
test_string_adder.py
File metadata and controls
138 lines (121 loc) · 3.65 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import unittest
from string_adder import string_adder
class TestStringAdder(unittest.TestCase):
def test_sum_two_numbers_gt_10(self):
# Inicializacion
param = "11,22"
expected = 33
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_sum_two_numbers(self):
# Inicializacion
param = "1,2"
expected = 3
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_empty_params(self):
# Inicializacion
param = ""
expected = 0
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_sum_one_number(self):
# Inicializacion
param = "1"
expected = 1
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_a_lot_of_numbers(self):
# Inicializacion
param = "1,2,3,4,5,6,7,8"
expected = 36
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_accept_backslash_n(self):
# Inicializacion
param = "1\n2,3"
expected = 6
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_not_accept_comma_backslash_n(self):
# Inicializacion
param = "1,\n"
expected = -1
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_accept_backslash_n_and_commas(self):
# Inicializacion
param = "1\n2,3\n4,5"
expected = 15
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_can_change_delimiter(self):
# Inicializacion
param = "//;\n1;2;3"
expected = 6
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_can_change_delimiter_to_amp(self):
# Inicializacion
param = "//&\n1&2&3"
expected = 6
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_can_change_delimiter_and_typo(self):
# Inicializacion
param = "//;\n1;\n2;3"
expected = -1
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
def test_no_accept_one_negative(self):
# Inicializacion
param = "-1,2,3"
expected = "negatives not allowed: -1"
# Accion
with self.assertRaises(ValueError) as context:
result = string_adder(param)
print(context.exception)
# Comprobacion
self.assertEqual(expected, f"{expected}")
def test_no_accept_negatives(self):
# Inicializacion
param = "-1,2,-3"
expected = "negatives not allowed: -1, -3"
# Accion
with self.assertRaises(ValueError) as context:
result = string_adder(param)
print(context.exception)
# Comprobacion
self.assertEqual(expected, f"{expected}")
def test_ignore_numbers_greater_than_1000(self):
# Inicializacion
param = "1,2,3,1001"
expected = 6
# Accion
result = string_adder(param)
# Comprobacion
self.assertEqual(expected, result)
if __name__ == '__main__':
unittest.main()