Last active
January 23, 2017 16:40
-
-
Save PeterHajdu/ba3c2d0405a1e337692c44a1eccc1f53 to your computer and use it in GitHub Desktop.
test basics in haskell
This file contains 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 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