module Page562Tests where import Page562 import Test.QuickCheck import Data.List (sort) --Ex 1 halfIdentity :: (Fractional a, Num a) => a -> a halfIdentity = (*2) . half prop_halfIdentity :: Float -> Bool prop_halfIdentity x = x == halfIdentity x --Ex 2 listGen :: Arbitrary => Gen [a] listGen = do a <- arbitrary return (a) listIsOrdered :: [a] -> Bool listIsOrdered xs = snd $ foldr go (Nothing, True) xs where go _ status@(_, False) = status go y (Nothing, t) = (Just y, t) go y (Just x, t) = (Just y, x >= y) prop_listOrdered :: Property prop_listOrdered = forAll listGen (\l -> (listIsOrdered $ sort l)) runQC :: IO () runQC = do quickCheck prop_halfIdentity quickCheck prop_listOrdered