Skip to content

Commit

Permalink
Add leap exercise (#8)
Browse files Browse the repository at this point in the history
* Add leap exercise

* Remove template type sig

We don't provide these in the Elm track, so it seems sensible not to do
it here either.
  • Loading branch information
lpil authored and paf31 committed Dec 9, 2016
1 parent 3311965 commit 2f2ba39
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 5 deletions.
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

0 comments on commit 2f2ba39

Please sign in to comment.