Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. module Main where
  2.  
  3. import Test.Hspec
  4. import Test.QuickCheck
  5.  
  6. sqr :: Integer -> Integer
  7. sqr n = n * n
  8.  
  9. squareNumberIsGreaterOrEqualToZero :: Integer -> Bool
  10. squareNumberIsGreaterOrEqualToZero n = sqr n >= 0
  11.  
  12. theOtherProperty :: Integer -> Bool
  13. theOtherProperty n = let bign = (abs n) + 1
  14. in sqr bign >= bign
  15.  
  16. theThird :: Integer -> Bool
  17. theThird n = (round $ sqrt (fromIntegral $ sqr n)) == abs n
  18.  
  19. main :: IO ()
  20. main = do
  21. quickCheck squareNumberIsGreaterOrEqualToZero
  22. quickCheck theOtherProperty
  23. quickCheck theThird
  24. hspec $ describe "square function" $ do
  25. it "the square of 0 is 0" $
  26. sqr 0 `shouldBe` 0
  27.  
  28. it "the square of 1 is 1" $
  29. sqr 1 `shouldBe` 1
  30.  
  31. it "the square of 2 is 4" $
  32. sqr 2 `shouldBe` 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement