{-# LANGUAGE TemplateHaskell #-} -- Testing the ADT laws for sets: module TestSets where import Test.QuickCheck --import Sets --import SetsAsLists import SetsAsOrdLists import qualified Data.List (foldr) type Elem = Int prop_empty_list :: Elem -> Bool prop_empty_list x = isElem x empty == False prop_elem_insert :: Elem -> Set Elem -> Bool prop_elem_insert x s = isElem x (insert x s) == True prop_insert_insert :: Elem -> Elem -> Set Elem -> Bool prop_insert_insert x y s = isElem x (insert y (insert x s)) == True prop_union :: Elem -> Set Elem -> Set Elem -> Bool prop_union x s1 s2 = isElem x (union s1 s2) == isElem x s1 || isElem x s2 instance (Eq a, Ord a, Arbitrary a) => Arbitrary (Set a) where arbitrary = do s <- arbitrary -- generate an arbitrary list of `a` elements return ((foldr :: (a->b->b) -> b -> [a] -> b) insert empty s) -- run all property tests: return [] testAll = $quickCheckAll