Created
January 20, 2018 10:35
-
-
Save bChiquet/6f027e00eb4797ab80629594bce0b32f to your computer and use it in GitHub Desktop.
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.Hspec | |
main = hspec $ do | |
describe "fizbuzz" $ do | |
it "returns a number string when given a number" $ do | |
fb 1 `shouldBe` "1" | |
fb 2 `shouldBe` "2" | |
fb 4 `shouldBe` "4" | |
it "returns 'fizz' when given a multiple of 3" $ do | |
fb 3 `shouldBe` "fizz" | |
fb 6 `shouldBe` "fizz" | |
it "returns 'buzz' when given a multiple of 5" $ do | |
fb 5 `shouldBe` "buzz" | |
fb 10 `shouldBe` "buzz" | |
it "returns 'fizzbuzz' when given a multiple of 3 and 5" $ do | |
fb 15 `shouldBe` "fizzbuzz" | |
fb 30 `shouldBe` "fizzbuzz" | |
mult :: Int -> Int -> Bool | |
mult a x = a `mod` x == 0 | |
fb :: Int -> String | |
fb a | (a `mult` 3 && a `mult` 5) = "fizzbuzz" | |
fb a | (a `mult` 5) = "buzz" | |
fb a | (a `mult` 3) = "fizz" | |
fb a = show a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment