1 -----------------------------------------------------------------------------
3 -- Module : Debug.QuickCheck.Utils
4 -- Copyright : (c) Andy Gill 2001
5 -- License : BSD-style (see the file libraries/core/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : portable
11 -- These are some general purpose utilities for use with QuickCheck.
13 -----------------------------------------------------------------------------
15 module Debug.QuickCheck.Utils
23 import Debug.QuickCheck
25 isAssociativeBy :: (Show a,Testable prop)
26 => (a -> a -> prop) -> Gen a -> (a -> a -> a) -> Property
27 isAssociativeBy (===) src (**) =
31 ((a ** b) ** c) === (a ** (b ** c))
33 isAssociative :: (Arbitrary a,Show a,Eq a) => (a -> a -> a) -> Property
34 isAssociative = isAssociativeBy (==) arbitrary
36 isCommutableBy :: (Show a,Testable prop)
37 => (b -> b -> prop) -> Gen a -> (a -> a -> b) -> Property
38 isCommutableBy (===) src (**) =
43 isCommutable :: (Arbitrary a,Show a,Eq b) => (a -> a -> b) -> Property
44 isCommutable = isCommutableBy (==) arbitrary
46 isTotalOrder :: (Arbitrary a,Show a,Ord a) => a -> a -> Property
48 classify (x > y) "less than" $
49 classify (x == y) "equals" $
50 classify (x < y) "greater than" $
51 x < y || x == y || x > y