Skip to content

Instantly share code, notes, and snippets.

@MikeMKH
Created June 1, 2014 21:31
Show Gist options
  • Save MikeMKH/dcc277fead14b6d44364 to your computer and use it in GitHub Desktop.
Save MikeMKH/dcc277fead14b6d44364 to your computer and use it in GitHub Desktop.
Leap year check kata in Haskell using HUnit
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]
@MikeMKH
Copy link
Author

MikeMKH commented Jun 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment