Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement