QuickCheck-2.8.2: Automatic testing of Haskell programs

Safe HaskellNone
LanguageHaskell98

Test.QuickCheck.Function

Description

Generation of random shrinkable, showable functions. See the paper "Shrinking and showing functions" by Koen Claessen.

Example of use:

>>> :{
>>> let prop :: Fun String Integer -> Bool
>>> prop (Fun _ f) = f "monkey" == f "banana" || f "banana" == f "elephant"
>>> :}
>>> quickCheck prop
*** Failed! Falsifiable (after 3 tests and 134 shrinks):
{"elephant"->1, "monkey"->1, _->0}

To generate random values of type Fun a b, you must have an instance Function a. If your type has a Show instance, you can use functionShow to write the instance; otherwise, use functionMap to give a bijection between your type and a type that is already an instance of Function. See the Function [a] instance for an example of the latter.

Synopsis

Documentation

data Fun a b Source

Constructors

Fun (a :-> b, b) (a -> b) 

Instances

(Show a, Show b) => Show (Fun a b) Source 
(Function a, CoArbitrary a, Arbitrary b) => Arbitrary (Fun a b) Source 

apply :: Fun a b -> a -> b Source

data a :-> c Source

The type of possibly partial concrete functions

Instances

functionMap :: Function b => (a -> b) -> (b -> a) -> (a -> c) -> a :-> c Source

functionShow :: (Show a, Read a) => (a -> c) -> a :-> c Source

pattern Fn :: (t -> t) -> Fun t t Source

A pattern for matching against the function only:

prop :: Fun String Integer -> Bool
prop (Fn f) = f "banana" == f "monkey"
           || f "banana" == f "elephant"