Skip to content

Commit

Permalink
grains: replace tests with canonical-data tests and fix example script (
Browse files Browse the repository at this point in the history
JuliaLang#141)

* replaced grains tests with canonical-data tests and fixed example script

* split grains testsets and added comment about cononical data
  • Loading branch information
dhpollack authored and SaschaMann committed Apr 5, 2019
1 parent 0863b30 commit f4f6c59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion exercises/grains/example.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Calculate the number of grains on square `square`."""
function on_square(square)
check_square_input(square)
2 ^ (square - 1)
Int128(2) ^ (square - 1)
end

"""Calculate the total number of grains after square `square`."""
Expand Down
22 changes: 17 additions & 5 deletions exercises/grains/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
using Test

# canonical data version: 1.2.0

include("grains.jl")

@testset "On squares" begin
@testset "On square $s" for s = UInt64(1):64
@test on_square(s) == 2^(s-1)
@test total_after(s) == 2^s - 1
end
@testset "beginning squares" begin
@test on_square(1) == 1
@test on_square(2) == 2
@test on_square(3) == 4
@test on_square(4) == 8
@test on_square(16) == 32768
@test on_square(32) == 2147483648
@test total_after(1) == 1
@test total_after(3) == on_square(1) + on_square(2) + on_square(3)
end

@testset "ending squares" begin
@test total_after(32) < total_after(64)
@test on_square(64) == 9223372036854775808
@test total_after(64) == 18446744073709551615
end

@testset "Invalid values" begin
Expand Down

0 comments on commit f4f6c59

Please sign in to comment.