QuickCheck-2.9.2: Automatic testing of Haskell programs

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

# Documentation

data Fun a b #

Constructors

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

Instances

 (Show a, Show b) => Show (Fun a b) # MethodsshowsPrec :: 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) # Methodsarbitrary :: 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) # Methodsfmap :: (a -> b) -> (a :-> a) -> a :-> b #(<\$) :: a -> (a :-> b) -> a :-> a # (Show a, Show b) => Show ((:->) a b) # MethodsshowsPrec :: Int -> (a :-> b) -> ShowS #show :: (a :-> b) -> String #showList :: [a :-> b] -> ShowS # (Function a, CoArbitrary a, Arbitrary b) => Arbitrary ((:->) a b) # Methodsarbitrary :: 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

 # Methodsfunction :: (Bool -> b) -> Bool :-> b # # Methodsfunction :: (Char -> b) -> Char :-> b # # Methodsfunction :: (Double -> b) -> Double :-> b # # Methodsfunction :: (Float -> b) -> Float :-> b # # Methodsfunction :: (Int -> b) -> Int :-> b # # Methodsfunction :: (Int8 -> b) -> Int8 :-> b # # Methodsfunction :: (Int16 -> b) -> Int16 :-> b # # Methodsfunction :: (Int32 -> b) -> Int32 :-> b # # Methodsfunction :: (Int64 -> b) -> Int64 :-> b # # Methodsfunction :: (Integer -> b) -> Integer :-> b # # Methodsfunction :: (Ordering -> b) -> Ordering :-> b # # Methodsfunction :: (Word8 -> b) -> Word8 :-> b # # Methodsfunction :: (Word16 -> b) -> Word16 :-> b # # Methodsfunction :: (Word32 -> b) -> Word32 :-> b # # Methodsfunction :: (Word64 -> b) -> Word64 :-> b # Function () # Methodsfunction :: (() -> b) -> () :-> b # # Methodsfunction :: (Natural -> b) -> Natural :-> b # # Methodsfunction :: (IntSet -> b) -> IntSet :-> b # # Methodsfunction :: (OrdC -> b) -> OrdC :-> b # # Methodsfunction :: (OrdB -> b) -> OrdB :-> b # # Methodsfunction :: (OrdA -> b) -> OrdA :-> b # # Methodsfunction :: (C -> b) -> C :-> b # # Methodsfunction :: (B -> b) -> B :-> b # # Methodsfunction :: (A -> b) -> A :-> b # Function a => Function [a] # Methodsfunction :: ([a] -> b) -> [a] :-> b # Function a => Function (Maybe a) # Methodsfunction :: (Maybe a -> b) -> Maybe a :-> b # (Integral a, Function a) => Function (Ratio a) # Methodsfunction :: (Ratio a -> b) -> Ratio a :-> b # Function a => Function (NonEmpty a) # Methodsfunction :: (NonEmpty a -> b) -> NonEmpty a :-> b # HasResolution a => Function (Fixed a) # Methodsfunction :: (Fixed a -> b) -> Fixed a :-> b # (RealFloat a, Function a) => Function (Complex a) # Methodsfunction :: (Complex a -> b) -> Complex a :-> b # Function a => Function (IntMap a) # Methodsfunction :: (IntMap a -> b) -> IntMap a :-> b # Function a => Function (Seq a) # Methodsfunction :: (Seq a -> b) -> Seq a :-> b # (Ord a, Function a) => Function (Set a) # Methodsfunction :: (Set a -> b) -> Set a :-> b # (Function a, Function b) => Function (Either a b) # Methodsfunction :: (Either a b -> b) -> Either a b :-> b # (Function a, Function b) => Function (a, b) # Methodsfunction :: ((a, b) -> b) -> (a, b) :-> b # (Ord a, Function a, Function b) => Function (Map a b) # Methodsfunction :: (Map a b -> b) -> Map a b :-> b # (Function a, Function b, Function c) => Function (a, b, c) # Methodsfunction :: ((a, b, c) -> b) -> (a, b, c) :-> b # (Function a, Function b, Function c, Function d) => Function (a, b, c, d) # Methodsfunction :: ((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) # Methodsfunction :: ((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) # Methodsfunction :: ((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) # Methodsfunction :: ((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. (t1 -> t) -> Fun t1 t #

A pattern for matching against the function only:

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