Last active
March 3, 2017 08:42
-
-
Save sroccaserra/3bfcb918daaa745808466bed03ac7d83 to your computer and use it in GitHub Desktop.
Coding Dojo Haskell 001
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
| module Fibonacci where | |
| fibonacci 1 = 0 | |
| fibonacci 2 = 1 | |
| fibonacci n = fibonacci(n - 1) + fibonacci(n - 2) |
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
| test: | |
| @runhaskell Test.hs | |
| dependencies: | |
| cabal update | |
| cabal install hspec base-unicode-symbols |
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 | |
| import Fibonacci | |
| -- Fibonacci | |
| -- 1 -> 0 | |
| -- 2 -> 1 | |
| -- 3 -> 1 | |
| -- 4 -> 2 | |
| -- 5 -> 3 | |
| -- 6 -> 5 | |
| main = hspec $ do | |
| describe "Fibonacci numbers" $ do | |
| it "1 => 0" $ do | |
| fibonacci 1 `shouldBe` 0 | |
| it "2 => 1" $ do | |
| fibonacci 2 `shouldBe` 1 | |
| it "3 => 1" $ do | |
| fibonacci 3 `shouldBe` 1 | |
| it "4 => 2" $ do | |
| fibonacci 4 `shouldBe` 2 | |
| describe "Fibonacci undefined arguments" $ do | |
| it "should fail for 0" $ do | |
| fibonacci 0 `shouldThrow` anyException |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment