Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add leap exercise #8

Merged
merged 2 commits into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
bin/configlet
bin/configlet.exe

**/npm-debug.log

# Purescript artifact directories
**/bower_components/
**/node_modules/
Expand Down
7 changes: 7 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"maybe"
]
},
{
"slug": "leap",
"difficulty": 1,
"topics": [
"modulo"
]
},
{
"slug": "raindrops",
"difficulty": 1,
Expand Down
5 changes: 0 additions & 5 deletions exercises/hello-world/src/HelloWorld.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
module HelloWorld where

import Prelude
import Data.Maybe (Maybe(Just, Nothing))

helloWorld :: Maybe String -> String
16 changes: 16 additions & 0 deletions exercises/leap/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "leap",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"output"
],
"dependencies": {
"purescript-prelude": "^2.1.0"
},
"devDependencies": {
"purescript-psci-support": "^2.0.0",
"purescript-test-unit": "^10.0.1"
}
}
9 changes: 9 additions & 0 deletions exercises/leap/examples/src/Leap.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Leap where

import Prelude

isLeapYear :: Int -> Boolean
isLeapYear year =
mod year 4 == 0 &&
mod year 100 /= 0 ||
mod year 400 == 0
1 change: 1 addition & 0 deletions exercises/leap/src/Leap.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Leap where
25 changes: 25 additions & 0 deletions exercises/leap/test/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Test.Main where

import Prelude
import Test.Unit (suite, test)
import Test.Unit.Main (runTest)
import Test.Unit.Assert as Assert
import Leap as Leap


main = runTest do
suite "Leap.isLeapYear" do
test "leap year" do
Assert.equal true $ Leap.isLeapYear 1996
test "non-leap year" do
Assert.equal false $ Leap.isLeapYear 1997
test "non-leap even year" do
Assert.equal false $ Leap.isLeapYear 1998
test "century" do
Assert.equal false $ Leap.isLeapYear 1900
test "second century" do
Assert.equal false $ Leap.isLeapYear 1800
test "fourth century" do
Assert.equal true $ Leap.isLeapYear 2400
test "y2k" do
Assert.equal true $ Leap.isLeapYear 2000