[project @ 2001-12-21 15:07:20 by simonmar]
[packages/base.git] / Debug / QuickCheck / Utils.hs
1 -----------------------------------------------------------------------------
2 --
3 -- Module : Debug.QuickCheck.Utils
4 -- Copyright : (c) Andy Gill 2001
5 -- License : BSD-style (see the file libraries/core/LICENSE)
6 --
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : portable
10 --
11 -- $Id: Utils.hs,v 1.2 2001/12/21 15:07:22 simonmar Exp $
12 --
13 -- These are some general purpose utilities for use with QuickCheck.
14 --
15 -----------------------------------------------------------------------------
16
17 module Debug.QuickCheck.Utils
18 ( isAssociativeBy
19 , isAssociative
20 , isCommutableBy
21 , isCommutable
22 , isTotalOrder
23 ) where
24
25 import Debug.QuickCheck
26
27 isAssociativeBy :: (Show a,Testable prop)
28 => (a -> a -> prop) -> Gen a -> (a -> a -> a) -> Property
29 isAssociativeBy (===) src (**) =
30 forAll src $ \ a ->
31 forAll src $ \ b ->
32 forAll src $ \ c ->
33 ((a ** b) ** c) === (a ** (b ** c))
34
35 isAssociative :: (Arbitrary a,Show a,Eq a) => (a -> a -> a) -> Property
36 isAssociative = isAssociativeBy (==) arbitrary
37
38 isCommutableBy :: (Show a,Testable prop)
39 => (b -> b -> prop) -> Gen a -> (a -> a -> b) -> Property
40 isCommutableBy (===) src (**) =
41 forAll src $ \ a ->
42 forAll src $ \ b ->
43 (a ** b) === (b ** a)
44
45 isCommutable :: (Arbitrary a,Show a,Eq b) => (a -> a -> b) -> Property
46 isCommutable = isCommutableBy (==) arbitrary
47
48 isTotalOrder :: (Arbitrary a,Show a,Ord a) => a -> a -> Property
49 isTotalOrder x y =
50 classify (x > y) "less than" $
51 classify (x == y) "equals" $
52 classify (x < y) "greater than" $
53 x < y || x == y || x > y