{-# LANGUAGE TemplateHaskell #-} module TestSets where import Test.QuickCheck import SetsAsOrderedList -- The type of elements of sets to be tested: type Elem = Int prop_empty_elem :: Elem -> Bool prop_empty_elem x = not (isElem x empty) prop_insert_elem :: Elem -> Set Elem -> Bool prop_insert_elem x s = isElem x (insert x s) prop_insert2_elem :: Elem -> Elem -> Set Elem -> Bool prop_insert2_elem x y s = isElem x (insert y (insert x s)) prop_union_elem :: Elem -> Set Elem -> Set Elem -> Bool prop_union_elem x s1 s2 = isElem x (union s1 s2) == (isElem x s1 || isElem x s2) -- Arbitrary instance for sets based on guessing lists and transforming -- them into sets: instance (Ord a, Arbitrary a) => Arbitrary (Set a) where arbitrary = do xs <- arbitrary return ((foldr :: (a -> b -> b) -> b -> [a] -> b) insert empty xs) -- Executing all tests: return [] testAll = $quickCheckAll