Hi all,
I’ve recently solved the Need for Speed
challenge and realised it’s missing an important testing use-case for the CanFinish
function.
The README
#4 reads:
Assume that you are currently at the starting line of the race and start the engine of the car for the race. Take into account that the car’s battery might not necessarily be fully charged when starting the race:
Assume you’re currently at the starting line, but in the test scenarios, cars not always start at distance: 0
.
{
name: "Car can easily finish the track distance.",
car: Car{
speed: 5,
batteryDrain: 2,
battery: 100,
distance: 20,
},
track: Track{
distance: 30,
},
expected: true,
},
However, if the car.distance
is not zero, that means the car is not in the starting line when this function is called. As it says “the starting line”, most of community solutions - mine included - did not consider the car.distance
at all when implementing the function. But if the car could be anywhere in the track, then I suggest replacing the current instructions to something like this:
Assume that you are anywhere in the track, either the starting line or just before crossing the finish line.
And the test updated to:
{
name: "Car can easily finish the track distance.",
car: Car{
speed: 5,
batteryDrain: 5,
battery: 10,
distance: 90,
},
track: Track{
distance: 100,
},
expected: true,
},
That car would make, but depending on how the function is implemented it won’t return true
.
Hope that makes sense.
Thanks all!