QuickCheck-2.11.1: Automatic testing of Haskell programs

Safe HaskellTrustworthy
LanguageHaskell98

Test.QuickCheck.Modifiers

Contents

Description

Modifiers for test data.

These types do things such as restricting the kind of test data that can be generated. They can be pattern-matched on in properties as a stylistic alternative to using explicit quantification.

Examples:

-- Functions cannot be shown (but see Test.QuickCheck.Function)
prop_TakeDropWhile (Blind p) (xs :: [A]) =
  takeWhile p xs ++ dropWhile p xs == xs
prop_TakeDrop (NonNegative n) (xs :: [A]) =
  take n xs ++ drop n xs == xs
-- cycle does not work for empty lists
prop_Cycle (NonNegative n) (NonEmpty (xs :: [A])) =
  take n (cycle xs) == take n (xs ++ cycle xs)
-- Instead of forAll orderedList
prop_Sort (Ordered (xs :: [OrdA])) =
  sort xs == xs

Synopsis

Type-level modifiers for changing generator behavior

newtype Blind a Source #

Blind x: as x, but x does not have to be in the Show class.

Constructors

Blind 

Fields

Instances

Functor Blind Source # 

Methods

fmap :: (a -> b) -> Blind a -> Blind b #

(<$) :: a -> Blind b -> Blind a #

Enum a => Enum (Blind a) Source # 

Methods

succ :: Blind a -> Blind a #

pred :: Blind a -> Blind a #

toEnum :: Int -> Blind a #

fromEnum :: Blind a -> Int #

enumFrom :: Blind a -> [Blind a] #

enumFromThen :: Blind a -> Blind a -> [Blind a] #

enumFromTo :: Blind a -> Blind a -> [Blind a] #

enumFromThenTo :: Blind a -> Blind a -> Blind a -> [Blind a] #

Eq a => Eq (Blind a) Source # 

Methods

(==) :: Blind a -> Blind a -> Bool #

(/=) :: Blind a -> Blind a -> Bool #

Integral a => Integral (Blind a) Source # 

Methods

quot :: Blind a -> Blind a -> Blind a #

rem :: Blind a -> Blind a -> Blind a #

div :: Blind a -> Blind a -> Blind a #

mod :: Blind a -> Blind a -> Blind a #

quotRem :: Blind a -> Blind a -> (Blind a, Blind a) #

divMod :: Blind a -> Blind a -> (Blind a, Blind a) #

toInteger :: Blind a -> Integer #

Num a => Num (Blind a) Source # 

Methods

(+) :: Blind a -> Blind a -> Blind a #

(-) :: Blind a -> Blind a -> Blind a #

(*) :: Blind a -> Blind a -> Blind a #

negate :: Blind a -> Blind a #

abs :: Blind a -> Blind a #

signum :: Blind a -> Blind a #

fromInteger :: Integer -> Blind a #

Ord a => Ord (Blind a) Source # 

Methods

compare :: Blind a -> Blind a -> Ordering #

(<) :: Blind a -> Blind a -> Bool #

(<=) :: Blind a -> Blind a -> Bool #

(>) :: Blind a -> Blind a -> Bool #

(>=) :: Blind a -> Blind a -> Bool #

max :: Blind a -> Blind a -> Blind a #

min :: Blind a -> Blind a -> Blind a #

Real a => Real (Blind a) Source # 

Methods

toRational :: Blind a -> Rational #

Show (Blind a) Source # 

Methods

showsPrec :: Int -> Blind a -> ShowS #

show :: Blind a -> String #

showList :: [Blind a] -> ShowS #

Arbitrary a => Arbitrary (Blind a) Source # 

Methods

arbitrary :: Gen (Blind a) Source #

shrink :: Blind a -> [Blind a] Source #

newtype Fixed a Source #

Fixed x: as x, but will not be shrunk.

Constructors

Fixed 

Fields

Instances

Functor Fixed Source # 

Methods

fmap :: (a -> b) -> Fixed a -> Fixed b #

(<$) :: a -> Fixed b -> Fixed a #

Enum a => Enum (Fixed a) Source # 

Methods

succ :: Fixed a -> Fixed a #

pred :: Fixed a -> Fixed a #

toEnum :: Int -> Fixed a #

fromEnum :: Fixed a -> Int #

enumFrom :: Fixed a -> [Fixed a] #

enumFromThen :: Fixed a -> Fixed a -> [Fixed a] #

enumFromTo :: Fixed a -> Fixed a -> [Fixed a] #

enumFromThenTo :: Fixed a -> Fixed a -> Fixed a -> [Fixed a] #

Eq a => Eq (Fixed a) Source # 

Methods

(==) :: Fixed a -> Fixed a -> Bool #

(/=) :: Fixed a -> Fixed a -> Bool #

Integral a => Integral (Fixed a) Source # 

Methods

quot :: Fixed a -> Fixed a -> Fixed a #

rem :: Fixed a -> Fixed a -> Fixed a #

div :: Fixed a -> Fixed a -> Fixed a #

mod :: Fixed a -> Fixed a -> Fixed a #

quotRem :: Fixed a -> Fixed a -> (Fixed a, Fixed a) #

divMod :: Fixed a -> Fixed a -> (Fixed a, Fixed a) #

toInteger :: Fixed a -> Integer #

Num a => Num (Fixed a) Source # 

Methods

(+) :: Fixed a -> Fixed a -> Fixed a #

(-) :: Fixed a -> Fixed a -> Fixed a #

(*) :: Fixed a -> Fixed a -> Fixed a #

negate :: Fixed a -> Fixed a #

abs :: Fixed a -> Fixed a #

signum :: Fixed a -> Fixed a #

fromInteger :: Integer -> Fixed a #

Ord a => Ord (Fixed a) Source # 

Methods

compare :: Fixed a -> Fixed a -> Ordering #

(<) :: Fixed a -> Fixed a -> Bool #

(<=) :: Fixed a -> Fixed a -> Bool #

(>) :: Fixed a -> Fixed a -> Bool #

(>=) :: Fixed a -> Fixed a -> Bool #

max :: Fixed a -> Fixed a -> Fixed a #

min :: Fixed a -> Fixed a -> Fixed a #

Read a => Read (Fixed a) Source # 
Real a => Real (Fixed a) Source # 

Methods

toRational :: Fixed a -> Rational #

Show a => Show (Fixed a) Source # 

Methods

showsPrec :: Int -> Fixed a -> ShowS #

show :: Fixed a -> String #

showList :: [Fixed a] -> ShowS #

Arbitrary a => Arbitrary (Fixed a) Source # 

Methods

arbitrary :: Gen (Fixed a) Source #

shrink :: Fixed a -> [Fixed a] Source #

newtype OrderedList a Source #

Ordered xs: guarantees that xs is ordered.

Constructors

Ordered 

Fields

data InfiniteList a Source #

InfiniteList xs _: guarantees that xs is an infinite list. When a counterexample is found, only prints the prefix of xs that was used by the program.

Here is a contrived example property:

prop_take_10 :: InfiniteList Char -> Bool
prop_take_10 (InfiniteList xs _) =
  or [ x == 'a' | x <- take 10 xs ]

In the following counterexample, the list must start with "bbbbbbbbbb" but the remaining (infinite) part can contain anything:

>>> quickCheck prop_take_10
*** Failed! Falsifiable (after 1 test and 14 shrinks):
"bbbbbbbbbb" ++ ...

Constructors

InfiniteList 

Fields

newtype Positive a Source #

Positive x: guarantees that x > 0.

Constructors

Positive 

Fields

Instances

Functor Positive Source # 

Methods

fmap :: (a -> b) -> Positive a -> Positive b #

(<$) :: a -> Positive b -> Positive a #

Enum a => Enum (Positive a) Source # 
Eq a => Eq (Positive a) Source # 

Methods

(==) :: Positive a -> Positive a -> Bool #

(/=) :: Positive a -> Positive a -> Bool #

Ord a => Ord (Positive a) Source # 

Methods

compare :: Positive a -> Positive a -> Ordering #

(<) :: Positive a -> Positive a -> Bool #

(<=) :: Positive a -> Positive a -> Bool #

(>) :: Positive a -> Positive a -> Bool #

(>=) :: Positive a -> Positive a -> Bool #

max :: Positive a -> Positive a -> Positive a #

min :: Positive a -> Positive a -> Positive a #

Read a => Read (Positive a) Source # 
Show a => Show (Positive a) Source # 

Methods

showsPrec :: Int -> Positive a -> ShowS #

show :: Positive a -> String #

showList :: [Positive a] -> ShowS #

(Num a, Ord a, Arbitrary a) => Arbitrary (Positive a) Source # 

newtype NonZero a Source #

NonZero x: guarantees that x /= 0.

Constructors

NonZero 

Fields

Instances

Functor NonZero Source # 

Methods

fmap :: (a -> b) -> NonZero a -> NonZero b #

(<$) :: a -> NonZero b -> NonZero a #

Enum a => Enum (NonZero a) Source # 

Methods

succ :: NonZero a -> NonZero a #

pred :: NonZero a -> NonZero a #

toEnum :: Int -> NonZero a #

fromEnum :: NonZero a -> Int #

enumFrom :: NonZero a -> [NonZero a] #

enumFromThen :: NonZero a -> NonZero a -> [NonZero a] #

enumFromTo :: NonZero a -> NonZero a -> [NonZero a] #

enumFromThenTo :: NonZero a -> NonZero a -> NonZero a -> [NonZero a] #

Eq a => Eq (NonZero a) Source # 

Methods

(==) :: NonZero a -> NonZero a -> Bool #

(/=) :: NonZero a -> NonZero a -> Bool #

Ord a => Ord (NonZero a) Source # 

Methods

compare :: NonZero a -> NonZero a -> Ordering #

(<) :: NonZero a -> NonZero a -> Bool #

(<=) :: NonZero a -> NonZero a -> Bool #

(>) :: NonZero a -> NonZero a -> Bool #

(>=) :: NonZero a -> NonZero a -> Bool #

max :: NonZero a -> NonZero a -> NonZero a #

min :: NonZero a -> NonZero a -> NonZero a #

Read a => Read (NonZero a) Source # 
Show a => Show (NonZero a) Source # 

Methods

showsPrec :: Int -> NonZero a -> ShowS #

show :: NonZero a -> String #

showList :: [NonZero a] -> ShowS #

(Num a, Eq a, Arbitrary a) => Arbitrary (NonZero a) Source # 

newtype NonNegative a Source #

NonNegative x: guarantees that x >= 0.

Constructors

NonNegative 

Fields

Instances

Functor NonNegative Source # 

Methods

fmap :: (a -> b) -> NonNegative a -> NonNegative b #

(<$) :: a -> NonNegative b -> NonNegative a #

Enum a => Enum (NonNegative a) Source # 
Eq a => Eq (NonNegative a) Source # 
Ord a => Ord (NonNegative a) Source # 
Read a => Read (NonNegative a) Source # 
Show a => Show (NonNegative a) Source # 
(Num a, Ord a, Arbitrary a) => Arbitrary (NonNegative a) Source # 

newtype Large a Source #

Large x: by default, QuickCheck generates Ints drawn from a small range. Large Int gives you values drawn from the entire range instead.

Constructors

Large 

Fields

Instances

Functor Large Source # 

Methods

fmap :: (a -> b) -> Large a -> Large b #

(<$) :: a -> Large b -> Large a #

Enum a => Enum (Large a) Source # 

Methods

succ :: Large a -> Large a #

pred :: Large a -> Large a #

toEnum :: Int -> Large a #

fromEnum :: Large a -> Int #

enumFrom :: Large a -> [Large a] #

enumFromThen :: Large a -> Large a -> [Large a] #

enumFromTo :: Large a -> Large a -> [Large a] #

enumFromThenTo :: Large a -> Large a -> Large a -> [Large a] #

Eq a => Eq (Large a) Source # 

Methods

(==) :: Large a -> Large a -> Bool #

(/=) :: Large a -> Large a -> Bool #

Integral a => Integral (Large a) Source # 

Methods

quot :: Large a -> Large a -> Large a #

rem :: Large a -> Large a -> Large a #

div :: Large a -> Large a -> Large a #

mod :: Large a -> Large a -> Large a #

quotRem :: Large a -> Large a -> (Large a, Large a) #

divMod :: Large a -> Large a -> (Large a, Large a) #

toInteger :: Large a -> Integer #

Num a => Num (Large a) Source # 

Methods

(+) :: Large a -> Large a -> Large a #

(-) :: Large a -> Large a -> Large a #

(*) :: Large a -> Large a -> Large a #

negate :: Large a -> Large a #

abs :: Large a -> Large a #

signum :: Large a -> Large a #

fromInteger :: Integer -> Large a #

Ord a => Ord (Large a) Source # 

Methods

compare :: Large a -> Large a -> Ordering #

(<) :: Large a -> Large a -> Bool #

(<=) :: Large a -> Large a -> Bool #

(>) :: Large a -> Large a -> Bool #

(>=) :: Large a -> Large a -> Bool #

max :: Large a -> Large a -> Large a #

min :: Large a -> Large a -> Large a #

Read a => Read (Large a) Source # 
Real a => Real (Large a) Source # 

Methods

toRational :: Large a -> Rational #

Show a => Show (Large a) Source # 

Methods

showsPrec :: Int -> Large a -> ShowS #

show :: Large a -> String #

showList :: [Large a] -> ShowS #

Ix a => Ix (Large a) Source # 

Methods

range :: (Large a, Large a) -> [Large a] #

index :: (Large a, Large a) -> Large a -> Int #

unsafeIndex :: (Large a, Large a) -> Large a -> Int

inRange :: (Large a, Large a) -> Large a -> Bool #

rangeSize :: (Large a, Large a) -> Int #

unsafeRangeSize :: (Large a, Large a) -> Int

(Integral a, Bounded a) => Arbitrary (Large a) Source # 

Methods

arbitrary :: Gen (Large a) Source #

shrink :: Large a -> [Large a] Source #

newtype Small a Source #

Small x: generates values of x drawn from a small range. The opposite of Large.

Constructors

Small 

Fields

Instances

Functor Small Source # 

Methods

fmap :: (a -> b) -> Small a -> Small b #

(<$) :: a -> Small b -> Small a #

Enum a => Enum (Small a) Source # 

Methods

succ :: Small a -> Small a #

pred :: Small a -> Small a #

toEnum :: Int -> Small a #

fromEnum :: Small a -> Int #

enumFrom :: Small a -> [Small a] #

enumFromThen :: Small a -> Small a -> [Small a] #

enumFromTo :: Small a -> Small a -> [Small a] #

enumFromThenTo :: Small a -> Small a -> Small a -> [Small a] #

Eq a => Eq (Small a) Source # 

Methods

(==) :: Small a -> Small a -> Bool #

(/=) :: Small a -> Small a -> Bool #

Integral a => Integral (Small a) Source # 

Methods

quot :: Small a -> Small a -> Small a #

rem :: Small a -> Small a -> Small a #

div :: Small a -> Small a -> Small a #

mod :: Small a -> Small a -> Small a #

quotRem :: Small a -> Small a -> (Small a, Small a) #

divMod :: Small a -> Small a -> (Small a, Small a) #

toInteger :: Small a -> Integer #

Num a => Num (Small a) Source # 

Methods

(+) :: Small a -> Small a -> Small a #

(-) :: Small a -> Small a -> Small a #

(*) :: Small a -> Small a -> Small a #

negate :: Small a -> Small a #

abs :: Small a -> Small a #

signum :: Small a -> Small a #

fromInteger :: Integer -> Small a #

Ord a => Ord (Small a) Source # 

Methods

compare :: Small a -> Small a -> Ordering #

(<) :: Small a -> Small a -> Bool #

(<=) :: Small a -> Small a -> Bool #

(>) :: Small a -> Small a -> Bool #

(>=) :: Small a -> Small a -> Bool #

max :: Small a -> Small a -> Small a #

min :: Small a -> Small a -> Small a #

Read a => Read (Small a) Source # 
Real a => Real (Small a) Source # 

Methods

toRational :: Small a -> Rational #

Show a => Show (Small a) Source # 

Methods

showsPrec :: Int -> Small a -> ShowS #

show :: Small a -> String #

showList :: [Small a] -> ShowS #

Ix a => Ix (Small a) Source # 

Methods

range :: (Small a, Small a) -> [Small a] #

index :: (Small a, Small a) -> Small a -> Int #

unsafeIndex :: (Small a, Small a) -> Small a -> Int

inRange :: (Small a, Small a) -> Small a -> Bool #

rangeSize :: (Small a, Small a) -> Int #

unsafeRangeSize :: (Small a, Small a) -> Int

Integral a => Arbitrary (Small a) Source # 

Methods

arbitrary :: Gen (Small a) Source #

shrink :: Small a -> [Small a] Source #

data Smart a Source #

Smart _ x: tries a different order when shrinking.

Constructors

Smart Int a 

Instances

Functor Smart Source # 

Methods

fmap :: (a -> b) -> Smart a -> Smart b #

(<$) :: a -> Smart b -> Smart a #

Show a => Show (Smart a) Source # 

Methods

showsPrec :: Int -> Smart a -> ShowS #

show :: Smart a -> String #

showList :: [Smart a] -> ShowS #

Arbitrary a => Arbitrary (Smart a) Source # 

Methods

arbitrary :: Gen (Smart a) Source #

shrink :: Smart a -> [Smart a] Source #

newtype Shrink2 a Source #

Shrink2 x: allows 2 shrinking steps at the same time when shrinking x

Constructors

Shrink2 

Fields

Instances

Functor Shrink2 Source # 

Methods

fmap :: (a -> b) -> Shrink2 a -> Shrink2 b #

(<$) :: a -> Shrink2 b -> Shrink2 a #

Enum a => Enum (Shrink2 a) Source # 

Methods

succ :: Shrink2 a -> Shrink2 a #

pred :: Shrink2 a -> Shrink2 a #

toEnum :: Int -> Shrink2 a #

fromEnum :: Shrink2 a -> Int #

enumFrom :: Shrink2 a -> [Shrink2 a] #

enumFromThen :: Shrink2 a -> Shrink2 a -> [Shrink2 a] #

enumFromTo :: Shrink2 a -> Shrink2 a -> [Shrink2 a] #

enumFromThenTo :: Shrink2 a -> Shrink2 a -> Shrink2 a -> [Shrink2 a] #

Eq a => Eq (Shrink2 a) Source # 

Methods

(==) :: Shrink2 a -> Shrink2 a -> Bool #

(/=) :: Shrink2 a -> Shrink2 a -> Bool #

Integral a => Integral (Shrink2 a) Source # 

Methods

quot :: Shrink2 a -> Shrink2 a -> Shrink2 a #

rem :: Shrink2 a -> Shrink2 a -> Shrink2 a #

div :: Shrink2 a -> Shrink2 a -> Shrink2 a #

mod :: Shrink2 a -> Shrink2 a -> Shrink2 a #

quotRem :: Shrink2 a -> Shrink2 a -> (Shrink2 a, Shrink2 a) #

divMod :: Shrink2 a -> Shrink2 a -> (Shrink2 a, Shrink2 a) #

toInteger :: Shrink2 a -> Integer #

Num a => Num (Shrink2 a) Source # 

Methods

(+) :: Shrink2 a -> Shrink2 a -> Shrink2 a #

(-) :: Shrink2 a -> Shrink2 a -> Shrink2 a #

(*) :: Shrink2 a -> Shrink2 a -> Shrink2 a #

negate :: Shrink2 a -> Shrink2 a #

abs :: Shrink2 a -> Shrink2 a #

signum :: Shrink2 a -> Shrink2 a #

fromInteger :: Integer -> Shrink2 a #

Ord a => Ord (Shrink2 a) Source # 

Methods

compare :: Shrink2 a -> Shrink2 a -> Ordering #

(<) :: Shrink2 a -> Shrink2 a -> Bool #

(<=) :: Shrink2 a -> Shrink2 a -> Bool #

(>) :: Shrink2 a -> Shrink2 a -> Bool #

(>=) :: Shrink2 a -> Shrink2 a -> Bool #

max :: Shrink2 a -> Shrink2 a -> Shrink2 a #

min :: Shrink2 a -> Shrink2 a -> Shrink2 a #

Read a => Read (Shrink2 a) Source # 
Real a => Real (Shrink2 a) Source # 

Methods

toRational :: Shrink2 a -> Rational #

Show a => Show (Shrink2 a) Source # 

Methods

showsPrec :: Int -> Shrink2 a -> ShowS #

show :: Shrink2 a -> String #

showList :: [Shrink2 a] -> ShowS #

Arbitrary a => Arbitrary (Shrink2 a) Source # 

data Shrinking s a Source #

Shrinking _ x: allows for maintaining a state during shrinking.

Constructors

Shrinking s a 

Instances

Functor (Shrinking s) Source # 

Methods

fmap :: (a -> b) -> Shrinking s a -> Shrinking s b #

(<$) :: a -> Shrinking s b -> Shrinking s a #

Show a => Show (Shrinking s a) Source # 

Methods

showsPrec :: Int -> Shrinking s a -> ShowS #

show :: Shrinking s a -> String #

showList :: [Shrinking s a] -> ShowS #

(Arbitrary a, ShrinkState s a) => Arbitrary (Shrinking s a) Source # 

Methods

arbitrary :: Gen (Shrinking s a) Source #

shrink :: Shrinking s a -> [Shrinking s a] Source #

class ShrinkState s a where Source #

Minimal complete definition

shrinkInit, shrinkState

Methods

shrinkInit :: a -> s Source #

shrinkState :: a -> s -> [(a, s)] Source #