Test.QuickCheck.Function

QuickCheck-2.8.2: Automatic testing of Haskell programs

Safe Haskell | None
Language | Haskell98

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

- data Fun a b = Fun (a :-> b, b) (a -> b)
- apply :: Fun a b -> a -> b
- data a :-> c
- class Function a where
- functionMap :: Function b => (a -> b) -> (b -> a) -> (a -> c) -> a :-> c
- functionShow :: (Show a, Read a) => (a -> c) -> a :-> c
- pattern Fn :: forall a b. (a -> b) -> Fun a b

# Documentation

data Fun a b #

Constructors

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

Instances

(Show a, Show b) => Show (Fun a b) # |
Methods showsPrec :: Int -> Fun a b -> ShowS # show :: Fun a b -> String # showList :: [Fun a b] -> ShowS #
(Function a, CoArbitrary a, Arbitrary b) => Arbitrary (Fun a b) # |
Methods arbitrary :: Gen (Fun a b) # shrink :: Fun a b -> [Fun a b] #

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

data a :-> c #

The type of possibly partial concrete functions

Instances

Functor ((:->) a) # |
Methods fmap :: (a -> b) -> (a :-> a) -> a :-> b # (<$) :: a -> (a :-> b) -> a :-> a #
(Show a, Show b) => Show ((:->) a b) # |
Methods showsPrec :: Int -> (a :-> b) -> ShowS # show :: (a :-> b) -> String # showList :: [a :-> b] -> ShowS #
(Function a, CoArbitrary a, Arbitrary b) => Arbitrary ((:->) a b) # |
Methods arbitrary :: Gen (a :-> b) # shrink :: (a :-> b) -> [a :-> b] #

class Function a where #

Minimal complete definition

function

Methods

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

Instances

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

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

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

pattern Fn :: forall a b. (a -> b) -> Fun a b #

A pattern for matching against the function only:

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