diff --git a/config.json b/config.json index 837f57da49859..737779d7a31ca 100644 --- a/config.json +++ b/config.json @@ -5,7 +5,15 @@ "active": false, "test_pattern": "TODO", "exercises": [ - + { + "slug": "leap", + "difficulty": 1, + "topics": [ + "control-flow (conditionals)", + "integers", + "mathematics" + ] + } ], "deprecated": [ diff --git a/exercises/leap/example.jl b/exercises/leap/example.jl new file mode 100644 index 0000000000000..e4deb5bb25edd --- /dev/null +++ b/exercises/leap/example.jl @@ -0,0 +1,5 @@ +# Leap on every year that is evenly divisible by 4 +# except every year that is evenly divisible by 100 +# unless the year is also evenly divisible by 400 +is_leap_year(year::Int) = (year % 100 != 0 && year % 4 == 0) || (year % 400 == 0) + diff --git a/exercises/leap/leap.jl b/exercises/leap/leap.jl new file mode 100644 index 0000000000000..1af9bacbeffb0 --- /dev/null +++ b/exercises/leap/leap.jl @@ -0,0 +1,4 @@ +function is_leap_year(year::Int) + +end + diff --git a/exercises/leap/runtests.jl b/exercises/leap/runtests.jl new file mode 100644 index 0000000000000..08642402c7e78 --- /dev/null +++ b/exercises/leap/runtests.jl @@ -0,0 +1,20 @@ +using Base.Test + +include("leap.jl") + +@testset "Year not divisible by 4: common year" begin + @test !is_leap_year(2015) +end + +@testset "Year divisible by 4, not divisible by 100: leap year" begin + @test is_leap_year(2016) +end + +@testset "Year divisible by 100, not divisible by 400: common year" begin + @test !is_leap_year(2100) +end + +@testset "Year divisible by 400: leap year" begin + @test is_leap_year(2000) +end +