Created
June 6, 2014 11:57
-
-
Save MikeMKH/ffcc4b829101eb6f4b41 to your computer and use it in GitHub Desktop.
Leap year kata in F# using FsUnit with Xunit
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
namespace LeapYearChecker | |
open Xunit | |
open FsUnit.Xunit | |
module ``leap year kata`` = | |
let (|DivisibleBy|_|) by x = if x % by = 0 then Some DivisibleBy else None | |
let isLeapYear (year) = | |
match year with | |
| DivisibleBy 400 -> true | |
| DivisibleBy 100 -> false | |
| DivisibleBy 4 -> true | |
| _ -> false | |
[<Fact>] | |
let ``Given 4 it will return true`` () = | |
isLeapYear 4 |> should be True | |
[<Fact>] | |
let ``Given 1 it will return false`` () = | |
isLeapYear 1 |> should be False | |
[<Fact>] | |
let ``Given 64 it will return true`` () = | |
isLeapYear 64 |> should be True | |
[<Fact>] | |
let ``Given 2000 it will return true`` () = | |
isLeapYear 2000 |> should be True | |
[<Fact>] | |
let ``Given 1900 it will return false`` () = | |
isLeapYear 1900 |> should be False |
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