QuickCheck-2.14.2: Automatic testing of Haskell programs
Safe Haskell Safe
Language Haskell2010

Test.QuickCheck.Function

Description

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

Note : most of the contents of this module are re-exported by Test.QuickCheck . You probably do not need to import it directly.

Example of use:

>>> :{
>>> let prop :: Fun String Integer -> Bool
>>> prop (Fun _ f) = f "monkey" == f "banana" || f "banana" == f "elephant"
>>> :}
>>> quickCheck prop
*** Failed! Falsified (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 #

Generation of random shrinkable, showable functions.

To generate random values of type Fun a b , you must have an instance Function a .

See also applyFun , and Fn with GHC >= 7.8.

Constructors

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

applyFun :: Fun a b -> a -> b Source #

Extracts the value of a function.

Fn is the pattern equivalent of this function.

prop :: Fun String Integer -> Bool
prop f = applyFun f "banana" == applyFun f "monkey"
      || applyFun f "banana" == applyFun f "elephant"

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

Alias to applyFun .

applyFun2 :: Fun (a, b) c -> a -> b -> c Source #

Extracts the value of a binary function.

Fn2 is the pattern equivalent of this function.

prop_zipWith :: Fun (Int, Bool) Char -> [Int] -> [Bool] -> Bool
prop_zipWith f xs ys = zipWith (applyFun2 f) xs ys == [ applyFun2 f x y | (x, y) <- zip xs ys]

applyFun3 :: Fun (a, b, c) d -> a -> b -> c -> d Source #

Extracts the value of a ternary function. Fn3 is the pattern equivalent of this function.

data a :-> c Source #

The type of possibly partial concrete functions

class Function a where Source #

The class Function a is used for random generation of showable functions of type a -> b .

There is a default implementation for function , which you can use if your type has structural equality. Otherwise, you can normally use functionMap or functionShow .

Minimal complete definition

Nothing

Methods

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

default function :: ( Generic a, GFunction ( Rep a)) => (a -> b) -> a :-> b Source #

Instances

Instances details
Function Bool Source #
Instance details

Defined in Test.QuickCheck.Function

Function Char Source #
Instance details

Defined in Test.QuickCheck.Function

Function Double Source #
Instance details

Defined in Test.QuickCheck.Function

Function Float Source #
Instance details

Defined in Test.QuickCheck.Function

Function Int Source #
Instance details

Defined in Test.QuickCheck.Function

Function Int8 Source #
Instance details

Defined in Test.QuickCheck.Function

Function Int16 Source #
Instance details

Defined in Test.QuickCheck.Function

Function Int32 Source #
Instance details

Defined in Test.QuickCheck.Function

Function Int64 Source #
Instance details

Defined in Test.QuickCheck.Function

Function Integer Source #
Instance details

Defined in Test.QuickCheck.Function

Function Ordering Source #
Instance details

Defined in Test.QuickCheck.Function

Function Word Source #
Instance details

Defined in Test.QuickCheck.Function

Function Word8 Source #
Instance details

Defined in Test.QuickCheck.Function

Function Word16 Source #
Instance details

Defined in Test.QuickCheck.Function

Function Word32 Source #
Instance details

Defined in Test.QuickCheck.Function

Function Word64 Source #
Instance details

Defined in Test.QuickCheck.Function

Function () Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

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

Function All Source #
Instance details

Defined in Test.QuickCheck.Function

Function Any Source #
Instance details

Defined in Test.QuickCheck.Function

Function IntSet Source #
Instance details

Defined in Test.QuickCheck.Function

Function OrdC Source #
Instance details

Defined in Test.QuickCheck.Function

Function OrdB Source #
Instance details

Defined in Test.QuickCheck.Function

Function OrdA Source #
Instance details

Defined in Test.QuickCheck.Function

Function C Source #
Instance details

Defined in Test.QuickCheck.Function

Function B Source #
Instance details

Defined in Test.QuickCheck.Function

Function A Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function [a] Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ([a] -> b) -> [a] :-> b Source #

Function a => Function ( Maybe a) Source #
Instance details

Defined in Test.QuickCheck.Function

( Integral a, Function a) => Function ( Ratio a) Source #
Instance details

Defined in Test.QuickCheck.Function

( RealFloat a, Function a) => Function ( Complex a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( Identity a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( First a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( Last a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( Dual a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( Sum a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( Product a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( IntMap a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( Tree a) Source #
Instance details

Defined in Test.QuickCheck.Function

Function a => Function ( Seq a) Source #
Instance details

Defined in Test.QuickCheck.Function

( Ord a, Function a) => Function ( Set a) Source #
Instance details

Defined in Test.QuickCheck.Function

( Function a, Function b) => Function ( Either a b) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ( Either a b -> b0) -> Either a b :-> b0 Source #

( Function a, Function b) => Function (a, b) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ((a, b) -> b0) -> (a, b) :-> b0 Source #

HasResolution a => Function ( Fixed a) Source #
Instance details

Defined in Test.QuickCheck.Function

( Ord a, Function a, Function b) => Function ( Map a b) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ( Map a b -> b0) -> Map a b :-> b0 Source #

( Function a, Function b, Function c) => Function (a, b, c) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ((a, b, c) -> b0) -> (a, b, c) :-> b0 Source #

Function a => Function ( Const a b) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ( Const a b -> b0) -> Const a b :-> b0 Source #

Function (f a) => Function ( Alt f a) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ( Alt f a -> b) -> Alt f a :-> b Source #

( Function a, Function b, Function c, Function d) => Function (a, b, c, d) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ((a, b, c, d) -> b0) -> (a, b, c, d) :-> b0 Source #

( Function a, Function b, Function c, Function d, Function e) => Function (a, b, c, d, e) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ((a, b, c, d, e) -> b0) -> (a, b, c, d, e) :-> b0 Source #

( Function a, Function b, Function c, Function d, Function e, Function f) => Function (a, b, c, d, e, f) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ((a, b, c, d, e, f) -> b0) -> (a, b, c, d, e, f) :-> b0 Source #

( Function a, Function b, Function c, Function d, Function e, Function f, Function g) => Function (a, b, c, d, e, f, g) Source #
Instance details

Defined in Test.QuickCheck.Function

Methods

function :: ((a, b, c, d, e, f, g) -> b0) -> (a, b, c, d, e, f, g) :-> b0 Source #

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

The basic building block for Function instances. Provides a Function instance by mapping to and from a type that already has a Function instance.

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

Provides a Function instance for types with Show and Read .

functionIntegral :: Integral a => (a -> b) -> a :-> b Source #

Provides a Function instance for types with Integral .

functionRealFrac :: RealFrac a => (a -> b) -> a :-> b Source #

Provides a Function instance for types with RealFrac .

functionBoundedEnum :: ( Eq a, Bounded a, Enum a) => (a -> b) -> a :-> b Source #

Provides a Function instance for types with Bounded and Enum . Use only for small types (i.e. not integers): creates the list [ minBound .. maxBound ] !

functionVoid :: ( forall b. void -> b) -> void :-> c Source #

Provides a Function instance for types isomorphic to Void .

An actual Function Void instance is defined in quickcheck-instances .

functionMapWith :: ((b -> c) -> b :-> c) -> (a -> b) -> (b -> a) -> (a -> c) -> a :-> c Source #

Since: 2.13.3

functionEitherWith :: ((a -> c) -> a :-> c) -> ((b -> c) -> b :-> c) -> ( Either a b -> c) -> Either a b :-> c Source #

Since: 2.13.3

functionPairWith :: ((a -> b -> c) -> a :-> (b -> c)) -> ((b -> c) -> b :-> c) -> ((a, b) -> c) -> (a, b) :-> c Source #

Since: 2.13.3

pattern Fn :: (a -> b) -> Fun a b Source #

A modifier for testing functions.

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

pattern Fn2 :: (a -> b -> c) -> Fun (a, b) c Source #

A modifier for testing binary functions.

prop_zipWith :: Fun (Int, Bool) Char -> [Int] -> [Bool] -> Bool
prop_zipWith (Fn2 f) xs ys = zipWith f xs ys == [ f x y | (x, y) <- zip xs ys]

pattern Fn3 :: (a -> b -> c -> d) -> Fun (a, b, c) d Source #

A modifier for testing ternary functions.