| 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 ,
you must have an instance Fun a b.
If your type has a Function aShow 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 instance for an example of the latter.Function [a]
Synopsis
- data Fun a b = Fun (a :-> b, b, Shrunk) (a -> b)
- applyFun :: Fun a b -> a -> b
- apply :: Fun a b -> a -> b
- applyFun2 :: Fun (a, b) c -> a -> b -> c
- applyFun3 :: Fun (a, b, c) d -> a -> b -> c -> d
- 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
- functionElements :: Eq a => [a] -> (a -> b) -> a :-> b
- functionVoid :: (forall b. void -> b) -> void :-> c
- functionMapWith :: ((b -> c) -> b :-> c) -> (a -> b) -> (b -> a) -> (a -> c) -> a :-> c
- functionEitherWith :: ((a -> c) -> a :-> c) -> ((b -> c) -> b :-> c) -> (Either a b -> c) -> Either a b :-> c
- functionPairWith :: ((a -> b -> c) -> a :-> (b -> c)) -> ((b -> c) -> b :-> c) -> ((a, b) -> c) -> (a, b) :-> c
- pattern Fn :: (a -> b) -> Fun a b
- pattern Fn2 :: (a -> b -> c) -> Fun (a, b) c
- pattern Fn3 :: (a -> b -> c -> d) -> Fun (a, b, c) d
Documentation
Generation of random shrinkable, showable functions.
To generate random values of type ,
you must have an instance Fun a b.Function a
Instances
Instances details
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"
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.
The type of possibly partial concrete functions
Instances
Instances details
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
Instances
Instances details
Instance details
Defined in Test.QuickCheck.Function
Methods
function :: (NewlineMode -> b) -> NewlineMode :-> b Source #
Instance details
Defined in Test.QuickCheck.Function
Instance details
Defined in Test.QuickCheck.Function
Instance details
Defined in Test.QuickCheck.Function
Instance details
Defined in Test.QuickCheck.Function
Instance details
Defined in Test.QuickCheck.Function
Instance details
Defined in Test.QuickCheck.Function
Instance details
Defined in Test.QuickCheck.Function
Instance details
Defined in Test.QuickCheck.Function
functionMap :: Function b => (a -> b) -> (b -> a) -> (a -> c) -> a :-> c Source #
functionIntegral :: Integral a => (a -> b) -> a :-> b Source #
functionRealFrac :: RealFrac a => (a -> b) -> a :-> b Source #
functionElements :: Eq a => [a] -> (a -> b) -> a :-> b Source #
Provides a Function instance for small finite types.
functionVoid :: (forall b. void -> b) -> void :-> c Source #
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"