I've submitted the exercise with the tests from canonical-data.json and a more mathematical example.jl.
I've marked this as a 4 difficulty, but could see it also as a 3.
Testing in canonical-data.json could be augmented with further edge cases.
Below are some extra edge cases which I encountered while working on the more mathematical implementation, but I only included a few here. I was testing against a more procedural implementation, which can be found below the tests (the two algorithms are mutually consistent as far as I can tell).
Lastly, below that, there is a function to produce example input, which I used to test the two implementations against each other.
Extra edge cases which could be added to testing:
@testset "Buckets are same size but goal is different" begin
@test_throws DomainError twobucket(4, 4, 2, 1)
end
@testset "Both buckets are the same size as the goal" begin
@test twobucket(3, 3, 3, 1) == (1, 1, 0)
@test twobucket(3, 3, 3, 2) == (1, 2, 0)
end
@testset "Goal is multiple of smaller bucket and smaller than larger bucket, start with smaller bucket" begin
@test twobucket(4, 9, 8, 1) == (4, 2, 0)
end
@testset "Goal is multiple of smaller bucket and smaller than larger bucket, start with larger bucket" begin
@test twobucket(1, 9, 7, 2) == (4, 2, 1)
end
@testset "Bucket one is larger than bucket two, start with bucket one" begin
@test twobucket(9, 5, 4, 1) == (2, 1, 5)
end
@testset "Bucket one is larger than bucket two, start with bucket two" begin
@test twobucket(9, 5, 4, 2) == (22, 2, 9)
end
@testset "Switching bucket order and start number gives same result only with end bucket number switched" begin
@test twobucket(26, 12, 4, 1) == (10, 1, 12)
@test twobucket(12, 26, 4, 2) == (10, 2, 12)
end
I've submitted the exercise with the tests from
canonical-data.json
and a more mathematicalexample.jl
.canonical-data.json
could be augmented with further edge cases.Below are some extra edge cases which I encountered while working on the more mathematical implementation, but I only included a few here. I was testing against a more procedural implementation, which can be found below the tests (the two algorithms are mutually consistent as far as I can tell). Lastly, below that, there is a function to produce example input, which I used to test the two implementations against each other.
Extra edge cases which could be added to testing:
Procedural approach for
example.jl
:A function to produce example input in case a reviewer would like to experiment: