Last active
August 29, 2015 14:14
-
-
Save njpst8/55c9f632a0d391363fb2 to your computer and use it in GitHub Desktop.
using unfold to generate a FizzBuzz sequence
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
| let genFizzBuzz arg = | |
| match arg % 3, arg % 5 with | |
| | 0, 0 -> "fizzbuzz" | |
| | 0, _ -> "fizz" | |
| | _, 0 -> "buzz" | |
| | _, _ -> string arg | |
| [<Test>] | |
| let fizzbuzztester1() = | |
| Assert.AreEqual("1", genFizzBuzz 1) | |
| [<Test>] | |
| let fizzbuzztester3() = | |
| Assert.AreEqual("fizz", genFizzBuzz 3) | |
| [<Test>] | |
| let fizzbuzztester5() = | |
| Assert.AreEqual("buzz", genFizzBuzz 5) | |
| [<Test>] | |
| let fizzbuzztester15() = | |
| Assert.AreEqual("fizzbuzz", genFizzBuzz 15) | |
| let fizzbuzzseq = Seq.unfold (fun x -> | |
| if (x > 15) then None | |
| else Some((genFizzBuzz x), x+1)) 1 | |
| [<Test>] | |
| let fibHuh2() = | |
| Assert.AreEqual([| "1"; "2"; "fizz"; "4"; "buzz"; "fizz"; "7"; "8"; "fizz"; "buzz"; "11"; "fizz"; "13"; "14"; "fizzbuzz"|], Seq.toArray(fizzbuzzseq)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment