Skip to content

Instantly share code, notes, and snippets.

@sroccaserra
Last active March 3, 2017 08:42
Show Gist options
  • Select an option

  • Save sroccaserra/3bfcb918daaa745808466bed03ac7d83 to your computer and use it in GitHub Desktop.

Select an option

Save sroccaserra/3bfcb918daaa745808466bed03ac7d83 to your computer and use it in GitHub Desktop.
Coding Dojo Haskell 001
module Fibonacci where
fibonacci 1 = 0
fibonacci 2 = 1
fibonacci n = fibonacci(n - 1) + fibonacci(n - 2)
test:
@runhaskell Test.hs
dependencies:
cabal update
cabal install hspec base-unicode-symbols
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