QuickCheck-2.6: Automatic testing of Haskell programs

Safe Haskell | None
Language | Haskell98

Test.QuickCheck.Function

Description

Generation of random shrinkable, showable functions. Not really documented at the moment!

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.

# Documentation

data Fun a b

Constructors

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

Instances

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

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

data a :-> c

Instances

Functor ((:->) a) |
(Show a, Show b) => Show ((:->) a b) |
(Function a, CoArbitrary a, Arbitrary b) => Arbitrary ((:->) a b) |

class Function a where

Methods

function :: (a -> b) -> a :-> b

Instances

Function Bool |
Function Char |
Function Int |
Function Integer |
Function Word8 |
Function () |
Function OrdC |
Function OrdB |
Function OrdA |
Function C |
Function B |
Function A |
Function a => Function [a] |
Function a => Function (Maybe a) |
(Function a, Function b) => Function (Either a b) |
(Function a, Function b) => Function (a, b) |
(Function a, Function b, Function c) => Function (a, b, c) |
(Function a, Function b, Function c, Function d) => Function (a, b, c, d) |
(Function a, Function b, Function c, Function d, Function e) => Function (a, b, c, d, e) |
(Function a, Function b, Function c, Function d, Function e, Function f) => Function (a, b, c, d, e, f) |
(Function a, Function b, Function c, Function d, Function e, Function f, Function g) => Function (a, b, c, d, e, f, g) |

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

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