Created
June 1, 2014 21:31
-
-
Save MikeMKH/dcc277fead14b6d44364 to your computer and use it in GitHub Desktop.
Leap year check kata in Haskell using HUnit
This file contains hidden or 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
import Test.HUnit | |
isLeapYear::Int->Bool | |
isLeapYear y | |
| mod y 400 == 0 = True | |
| mod y 100 == 0 = False | |
| mod y 4 == 0 = True | |
| otherwise = False | |
tests = TestList[TestCase $ assertEqual "4 is a leap year" True $ isLeapYear 4 | |
,TestCase $ assertEqual "1 is not a leap year" False $ isLeapYear 1 | |
,TestCase $ assertEqual "64 is a leap year" True $ isLeapYear 64 | |
,TestCase $ assertEqual "2000 is a leap year" True $ isLeapYear 2000 | |
,TestCase $ assertEqual "1900 is not a leap year" False $ isLeapYear 1900] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my blog post which goes with this: http://comp-phil.blogspot.com/2014/06/leap-year-in-key-of-c-f-haskell-and.html