1 -----------------------------------------------------------------------------
3 -- Module : Debug.QuickCheck.Utils
4 -- Copyright : (c) Andy Gill 2001
5 -- License : BSD-style (see the file libraries/base/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
25 import Debug.QuickCheck
27 isAssociativeBy :: (Show a,Testable prop)
28 => (a -> a -> prop) -> Gen a -> (a -> a -> a) -> Property
29 isAssociativeBy (===) src (**) =
33 ((a ** b) ** c) === (a ** (b ** c))
35 isAssociative :: (Arbitrary a,Show a,Eq a) => (a -> a -> a) -> Property
36 isAssociative = isAssociativeBy (==) arbitrary
38 isCommutableBy :: (Show a,Testable prop)
39 => (b -> b -> prop) -> Gen a -> (a -> a -> b) -> Property
40 isCommutableBy (===) src (**) =
45 isCommutable :: (Arbitrary a,Show a,Eq b) => (a -> a -> b) -> Property
46 isCommutable = isCommutableBy (==) arbitrary
48 isTotalOrder :: (Arbitrary a,Show a,Ord a) => a -> a -> Property
50 classify (x > y) "less than" $
51 classify (x == y) "equals" $
52 classify (x < y) "greater than" $
53 x < y || x == y || x > y