Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Test.QuickCheck.Modifiers
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.
Note : the contents of this module are re-exported by Test.QuickCheck . You do not need to import it directly.
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 offorAll
orderedList
prop_Sort (Ordered
(xs :: [OrdA
])) = sort xs == xs
Synopsis
-
newtype
Blind
a =
Blind
{
- getBlind :: a
-
newtype
Fixed
a =
Fixed
{
- getFixed :: a
-
newtype
OrderedList
a =
Ordered
{
- getOrdered :: [a]
-
newtype
NonEmptyList
a =
NonEmpty
{
- getNonEmpty :: [a]
-
data
InfiniteList
a =
InfiniteList
{
- getInfiniteList :: [a]
- infiniteListInternalData :: InfiniteListInternalData a
-
newtype
SortedList
a =
Sorted
{
- getSorted :: [a]
-
newtype
Positive
a =
Positive
{
- getPositive :: a
-
newtype
Negative
a =
Negative
{
- getNegative :: a
-
newtype
NonZero
a =
NonZero
{
- getNonZero :: a
-
newtype
NonNegative
a =
NonNegative
{
- getNonNegative :: a
-
newtype
NonPositive
a =
NonPositive
{
- getNonPositive :: a
-
newtype
Large
a =
Large
{
- getLarge :: a
-
newtype
Small
a =
Small
{
- getSmall :: a
- data Smart a = Smart Int a
-
newtype
Shrink2
a =
Shrink2
{
- getShrink2 :: a
- data Shrinking s a = Shrinking s a
-
class
ShrinkState
s a
where
- shrinkInit :: a -> s
- shrinkState :: a -> s -> [(a, s)]
- newtype ASCIIString = ASCIIString { }
- newtype UnicodeString = UnicodeString { }
- newtype PrintableString = PrintableString { }
Type-level modifiers for changing generator behavior
Blind x
: as x, but x does not have to be in the
Show
class.
Instances
Fixed x
: as x, but will not be shrunk.
Instances
newtype OrderedList a Source #
Ordered xs
: guarantees that xs is ordered.
Constructors
Ordered | |
Fields
|
Instances
newtype NonEmptyList a Source #
NonEmpty xs
: guarantees that xs is non-empty.
Constructors
NonEmpty | |
Fields
|
Instances
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! Falsified (after 1 test and 14 shrinks): "bbbbbbbbbb" ++ ...
Constructors
InfiniteList | |
Fields
|
Instances
Show a => Show ( InfiniteList a) Source # | |
Defined in Test.QuickCheck.Modifiers |
|
Arbitrary a => Arbitrary ( InfiniteList a) Source # | |
Defined in Test.QuickCheck.Modifiers Methods arbitrary :: Gen ( InfiniteList a) Source # shrink :: InfiniteList a -> [ InfiniteList a] Source # |
newtype SortedList a Source #
Sorted xs
: guarantees that xs is sorted.
Instances
Positive x
: guarantees that
x > 0
.
Constructors
Positive | |
Fields
|
Instances
Negative x
: guarantees that
x < 0
.
Constructors
Negative | |
Fields
|
Instances
NonZero x
: guarantees that
x /= 0
.
Constructors
NonZero | |
Fields
|
Instances
newtype NonNegative a Source #
NonNegative x
: guarantees that
x >= 0
.
Constructors
NonNegative | |
Fields
|
Instances
newtype NonPositive a Source #
NonPositive x
: guarantees that
x <= 0
.
Constructors
NonPositive | |
Fields
|
Instances
Large x
: by default, QuickCheck generates
Int
s drawn from a small
range.
Large Int
gives you values drawn from the entire range instead.
Instances
Small x
: generates values of
x
drawn from a small range.
The opposite of
Large
.
Instances
Smart _ x
: tries a different order when shrinking.
Shrink2 x
: allows 2 shrinking steps at the same time when shrinking x
Constructors
Shrink2 | |
Fields
|
Instances
Shrinking _ x
: allows for maintaining a state during shrinking.
Constructors
Shrinking s a |
class ShrinkState s a where Source #
newtype ASCIIString Source #
ASCIIString
: generates an ASCII string.
Constructors
ASCIIString | |
Fields |
Instances
newtype UnicodeString Source #
UnicodeString
: generates a unicode String.
The string will not contain surrogate pairs.
Constructors
UnicodeString | |
Fields |
Instances
newtype PrintableString Source #
PrintableString
: generates a printable unicode String.
The string will not contain surrogate pairs.
Constructors
PrintableString | |
Fields |