Skip to content

Commit

Permalink
Merge pull request JuliaLang#16 from andrej-makarov-skrt/ex-leap
Browse files Browse the repository at this point in the history
Add exercise: leap
  • Loading branch information
SaschaMann authored Jan 25, 2017
2 parents e9a840a + 3809767 commit f682d4d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
10 changes: 9 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
"active": false,
"test_pattern": "TODO",
"exercises": [

{
"slug": "leap",
"difficulty": 1,
"topics": [
"control-flow (conditionals)",
"integers",
"mathematics"
]
}
],
"deprecated": [

Expand Down
5 changes: 5 additions & 0 deletions exercises/leap/example.jl
Original file line number Diff line number Diff line change
@@ -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)

4 changes: 4 additions & 0 deletions exercises/leap/leap.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function is_leap_year(year::Int)

end

20 changes: 20 additions & 0 deletions exercises/leap/runtests.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f682d4d

Please sign in to comment.