exercism / go

Exercism exercises in Go.
https://exercism.org/tracks/go
MIT License
951 stars 644 forks source link

Need for speed exercise CanFinish tests do not validate start with distance travelled #2740

Closed seriar closed 6 months ago

seriar commented 6 months ago

There are two slightly ambiguous parts about the CanFinish subtask:

Calling CanFinish with car.distance > 0

Problem

There is a line in instructions implying that the distance traveled by car before the function call should not be use for the check:

Assume that you are currently at the starting line of the race

But the tests do not validate it so both implementations counting and not counting it towards the track distance

Suggestion

  1. Rephrase the can finish the race to can finish the race from start to finish to make it a bit clearer, and
  2. add a test validating that car.distance is not counted towards the target distance
        {
            name: "Car cannot finish the track distance with initial battery less than 100% and traveled distance is not 0",
            car: Car{
                speed:        4,
                batteryDrain: 5,
                battery:      25,
                distance:     1,
            },
            track: Track{
                distance: 21,
            },
            expected: false,
        },

Travelling with battery < batteryDrain

Problem

The instructions for Drive function indicate that it should not be possible to travel with a battery level lower the battery drain rate. But the tests for CanFinish do not validate it. So one can write a solution that would allow it, and still pass all the tests.

Suggestion

  1. Clarify the requirement with Car cannot travel at all if the battery level is less than batteryDrain (or the opposite but that is a bit more tricky) and
  2. add a test validating that part of the speed is never taken
        {
            name: "Car cannot finish with partial move (part of batteryDrain)",
            car: Car{
                speed:        2,
                batteryDrain: 200,
                battery:      100,
                distance:     0,
            },
            track: Track{
                distance: 1,
            },
            expected: false,
        },
github-actions[bot] commented 6 months ago

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use this link to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.