Skip to content

Commit 375818c

Browse files
authored
[Currency Exchange]: Updated Test Error Messages. (#3537)
* Updated test error messages. * Added bethang and kytrinyx as contributors. [no important files changed]
1 parent 7521cb0 commit 375818c

File tree

2 files changed

+109
-38
lines changed

2 files changed

+109
-38
lines changed

exercises/concept/currency-exchange/.meta/config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"J08K"
99
],
1010
"contributors": [
11+
"BethanyG",
12+
"kytrinyx",
1113
"pranasziaukas"
1214
],
1315
"files": {
Lines changed: 107 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22
import pytest
3+
34
from exchange import (
45
exchange_money,
56
get_change,
@@ -10,63 +11,131 @@
1011

1112

1213
class CurrencyExchangeTest(unittest.TestCase):
13-
1414
@pytest.mark.task(taskno=1)
1515
def test_exchange_money(self):
16-
input_data = [(100000, 0.8), (700000, 10.0)]
17-
output_data = [125000, 70000]
16+
test_data = [(100000, 0.8), (700000, 10.0)]
17+
result_data = [125000, 70000]
18+
19+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
20+
budget, exchange_rate = params
1821

19-
for variant, (input_data, output_data) in enumerate(zip(input_data, output_data), start=1):
20-
with self.subTest(f"variation #{variant}", input_data=input_data, output_data=output_data):
21-
self.assertAlmostEqual(exchange_money(input_data[0], input_data[1]), output_data)
22+
with self.subTest(f"variation #{variant}",
23+
budget=budget,
24+
exchange_rate=exchange_rate,
25+
expected=expected):
26+
27+
actual_result = exchange_money(*params)
28+
error_message = (f'Called exchange_money{budget, exchange_rate}. '
29+
f'The function returned {actual_result}, but '
30+
f'The tests expected {expected} when exchanging'
31+
f' {budget} at a rate of {exchange_rate}.')
32+
33+
self.assertAlmostEqual(actual_result, expected, msg=error_message)
2234

2335
@pytest.mark.task(taskno=2)
2436
def test_get_change(self):
25-
input_data = [(463000, 5000), (1250, 120), (15000, 1380)]
26-
output_data = [458000, 1130, 13620]
37+
test_data = [(463000, 5000), (1250, 120), (15000, 1380)]
38+
result_data = [458000, 1130, 13620]
39+
40+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
41+
budget, exchanging_value = params
2742

28-
for variant, (input_data, output_data) in enumerate(zip(input_data, output_data), start=1):
29-
with self.subTest(f"variation #{variant}", input_data=input_data, output_data=output_data):
30-
self.assertAlmostEqual(get_change(input_data[0], input_data[1]), output_data)
43+
with self.subTest(f"variation #{variant}",
44+
budget=budget,
45+
exchanging_value=exchanging_value,
46+
expected=expected):
47+
48+
actual_result = get_change(*params)
49+
error_message = (f'Called get_change{budget, exchanging_value}. '
50+
f'The function returned {actual_result}, but '
51+
f'The tests expected {expected} left in your budget.')
52+
53+
self.assertAlmostEqual(actual_result, expected, msg=error_message)
3154

3255
@pytest.mark.task(taskno=3)
3356
def test_get_value_of_bills(self):
34-
input_data = [(10000, 128), (50, 360), (200, 200)]
35-
output_data = [1280000, 18000, 40000]
57+
test_data = [(10000, 128), (50, 360), (200, 200)]
58+
result_data = [1280000, 18000, 40000]
59+
60+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
61+
denomination, number_of_bills = params
62+
63+
with self.subTest(f"variation #{variant}",
64+
denomination=denomination,
65+
number_of_bills=number_of_bills,
66+
expected=expected):
67+
68+
actual_result = get_value_of_bills(*params)
69+
error_message = (f'Called get_value_of_bills{denomination, number_of_bills}. '
70+
f'The function returned {actual_result}, but '
71+
f'The tests expected {expected} for the bills value.')
3672

37-
for variant, (input_data, output_data) in enumerate(zip(input_data, output_data), start=1):
38-
with self.subTest(f"variation #{variant}", input_data=input_data, output_data=output_data):
39-
self.assertEqual(get_value_of_bills(input_data[0], input_data[1]), output_data)
73+
self.assertEqual(actual_result, expected, msg=error_message)
4074

4175
@pytest.mark.task(taskno=4)
4276
def test_get_number_of_bills(self):
43-
input_data = [(163270, 50000), (54361, 1000)]
44-
output_data = [3, 54]
77+
test_data = [(163270, 50000), (54361, 1000)]
78+
result_data = [3, 54]
4579

46-
for variant, (input_data, output_data) in enumerate(zip(input_data, output_data), start=1):
47-
with self.subTest(f"variation #{variant}", input_data=input_data, output_data=output_data):
48-
self.assertEqual(get_number_of_bills(input_data[0], input_data[1]), output_data)
80+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
81+
amount, denomination = params
82+
83+
with self.subTest(f"variation #{variant}",
84+
amount=amount,
85+
denomination=denomination,
86+
expected=expected):
87+
88+
actual_result = get_number_of_bills(amount, denomination)
89+
error_message = (f'Called get_number_of_bills{amount, denomination}. '
90+
f'The function returned {actual_result} bills, but '
91+
f'The tests expected {expected} bills.')
92+
93+
self.assertEqual(actual_result, expected, msg=error_message)
4994

5095
@pytest.mark.task(taskno=5)
5196
def test_get_leftover_of_bills(self):
52-
input_data = [(10.1, 10), (654321.0, 5), (3.14, 2)]
53-
output_data = [0.1, 1.0, 1.14]
97+
test_data = [(10.1, 10), (654321.0, 5), (3.14, 2)]
98+
result_data = [0.1, 1.0, 1.14]
99+
100+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
101+
amount, denomination = params
102+
103+
with self.subTest(f"variation #{variant}",
104+
amount=amount,
105+
denomination=denomination,
106+
expected=expected):
107+
108+
actual_result = get_leftover_of_bills(*params)
109+
error_message = (f'Called get_leftover_of_bills{amount, denomination}. '
110+
f'The function returned {actual_result}, but '
111+
f'The tests expected {expected} as the leftover amount.')
54112

55-
for variant, (input_data, output_data) in enumerate(zip(input_data, output_data), start=1):
56-
with self.subTest(f"variation #{variant}", input_data=input_data, output_data=output_data):
57-
self.assertAlmostEqual(get_leftover_of_bills(input_data[0], input_data[1]), output_data)
113+
self.assertAlmostEqual(actual_result, expected, msg=error_message)
58114

59115
@pytest.mark.task(taskno=6)
60116
def test_exchangeable_value(self):
61-
inputs = [
62-
(100000, 10.61, 10, 1),
63-
(1500, 0.84, 25, 40),
64-
(470000, 1050, 30, 10000000000),
65-
(470000, 0.00000009, 30, 700),
66-
(425.33, 0.0009, 30, 700)]
67-
68-
output_data = [8568, 1400, 0, 4017094016600, 363300]
69-
70-
for variant, (inputs, output_data) in enumerate(zip(inputs, output_data), start=1):
71-
with self.subTest(f"variation #{variant}", inputs=inputs, output_data=output_data):
72-
self.assertEqual(exchangeable_value(inputs[0], inputs[1], inputs[2], inputs[3]), output_data)
117+
test_data = [(100000, 10.61, 10, 1),
118+
(1500, 0.84, 25, 40),
119+
(470000, 1050, 30, 10000000000),
120+
(470000, 0.00000009, 30, 700),
121+
(425.33, 0.0009, 30, 700)]
122+
123+
result_data = [8568, 1400, 0, 4017094016600, 363300]
124+
125+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
126+
budget, exchange_rate, spread, denomination = params
127+
128+
with self.subTest(f"variation #{variant}",
129+
budget=budget,
130+
exchange_rate=exchange_rate,
131+
spread=spread,
132+
denomination=denomination,
133+
expected=expected):
134+
135+
actual_result = exchangeable_value(budget, exchange_rate, spread, denomination)
136+
error_message = (f'Called exchangeable_value{budget, exchange_rate, spread, denomination}. '
137+
f'The function returned {actual_result}, but '
138+
f'The tests expected {expected} as the maximum '
139+
f'value of the new currency .')
140+
141+
self.assertEqual(actual_result, expected, msg=error_message)

0 commit comments

Comments
 (0)