Skip to content

Instantly share code, notes, and snippets.

@MikeMKH
Created June 6, 2014 11:57
Show Gist options
  • Save MikeMKH/ffcc4b829101eb6f4b41 to your computer and use it in GitHub Desktop.
Save MikeMKH/ffcc4b829101eb6f4b41 to your computer and use it in GitHub Desktop.
Leap year kata in F# using FsUnit with Xunit
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
@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