|
12 | 12 | ) |
13 | 13 |
|
14 | 14 |
|
15 | | -class TestToRounds(unittest.TestCase): |
| 15 | +class CardGamesTest(unittest.TestCase): |
16 | 16 |
|
17 | 17 | @pytest.mark.task(taskno=1) |
18 | | - def test_instructions_example(self): |
19 | | - round_number = 27 |
20 | | - want = [27, 28, 29] |
21 | | - got = get_rounds(round_number) |
22 | | - |
23 | | - self.assertEqual( |
24 | | - want, |
25 | | - got, |
26 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
27 | | - ) |
28 | | - |
29 | | - @pytest.mark.task(taskno=1) |
30 | | - def test_zero(self): |
| 18 | + def test_round_number_zero(self): |
31 | 19 | round_number = 0 |
32 | 20 | want = [0, 1, 2] |
33 | | - got = get_rounds(round_number) |
34 | 21 |
|
35 | | - self.assertEqual( |
36 | | - want, |
37 | | - got, |
38 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 22 | + self.assertEqual(want, get_rounds(round_number), |
| 23 | + msg=f'Expected {want} but got an incorrect result.' |
39 | 24 | ) |
40 | 25 |
|
41 | 26 | @pytest.mark.task(taskno=1) |
42 | | - def test_random_int(self): |
| 27 | + def test_random_int_for_round_number(self): |
43 | 28 | round_number = random.randint(0, 100) |
44 | 29 | want = [round_number + i for i in range(3)] |
45 | | - got = get_rounds(round_number) |
46 | 30 |
|
47 | | - self.assertEqual( |
48 | | - want, |
49 | | - got, |
50 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 31 | + self.assertEqual(get_rounds(round_number), want, |
| 32 | + msg=f'Expected {want} but got an incorrect result.' |
51 | 33 | ) |
52 | 34 |
|
53 | | - |
54 | | -class TestConcatenateRounds(unittest.TestCase): |
55 | | - |
56 | 35 | @pytest.mark.task(taskno=2) |
57 | | - def test_empty(self): |
| 36 | + def test_concatenate_empty_rounds(self): |
58 | 37 | rounds_1 = [] |
59 | 38 | rounds_2 = [] |
60 | 39 | want = [] |
61 | 40 |
|
62 | | - self.assertEqual(concatenate_rounds(rounds_1, rounds_2), |
63 | | - want, |
64 | | - msg=f'Expected {want} but got an incorrect result.' |
65 | | - ) |
| 41 | + self.assertEqual(concatenate_rounds(rounds_1, rounds_2), want, |
| 42 | + msg=f'Expected {want} but got an incorrect result.' |
| 43 | + ) |
66 | 44 |
|
67 | 45 | @pytest.mark.task(taskno=2) |
68 | | - def test_other(self): |
| 46 | + def test_concatenate_other_rounds(self): |
69 | 47 | rounds_1 = [1, 2, 3] |
70 | 48 | rounds_2 = [4, 5, 6] |
71 | 49 | want = [1, 2, 3, 4, 5, 6] |
72 | 50 |
|
73 | | - self.assertEqual(concatenate_rounds(rounds_1, rounds_2), |
74 | | - want, |
75 | | - msg=f'Expected {want} but got an incorrect result.' |
76 | | - ) |
77 | | - |
78 | | - |
79 | | -class TestListContainsRound(unittest.TestCase): |
| 51 | + self.assertEqual(concatenate_rounds(rounds_1, rounds_2), want, |
| 52 | + msg=f'Expected {want} but got an incorrect result.' |
| 53 | + ) |
80 | 54 |
|
81 | 55 | @pytest.mark.task(taskno=3) |
82 | | - def test_instructions_example_1(self): |
83 | | - rounds = [27, 28, 29, 35, 36] |
84 | | - round_number = 29 |
85 | | - want = True |
86 | | - got = list_contains_round(rounds, round_number) |
87 | | - |
88 | | - self.assertEqual( |
89 | | - want, |
90 | | - got, |
91 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
92 | | - ) |
93 | | - |
94 | | - @pytest.mark.task(taskno=3) |
95 | | - def test_instructions_example_2(self): |
96 | | - rounds = [27, 28, 29, 35, 36] |
97 | | - round_number = 30 |
98 | | - want = False |
99 | | - got = list_contains_round(rounds, round_number) |
100 | | - |
101 | | - self.assertEqual( |
102 | | - want, |
103 | | - got, |
104 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
105 | | - ) |
106 | | - |
107 | | - @pytest.mark.task(taskno=3) |
108 | | - def test_empty(self): |
| 56 | + def test_contains_empty_rounds(self): |
109 | 57 | rounds = [] |
110 | 58 | round_number = 1 |
111 | 59 | want = False |
112 | | - got = list_contains_round(rounds, round_number) |
113 | 60 |
|
114 | | - self.assertEqual( |
115 | | - want, |
116 | | - got, |
117 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 61 | + self.assertEqual(list_contains_round(rounds, round_number), want, |
| 62 | + msg=f'Expected {want} but got an incorrect result.' |
118 | 63 | ) |
119 | 64 |
|
120 | 65 | @pytest.mark.task(taskno=3) |
121 | | - def test_other_true(self): |
| 66 | + def test_contains_other_rounds_true(self): |
122 | 67 | rounds = [1, 2, 3] |
123 | 68 | round_number = 2 |
124 | 69 | want = True |
125 | | - got = list_contains_round(rounds, round_number) |
126 | 70 |
|
127 | | - self.assertEqual( |
128 | | - want, |
129 | | - got, |
130 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 71 | + self.assertEqual(list_contains_round(rounds, round_number), want, |
| 72 | + msg=f'Expected {want} but got an incorrect result.' |
131 | 73 | ) |
132 | 74 |
|
133 | 75 | @pytest.mark.task(taskno=3) |
134 | | - def test_other_false(self): |
| 76 | + def test_contains_other_rounds_false(self): |
135 | 77 | rounds = [1, 2, 3] |
136 | 78 | round_number = 0 |
137 | 79 | want = False |
138 | | - got = list_contains_round(rounds, round_number) |
139 | 80 |
|
140 | | - self.assertEqual( |
141 | | - want, |
142 | | - got, |
143 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 81 | + self.assertEqual(list_contains_round(rounds, round_number), want, |
| 82 | + msg=f'Expected {want} but got an incorrect result.' |
144 | 83 | ) |
145 | 84 |
|
146 | | - |
147 | | -class TestCardAverage(unittest.TestCase): |
148 | | - |
149 | 85 | @pytest.mark.task(taskno=4) |
150 | | - def test_instructions_example(self): |
151 | | - hand = [5, 6, 7] |
152 | | - want = 6.0 |
153 | | - got = card_average(hand) |
154 | | - |
155 | | - self.assertEqual( |
156 | | - want, |
157 | | - got, |
158 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
159 | | - ) |
160 | | - |
161 | | - @pytest.mark.task(taskno=4) |
162 | | - def test_other(self): |
| 86 | + def test_card_average_other(self): |
163 | 87 | hand = [1, 2, 3, 4] |
164 | 88 | want = 2.5 |
165 | | - got = card_average(hand) |
166 | | - |
167 | | - self.assertEqual( |
168 | | - want, |
169 | | - got, |
170 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
171 | | - ) |
172 | | - |
173 | | - |
174 | | -class TestApproxAverageIsAverage(unittest.TestCase): |
175 | | - |
176 | | - @pytest.mark.task(taskno=5) |
177 | | - def test_instructions_example_1(self): |
178 | | - hand = [1, 2, 3] |
179 | | - want = True |
180 | | - got = approx_average_is_average(hand) |
181 | | - |
182 | | - self.assertEqual( |
183 | | - want, |
184 | | - got, |
185 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
186 | | - ) |
187 | 89 |
|
188 | | - @pytest.mark.task(taskno=5) |
189 | | - def test_instructions_example_2(self): |
190 | | - hand = [2, 3, 4, 8, 8] |
191 | | - want = True |
192 | | - got = approx_average_is_average(hand) |
193 | | - |
194 | | - self.assertEqual( |
195 | | - want, |
196 | | - got, |
197 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 90 | + self.assertEqual(card_average(hand), want, |
| 91 | + msg=f'Expected {want} but got an incorrect result.' |
198 | 92 | ) |
199 | 93 |
|
200 | 94 | @pytest.mark.task(taskno=5) |
201 | 95 | def test_instructions_example_3(self): |
202 | 96 | hand = [1, 2, 3, 5, 9] |
203 | 97 | want = False |
204 | | - got = approx_average_is_average(hand) |
205 | 98 |
|
206 | | - self.assertEqual( |
207 | | - want, |
208 | | - got, |
209 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 99 | + self.assertEqual(approx_average_is_average(hand), want, |
| 100 | + msg=f'Expected {want} but got an incorrect result.' |
210 | 101 | ) |
211 | 102 |
|
212 | 103 | @pytest.mark.task(taskno=5) |
213 | | - def test_median_true(self): |
| 104 | + def test_approx_average_median_true(self): |
214 | 105 | hand = [1, 2, 4, 5, 8] |
215 | 106 | want = True |
216 | | - got = approx_average_is_average(hand) |
217 | 107 |
|
218 | | - self.assertEqual( |
219 | | - want, |
220 | | - got, |
221 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 108 | + self.assertEqual(approx_average_is_average(hand), want, |
| 109 | + msg=f'Expected {want} but got an incorrect result.' |
222 | 110 | ) |
223 | 111 |
|
224 | 112 | @pytest.mark.task(taskno=5) |
225 | | - def test_other_true(self): |
| 113 | + def test_approx_average_other_true(self): |
226 | 114 | hand = [2, 3, 4] |
227 | 115 | want = True |
228 | | - got = approx_average_is_average(hand) |
229 | 116 |
|
230 | | - self.assertEqual( |
231 | | - want, |
232 | | - got, |
233 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 117 | + self.assertEqual(approx_average_is_average(hand), want, |
| 118 | + msg=f'Expected {want} but got an incorrect result.' |
234 | 119 | ) |
235 | 120 |
|
236 | 121 | @pytest.mark.task(taskno=5) |
237 | | - def test_other_false(self): |
| 122 | + def test_approx_average_other_false(self): |
238 | 123 | hand = [2, 3, 4, 7, 8] |
239 | | - want = False |
240 | | - got = approx_average_is_average(hand) |
241 | | - |
242 | | - self.assertEqual( |
243 | | - want, |
244 | | - got, |
245 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
246 | | - ) |
247 | | - |
248 | | - |
249 | | -class TestAverageEvenIsAverageOdd(unittest.TestCase): |
250 | | - |
251 | | - @pytest.mark.task(taskno=6) |
252 | | - def test_instructions_example_1(self): |
253 | | - hand = [1, 2, 3] |
254 | | - want = True |
255 | | - got = average_even_is_average_odd(hand) |
| 124 | + want= False |
256 | 125 |
|
257 | | - self.assertEqual( |
258 | | - want, |
259 | | - got, |
260 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 126 | + self.assertEqual(approx_average_is_average(hand), want, |
| 127 | + msg=f'Expected {want} but got an incorrect result.' |
261 | 128 | ) |
262 | 129 |
|
263 | 130 | @pytest.mark.task(taskno=6) |
264 | | - def test_instructions_example_2(self): |
265 | | - hand = [1, 2, 3, 4] |
266 | | - want = False |
267 | | - got = average_even_is_average_odd(hand) |
268 | | - |
269 | | - self.assertEqual( |
270 | | - want, |
271 | | - got, |
272 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
273 | | - ) |
274 | | - |
275 | | - @pytest.mark.task(taskno=6) |
276 | | - def test_other_true(self): |
| 131 | + def test_avg_even_odd_other_true(self): |
277 | 132 | hand = [5, 6, 7] |
278 | | - want = True |
279 | | - got = average_even_is_average_odd(hand) |
| 133 | + want= True |
280 | 134 |
|
281 | | - self.assertEqual( |
282 | | - want, |
283 | | - got, |
284 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 135 | + self.assertEqual(average_even_is_average_odd(hand), want, |
| 136 | + msg=f'Expected {want} but got an incorrect result.' |
285 | 137 | ) |
286 | 138 |
|
287 | 139 | @pytest.mark.task(taskno=6) |
288 | | - def test_other_false(self): |
| 140 | + def test_avg_even_odd_other_false(self): |
289 | 141 | hand = [5, 6, 8] |
290 | 142 | want = False |
291 | | - got = average_even_is_average_odd(hand) |
292 | 143 |
|
293 | | - self.assertEqual( |
294 | | - want, |
295 | | - got, |
296 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
297 | | - ) |
298 | | - |
299 | | - |
300 | | -class TestMaybeDoubleLast(unittest.TestCase): |
301 | | - |
302 | | - @pytest.mark.task(taskno=7) |
303 | | - def test_instructions_example_1(self): |
304 | | - hand = [5, 9, 11] |
305 | | - want = [5, 9, 22] |
306 | | - got = maybe_double_last(hand) |
307 | | - |
308 | | - self.assertEqual( |
309 | | - want, |
310 | | - got, |
311 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
312 | | - ) |
313 | | - |
314 | | - @pytest.mark.task(taskno=7) |
315 | | - def test_instructions_example_2(self): |
316 | | - hand = [5, 9, 10] |
317 | | - want = [5, 9, 10] |
318 | | - got = maybe_double_last(hand) |
319 | | - |
320 | | - self.assertEqual( |
321 | | - want, |
322 | | - got, |
323 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 144 | + self.assertEqual(average_even_is_average_odd(hand), want, |
| 145 | + msg=f'Expected {want} but got an incorrect result.' |
324 | 146 | ) |
325 | 147 |
|
326 | 148 | @pytest.mark.task(taskno=7) |
327 | | - def test_other_doubles(self): |
| 149 | + def test_maybe_double_last_other_doubles(self): |
328 | 150 | hand = [1, 2, 11] |
329 | 151 | want = [1, 2, 22] |
330 | | - got = maybe_double_last(hand) |
331 | 152 |
|
332 | | - self.assertEqual( |
333 | | - want, |
334 | | - got, |
335 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 153 | + self.assertEqual(maybe_double_last(hand), want, |
| 154 | + msg=f'Expected {want} but got an incorrect result.' |
336 | 155 | ) |
337 | 156 |
|
338 | 157 | @pytest.mark.task(taskno=7) |
339 | | - def test_other_no_change(self): |
| 158 | + def test_maybe_double_last_other_no_change(self): |
340 | 159 | hand = [1, 2, 3] |
341 | 160 | want = [1, 2, 3] |
342 | | - got = maybe_double_last(hand) |
343 | 161 |
|
344 | | - self.assertEqual( |
345 | | - want, |
346 | | - got, |
347 | | - msg=f'Expected {want} but got an incorrect result: {got!r}' |
| 162 | + self.assertEqual(maybe_double_last(hand), want, |
| 163 | + msg=f'Expected {want} but got an incorrect result.' |
348 | 164 | ) |
0 commit comments