Stability | experimental |
---|---|

Maintainer | conal@conal.net |

Some QuickCheck helpers

- type Test = (String, Property)
- type TestBatch = (String, [Test])
- unbatch :: TestBatch -> [Test]
- checkBatch :: Args -> TestBatch -> IO ()
- quickBatch :: TestBatch -> IO ()
- verboseBatch :: TestBatch -> IO ()
- type Unop a = a -> a
- type Binop a = a -> a -> a
- genR :: Random a => (a, a) -> Gen a
- inverseL :: (EqProp b, Arbitrary b, Show b) => (a -> b) -> (b -> a) -> Property
- inverse :: (EqProp a, Arbitrary a, Show a, EqProp b, Arbitrary b, Show b) => (a -> b) -> (b -> a) -> Property
- type FracT = Float
- type NumT = Int
- type OrdT = Int
- type T = Char
- class EqProp a where
- eq :: Eq a => a -> a -> Property
- type BinRel a = a -> a -> Bool
- reflexive :: (Arbitrary a, Show a) => BinRel a -> Property
- transitive :: (Arbitrary a, Show a) => BinRel a -> (a -> Gen a) -> Property
- symmetric :: (Arbitrary a, Show a) => BinRel a -> (a -> Gen a) -> Property
- antiSymmetric :: (Arbitrary a, Show a, Eq a) => BinRel a -> (a -> Gen a) -> Property
- leftId :: (Show a, Arbitrary a, EqProp a) => (i -> a -> a) -> i -> Property
- rightId :: (Show a, Arbitrary a, EqProp a) => (a -> i -> a) -> i -> Property
- bothId :: (Show a, Arbitrary a, EqProp a) => (a -> a -> a) -> a -> Property
- isAssoc :: (EqProp a, Show a, Arbitrary a) => (a -> a -> a) -> Property
- isCommut :: (EqProp a, Show a, Arbitrary a) => (a -> a -> a) -> Property
- commutes :: EqProp z => (a -> a -> z) -> a -> a -> Property
- data MonoidD a
- monoidD :: Monoid a => MonoidD a
- endoMonoidD :: MonoidD (a -> a)
- homomorphism :: (EqProp b, Show a, Arbitrary a) => MonoidD a -> MonoidD b -> (a -> b) -> [(String, Property)]
- idempotent :: (Show a, Arbitrary a, EqProp a) => (a -> a) -> Property
- idempotent2 :: (Show a, Arbitrary a, EqProp a) => (a -> a -> a) -> Property
- idemElem :: EqProp a => (a -> a -> a) -> a -> Property
- class Model a b | a -> b where
- model :: a -> b

- meq :: (Model a b, EqProp b) => a -> b -> Property
- meq1 :: (Model a b, Model a1 b1, EqProp b) => (a1 -> a) -> (b1 -> b) -> a1 -> Property
- meq2 :: (Model a b, Model a1 b1, Model a2 b2, EqProp b) => (a1 -> a2 -> a) -> (b1 -> b2 -> b) -> a1 -> a2 -> Property
- meq3 :: (Model a b, Model a1 b1, Model a2 b2, Model a3 b3, EqProp b) => (a1 -> a2 -> a3 -> a) -> (b1 -> b2 -> b3 -> b) -> a1 -> a2 -> a3 -> Property
- meq4 :: (Model a b, Model a1 b1, Model a2 b2, Model a3 b3, Model a4 b4, EqProp b) => (a1 -> a2 -> a3 -> a4 -> a) -> (b1 -> b2 -> b3 -> b4 -> b) -> a1 -> a2 -> a3 -> a4 -> Property
- meq5 :: (Model a b, Model a1 b1, Model a2 b2, Model a3 b3, Model a4 b4, Model a5 b5, EqProp b) => (a1 -> a2 -> a3 -> a4 -> a5 -> a) -> (b1 -> b2 -> b3 -> b4 -> b5 -> b) -> a1 -> a2 -> a3 -> a4 -> a5 -> Property
- eqModels :: (Model a b, EqProp b) => a -> a -> Property
- class Model1 f g | f -> g where
- model1 :: forall a. f a -> g a

- arbs :: Arbitrary a => Int -> IO [a]
- gens :: Int -> Gen a -> IO [a]
- (.&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- arbitrarySatisfying :: Arbitrary a => (a -> Bool) -> Gen a

# Misc

checkBatch :: Args -> TestBatch -> IO ()Source

Run a batch of tests. See `quickBatch`

and `verboseBatch`

.

quickBatch :: TestBatch -> IO ()Source

Check a batch tersely.

verboseBatch :: TestBatch -> IO ()Source

Check a batch verbosely.

inverseL :: (EqProp b, Arbitrary b, Show b) => (a -> b) -> (b -> a) -> PropertySource

`f`

is a left inverse of `g`

. See also `inverse`

.

inverse :: (EqProp a, Arbitrary a, Show a, EqProp b, Arbitrary b, Show b) => (a -> b) -> (b -> a) -> PropertySource

`f`

is a left and right inverse of `g`

. See also `inverseL`

.

Token `Fractional`

type for tests

# Generalized equality

Types of values that can be tested for equality, perhaps through random sampling.

EqProp Bool | |

EqProp Char | |

EqProp Double | |

EqProp Float | |

EqProp Int | |

EqProp a => EqProp [a] | |

EqProp a => EqProp (Maybe a) | |

(Show a, Arbitrary a, EqProp b) => EqProp (a -> b) | |

(EqProp a, EqProp b) => EqProp (Either a b) | |

(EqProp a, EqProp b) => EqProp (a, b) | |

(EqProp a, EqProp b, EqProp c) => EqProp (a, b, c) | |

(EqProp a, EqProp b, EqProp c, EqProp d) => EqProp (a, b, c, d) |

transitive :: (Arbitrary a, Show a) => BinRel a -> (a -> Gen a) -> PropertySource

Transitive property: `a `

.
Generate `rel`

b && b `rel`

c ==> a `rel`

c`a`

randomly, but use `gen a`

to generate `b`

and `gen b`

to
generate `c`

. `gen`

ought to satisfy `rel`

fairly often.

symmetric :: (Arbitrary a, Show a) => BinRel a -> (a -> Gen a) -> PropertySource

Symmetric property: `a `

. Generate `rel`

b ==> b `rel`

a`a`

randomly, but use `gen a`

to generate `b`

. `gen`

ought to satisfy
`rel`

fairly often.

antiSymmetric :: (Arbitrary a, Show a, Eq a) => BinRel a -> (a -> Gen a) -> PropertySource

Symmetric property: `a `

. Generate
`rel`

b && b `rel`

a ==> a == b`a`

randomly, but use `gen a`

to generate `b`

. `gen`

ought to satisfy
both `rel`

directions fairly often but not always.

leftId :: (Show a, Arbitrary a, EqProp a) => (i -> a -> a) -> i -> PropertySource

Has a given left identity, according to '(=-=)'

rightId :: (Show a, Arbitrary a, EqProp a) => (a -> i -> a) -> i -> PropertySource

Has a given right identity, according to '(=-=)'

bothId :: (Show a, Arbitrary a, EqProp a) => (a -> a -> a) -> a -> PropertySource

Has a given left and right identity, according to '(=-=)'

isAssoc :: (EqProp a, Show a, Arbitrary a) => (a -> a -> a) -> PropertySource

Associative, according to '(=-=)'

isCommut :: (EqProp a, Show a, Arbitrary a) => (a -> a -> a) -> PropertySource

Commutative, according to '(=-=)'

endoMonoidD :: MonoidD (a -> a)Source

homomorphism :: (EqProp b, Show a, Arbitrary a) => MonoidD a -> MonoidD b -> (a -> b) -> [(String, Property)]Source

Homomorphism properties with respect to given monoid dictionaries.
See also `monoidMorphism`

.

idempotent :: (Show a, Arbitrary a, EqProp a) => (a -> a) -> PropertySource

The unary function `f`

is idempotent, i.e., `f . f == f`

idempotent2 :: (Show a, Arbitrary a, EqProp a) => (a -> a -> a) -> PropertySource

A binary function `op`

is idempotent, i.e., `x `

, for all `op`

x == x`x`

idemElem :: EqProp a => (a -> a -> a) -> a -> PropertySource

A binary function `op`

is has an idempotent element `x`

, i.e.,
`x `

`op`

x == x

# Model-based (semantics-based) testing

meq2 :: (Model a b, Model a1 b1, Model a2 b2, EqProp b) => (a1 -> a2 -> a) -> (b1 -> b2 -> b) -> a1 -> a2 -> PropertySource

meq3 :: (Model a b, Model a1 b1, Model a2 b2, Model a3 b3, EqProp b) => (a1 -> a2 -> a3 -> a) -> (b1 -> b2 -> b3 -> b) -> a1 -> a2 -> a3 -> PropertySource

meq4 :: (Model a b, Model a1 b1, Model a2 b2, Model a3 b3, Model a4 b4, EqProp b) => (a1 -> a2 -> a3 -> a4 -> a) -> (b1 -> b2 -> b3 -> b4 -> b) -> a1 -> a2 -> a3 -> a4 -> PropertySource

meq5 :: (Model a b, Model a1 b1, Model a2 b2, Model a3 b3, Model a4 b4, Model a5 b5, EqProp b) => (a1 -> a2 -> a3 -> a4 -> a5 -> a) -> (b1 -> b2 -> b3 -> b4 -> b5 -> b) -> a1 -> a2 -> a3 -> a4 -> a5 -> PropertySource

# Some handy testing types

(.&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property

Nondeterministic choice: `p1`

`.&.`

`p2`

picks randomly one of
`p1`

and `p2`

to test. If you test the property 100 times it
makes 100 random choices.

arbitrarySatisfying :: Arbitrary a => (a -> Bool) -> Gen aSource