Skip to content

Instantly share code, notes, and snippets.

@PeterHajdu
Last active January 23, 2017 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeterHajdu/ba3c2d0405a1e337692c44a1eccc1f53 to your computer and use it in GitHub Desktop.
Save PeterHajdu/ba3c2d0405a1e337692c44a1eccc1f53 to your computer and use it in GitHub Desktop.
test basics in haskell
module Main where
import Test.Hspec
import Test.QuickCheck
sqr :: Integer -> Integer
sqr n = n * n
squareNumberIsGreaterOrEqualToZero :: Integer -> Bool
squareNumberIsGreaterOrEqualToZero n = sqr n >= 0
theOtherProperty :: Integer -> Bool
theOtherProperty n = let bign = (abs n) + 1
in sqr bign >= bign
theThird :: Integer -> Bool
theThird n = (round $ sqrt (fromIntegral $ sqr n)) == abs n
main :: IO ()
main = do
quickCheck squareNumberIsGreaterOrEqualToZero
quickCheck theOtherProperty
quickCheck theThird
hspec $ describe "square function" $ do
it "the square of 0 is 0" $
sqr 0 `shouldBe` 0
it "the square of 1 is 1" $
sqr 1 `shouldBe` 1
it "the square of 2 is 4" $
sqr 2 `shouldBe` 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment