Skip to content

Instantly share code, notes, and snippets.

@bChiquet
Created January 20, 2018 10:35
Show Gist options
  • Save bChiquet/6f027e00eb4797ab80629594bce0b32f to your computer and use it in GitHub Desktop.
Save bChiquet/6f027e00eb4797ab80629594bce0b32f to your computer and use it in GitHub Desktop.
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