Lua: Test assertions don't have an error margin

Discord post: Link


Recently I found a very bizarre yet consistent test failure on the Lua track, car-assemble exercise:

image

It was the only remaining test that wasn’t succesful. Here’s my code:

local cars = {}

-- returns the amount of working cars produced by the assembly line every hour
function cars.calculate_working_cars_per_hour(production_rate, success_rate)
  return production_rate * (success_rate / 100)
end

-- returns the amount of working cars produced by the assembly line every minute
function cars.calculate_working_cars_per_minute(production_rate, success_rate)
  return cars.calculate_working_cars_per_hour(production_rate, success_rate) // 60
end

-- returns the cost of producing the given number of cars
function cars.calculate_cost(cars_count)
  return (95000 * (cars_count // 10)) + (10000 * (cars_count % 10))
end

return cars

It’s clear that there should be some kind of an error bar to eliminate such failures, as suggested by @iHiD on Discord.

Thanks!

As will probably be obvious to maintainers, my first thought was that it looks to me like an issue with the tests at a glance. I’d guess they’re comparing two floating point numbers without error bars.

You’ll get a different result if you remove the parentheses.

It works this way, but that failure is still very weird. It’s pretty natural for one to try and divide the percentage by 100 first before doing any multiplication.