QuickCheck-2.9.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, Bool) (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
- functionIntegral :: Integral a => (a -> b) -> a :-> b
- functionRealFrac :: RealFrac a => (a -> b) -> a :-> b
- functionBoundedEnum :: (Eq a, Bounded a, Enum a) => (a -> b) -> a :-> b
- pattern Fn :: forall t t1. (t -> t1) -> Fun t t1

# Documentation

data Fun a b #

Constructors

Fun (a :-> b, b, Bool) (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 #

Methods

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

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

Instances

Function Bool # |
Methods function :: (Bool -> b) -> Bool :-> b #
Function Char # |
Methods function :: (Char -> b) -> Char :-> b #
Function Double # |
Methods function :: (Double -> b) -> Double :-> b #
Function Float # |
Methods function :: (Float -> b) -> Float :-> b #
Function Int # |
Methods function :: (Int -> b) -> Int :-> b #
Function Int8 # |
Methods function :: (Int8 -> b) -> Int8 :-> b #
Function Int16 # |
Methods function :: (Int16 -> b) -> Int16 :-> b #
Function Int32 # |
Methods function :: (Int32 -> b) -> Int32 :-> b #
Function Int64 # |
Methods function :: (Int64 -> b) -> Int64 :-> b #
Function Integer # |
Methods function :: (Integer -> b) -> Integer :-> b #
Function Ordering # |
Methods function :: (Ordering -> b) -> Ordering :-> b #
Function Word8 # |
Methods function :: (Word8 -> b) -> Word8 :-> b #
Function Word16 # |
Methods function :: (Word16 -> b) -> Word16 :-> b #
Function Word32 # |
Methods function :: (Word32 -> b) -> Word32 :-> b #
Function Word64 # |
Methods function :: (Word64 -> b) -> Word64 :-> b #
Function () # |
Methods function :: (() -> b) -> () :-> b #
Function Natural # |
Methods function :: (Natural -> b) -> Natural :-> b #
Function IntSet # |
Methods function :: (IntSet -> b) -> IntSet :-> 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 #
(Integral a, Function a) => Function (Ratio a) # |
Methods function :: (Ratio a -> b) -> Ratio a :-> b #
Function a => Function (NonEmpty a) # |
Methods function :: (NonEmpty a -> b) -> NonEmpty a :-> b #
HasResolution a => Function (Fixed a) # |
Methods function :: (Fixed a -> b) -> Fixed a :-> b #
(RealFloat a, Function a) => Function (Complex a) # |
Methods function :: (Complex a -> b) -> Complex a :-> b #
Function a => Function (Seq a) # |
Methods function :: (Seq a -> b) -> Seq a :-> b #
Function a => Function (IntMap a) # |
Methods function :: (IntMap a -> b) -> IntMap a :-> b #
(Ord a, Function a) => Function (Set a) # |
Methods function :: (Set a -> b) -> Set 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 #
(Ord a, Function a, Function b) => Function (Map a b) # |
Methods function :: (Map a b -> b) -> Map 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 #

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 #

Provides a `Function` instance for types with `Show` and `Read`.

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

Provides a `Function` instance for types with `Integral`.

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

Provides a `Function` instance for types with `RealFrac`.

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

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

pattern Fn :: forall t t1. (t -> t1) -> Fun t t1 #

A pattern for matching against the function only:

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