ModuleQuickCheck-2.15.0.1Haskell2010
Test.QuickCheck.Function
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.
- 2 types
- 1 class
- 14 values
- PackageQuickCheck-2.15.0.1
- Exports20
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceFunction.hs
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"Alias to applyFun.
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]Extracts the value of a ternary function. Fn3 is the pattern equivalent of this function.
The type of possibly partial concrete functions
Instances3Functor, Show, Arbitrary
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.
Instances53Function, …
Function ADefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction BDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction CDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction OrdADefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction OrdBDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction OrdCDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction IntSetDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction IntegerDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction AllDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction AnyDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction NewlineDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction NewlineModeDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction Int16Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction Int32Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction Int64Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction Int8Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction Word16Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction Word32Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction Word64Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction Word8Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction BoolDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction CharDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction DoubleDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction FloatDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction IntDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction OrderingDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction WordDefined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction ()Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (IntMap a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Seq a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Tree a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Identity a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (First a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Last a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Dual a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Product a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Sum a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Maybe a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function [a]Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(RealFloat a, Function a) => Function (Complex a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Integral a, Function a) => Function (Ratio a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Ord a, Function a) => Function (Set a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionHasResolution a => Function (Fixed a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Function a, Function b) => Function (Either a b)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Function a, Function b) => Function (a, b)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Ord a, Function a, Function b) => Function (Map a b)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction (f a) => Function (Alt f a)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.FunctionFunction a => Function (Const a b)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Function a, Function b, Function c) => Function (a, b, c)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Function a, Function b, Function c, Function d) => Function (a, b, c, d)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Function a, Function b, Function c, Function d, Function e) => Function (a, b, c, d, e)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Function a, Function b, Function c, Function d, Function e, Function f) => Function (a, b, c, d, e, f)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function(Function a, Function b, Function c, Function d, Function e, Function f, Function g) => Function (a, b, c, d, e, f, g)Defined in QuickCheck-2.15.0.1 · Test.QuickCheck.Function
Provides a Function instance for small finite types.
A modifier for testing functions.
prop :: Fun String Integer -> Bool
prop (Fn f) = f "banana" == f "monkey"
|| f "banana" == f "elephant"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]A modifier for testing ternary functions.