Added fibonacci function and some tests for it. Still working on organizing tests.

This commit is contained in:
Martin Sosic 2019-02-17 19:44:57 +01:00
parent b02f9cd914
commit 7c2d42fdfd
3 changed files with 31 additions and 7 deletions

View File

@ -63,3 +63,4 @@ tests:
- stic
- tasty
- tasty-hspec
- tasty-quickcheck

View File

@ -1,6 +1,13 @@
module Lib
( someFunc
module Lib (
someFunc,
fibonacci
) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"
fibonacci :: (Num a, Ord a, Num b) => a -> b
fibonacci 0 = 0
fibonacci 1 = 1
fibonacci n | n > 1 = (fibonacci (n - 1)) + (fibonacci (n - 2))
fibonacci _ = undefined

View File

@ -1,5 +1,8 @@
import qualified Test.Tasty
import Test.Tasty.Hspec
import Test.Tasty.QuickCheck as QC
import Lib
main :: IO ()
main = do
@ -8,5 +11,18 @@ main = do
spec :: Spec
spec = parallel $ do
it "is trivially true" $ do
True `shouldBe` True
it "fibonacci element #0 is 0" $ do
fibonacci 0 `shouldBe` 0
it "fibonacci element #1 is 1" $ do
fibonacci 1 `shouldBe` 1
it "fibonacci element #2 is 1" $ do
fibonacci 2 `shouldBe` 1
it "fibonacci element #3 is 2" $ do
fibonacci 3 `shouldBe` 2
-- TODO: Figure out how to organize tests for multiple modules!
-- I should read https://documentup.com/feuerbach/tasty, especially "Project organization and integration with Cabal"
-- part, and then continue from there. Search for some examples, maybe existing projects.
-- Also, can tests be mixed with source files as we usually do it in other languages? They certainly can,
-- but is that better and if yes how would be implement that?
-- Do we need smth like tasty-discovery?