forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request JuliaLang#16 from andrej-makarov-skrt/ex-leap
Add exercise: leap
- Loading branch information
Showing
4 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function is_leap_year(year::Int) | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|