Code Run
test_data = [(100000, 10.61, 10, 1),
(1500, 0.84, 25, 40),
(470000, 1050, 30, 10000000000),
(470000, 0.00000009, 30, 700),
(425.33, 0.0009, 30, 700)]
result_data = [8568, 1400, 0, 4017094016600, 363300]
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
budget, exchange_rate, spread, denomination = params
with self.subTest(f"variation #{variant}",
budget=budget,
exchange_rate=exchange_rate,
spread=spread,
denomination=denomination,
expected=expected):
actual_result = exchangeable_value(budget, exchange_rate, spread, denomination)
error_message = (f'Called exchangeable_value{budget, exchange_rate, spread, denomination}. '
f'The function returned {actual_result}, but '
f'The tests expected {expected} as the maximum '
f'value of the new currency .')
self.assertEqual(actual_result, expected, msg=error_message)
Test Failure
One or more variations of this test failed. Details can be found under each [variant#].
The previous is wrong in the function:
def exchangeable_value(budget, exchange_rate, spread, denomination):
"""
:param budget: float - the amount of your money you are planning to exchange.
:param exchange_rate: float - the unit value of the foreign currency.
:param spread: int - percentage that is taken as an exchange fee.
:param denomination: int - the value of a single bill.
:return: int - maximum value you can get.
"""
# Cantidad en la divisa objetivo antes de la tarifa
cantidad_cambio = budget * exchange_rate
# Costo de la tarifa
tarifa = cantidad_cambio * (spread / 100)
# Cantidad despues de aplicar la tarifa
cantidad_despues_tarifa = cantidad_cambio - tarifa
# Numero maximo de billetes completos
maximo_billetes = cantidad_despues_tarifa // denomination
return int(maximo_billetes)
I cannot find for this function… Could you help me with that?