module Main (main) where import Control.Monad (unless) import Test.QuickCheck (Testable, isSuccess, quickCheckResult) import System.Exit (exitFailure) import Data.SortedList (SortedList) import qualified Data.SortedList as SL import qualified Data.List as List -- | Test a property. quickCheck :: Testable prop => String -> prop -> IO () quickCheck n p = do putStrLn $ "Testing property: " ++ n r <- quickCheckResult p unless (isSuccess r) exitFailure applyAsList :: Ord a => ([a] -> [a]) -> SortedList a -> SortedList a applyAsList f = SL.toSortedList . f . SL.fromSortedList main :: IO () main = do quickCheck "toSortedList . fromSortedList = id" $ \xs -> applyAsList id xs == (xs :: SortedList Int) quickCheck "insert" $ \x xs -> SL.insert x xs == applyAsList ((:) x) (xs :: SortedList Int) quickCheck "delete" $ \x xs -> let ys :: SortedList Int ys = SL.toSortedList $ x : xs in SL.delete x ys == applyAsList (List.delete x) ys quickCheck "deleteAll" $ \x xs -> SL.deleteAll (x :: Int) xs == SL.filter (/=x) xs quickCheck "elemOrd" $ \x xs -> SL.elemOrd x xs == List.elem (x :: Int) (SL.fromSortedList xs) quickCheck "nub" $ \xs -> SL.nub xs == applyAsList List.nub (xs :: SortedList Int)