Skip to content

Commit

Permalink
Updated Need For Speed exercise instructions and tests (exercism#2740)
Browse files Browse the repository at this point in the history
- requiring and testing that `CanFinish` handles the case of battery <
  batteryDrain as `Drive` function
  • Loading branch information
seriar committed Jan 10, 2024
1 parent 147d135 commit cbf9957
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exercises/concept/need-for-speed/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ car = Drive(car)

To finish a race, a car has to be able to drive the race's distance. This means not draining its battery before having crossed the finish line. Implement the `CanFinish` function that takes a `Car` and a `Track` instance as its parameter and returns `true` if the car can finish the race from start to finish; otherwise, return `false`.

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 that you are currently at the starting line of the race and start the engine of the car for the race. Same as for `Drive` function if `battery` is less than `batteryDrain` car should not move even with partial `speed`. Take into account that the car's battery might not necessarily be fully charged when starting the race:
```go
speed := 5
batteryDrain := 2
Expand Down
13 changes: 13 additions & 0 deletions exercises/concept/need-for-speed/need_for_speed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ func TestCanFinish(t *testing.T) {
},
expected: false,
},
{
name: "Car cannot finish the track with partial move (part of batteryDrain)",
car: Car{
speed: 2,
batteryDrain: 200,
battery: 100,
distance: 0,
},
track: Track{
distance: 1,
},
expected: false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit cbf9957

Please sign in to comment.