From 380976731fd1a4bfad45a4bd079ab212ed4dc10b Mon Sep 17 00:00:00 2001 From: Andrej Makarov Date: Wed, 25 Jan 2017 06:53:49 +0000 Subject: [PATCH] Add exercise: leap --- config.json | 10 +++++++++- exercises/leap/example.jl | 5 +++++ exercises/leap/leap.jl | 4 ++++ exercises/leap/runtests.jl | 20 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 exercises/leap/example.jl create mode 100644 exercises/leap/leap.jl create mode 100644 exercises/leap/runtests.jl 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 +