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
  - function :: (a -> b) -> a :-> 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

# Documentation

data Fun a b #

Constructors

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

Instances

(Show a, Show b) => Show (Fun a b) # |
Instance details Defined in Test.QuickCheck.Function 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) # |
Instance details Defined in Test.QuickCheck.Function 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) # |
Instance details Defined in Test.QuickCheck.Function Methods fmap :: (a0 -> b) -> (a :-> a0) -> a :-> b # (<$) :: a0 -> (a :-> b) -> a :-> a0 #
(Show a, Show b) => Show (a :-> b) # |
Instance details Defined in Test.QuickCheck.Function Methods showsPrec :: Int -> (a :-> b) -> ShowS # show :: (a :-> b) -> String # showList :: [a :-> b] -> ShowS #
(Function a, CoArbitrary a, Arbitrary b) => Arbitrary (a :-> b) # |
Instance details Defined in Test.QuickCheck.Function Methods arbitrary :: Gen (a :-> b) # shrink :: (a :-> b) -> [a :-> b] #

class Function a where #

Methods

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

Instances

Function Bool # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (Bool -> b) -> Bool :-> b #
Function Char # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (Char -> b) -> Char :-> b #
Function Int # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (Int -> b) -> Int :-> b #
Function Integer # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (Integer -> b) -> Integer :-> b #
Function Word8 # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (Word8 -> b) -> Word8 :-> b #
Function () # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (() -> b) -> () :-> b #
Function OrdC # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (OrdC -> b) -> OrdC :-> b #
Function OrdB # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (OrdB -> b) -> OrdB :-> b #
Function OrdA # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (OrdA -> b) -> OrdA :-> b #
Function C # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (C -> b) -> C :-> b #
Function B # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (B -> b) -> B :-> b #
Function A # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (A -> b) -> A :-> b #
Function a => Function [a] # |
Instance details Defined in Test.QuickCheck.Function Methods function :: ([a] -> b) -> [a] :-> b #
Function a => Function (Maybe a) # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (Maybe a -> b) -> Maybe a :-> b #
(Function a, Integral a) => Function (Ratio a) # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (Ratio a -> b) -> Ratio a :-> b #
(Function a, Function b) => Function (Either a b) # |
Instance details Defined in Test.QuickCheck.Function Methods function :: (Either a b -> b0) -> Either a b :-> b0 #
(Function a, Function b) => Function (a, b) # |
Instance details Defined in Test.QuickCheck.Function Methods function :: ((a, b) -> b0) -> (a, b) :-> b0 #
(Function a, Function b, Function c) => Function (a, b, c) # |
Instance details Defined in Test.QuickCheck.Function Methods function :: ((a, b, c) -> b0) -> (a, b, c) :-> b0 #
(Function a, Function b, Function c, Function d) => Function (a, b, c, d) # |
Instance details Defined in Test.QuickCheck.Function Methods function :: ((a, b, c, d) -> b0) -> (a, b, c, d) :-> b0 #
(Function a, Function b, Function c, Function d, Function e) => Function (a, b, c, d, e) # |
Instance details Defined in Test.QuickCheck.Function Methods function :: ((a, b, c, d, e) -> b0) -> (a, b, c, d, e) :-> b0 #
(Function a, Function b, Function c, Function d, Function e, Function f) => Function (a, b, c, d, e, f) # |
Instance details Defined in Test.QuickCheck.Function Methods function :: ((a, b, c, d, e, f) -> b0) -> (a, b, c, d, e, f) :-> b0 #
(Function a, Function b, Function c, Function d, Function e, Function f, Function g) => Function (a, b, c, d, e, f, g) # |
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 #

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"