This module defines the interface of properties that can be checked with the CurryCheck tool, an automatic property-based test tool based on the EasyCheck library. The ideas behind EasyCheck are described in the FLOPS 2008 paper. CurryCheck automatically tests properties defined with this library. CurryCheck supports the definition of unit tests (also for I/O operations) and property tests parameterized over some arguments. CurryCheck is described in more detail in the LOPSTR 2016 paper.
Basically, this module is a stub clone of the EasyCheck library which contains only the interface of the operations used to specify properties. Hence, this library does not import any other library. This supports the definition of properties in any other module (execept for the prelude).
Exported Functions: #, #<, #>, -=-, <=>, <~, <~>, <~~>, ==>, always, classify, collect, collectAs, deterministic, eventually, failing, for, forAll, is, isAlways, isEventually, label, returns, sameReturns, solutionOf, successful, toError, toIOError, trivial, uniquely, valuesOf, ~>
returns
:: (Eq a, Show a) => IO a -> a -> PropIO
The property returns a x
is satisfied if the execution of the
I/O action a
returns the value x
.
sameReturns
:: (Eq a, Show a) => IO a -> IO a -> PropIO
The property sameReturns a1 a2
is satisfied if the execution of the
I/O actions a1
and a2
return identical values.
The property toError a
is satisfied if the evaluation of the argument
to normal form yields an exception.
The property toIOError a
is satisfied if the execution of the
I/O action a
causes an exception.
(-=-)
:: (Eq a, Show a) => a -> a -> Prop
The property x -=- y
is satisfied if x
and y
have deterministic
values that are equal.
(<~>)
:: (Eq a, Show a) => a -> a -> Prop
The property x <~> y
is satisfied if the sets of the values of
x
and y
are equal.
(~>)
:: (Eq a, Show a) => a -> a -> Prop
The property x ~> y
is satisfied if x
evaluates to every value of y
.
Thus, the set of values of y
must be a subset of the set of values of x
.
(<~)
:: (Eq a, Show a) => a -> a -> Prop
The property x <~ y
is satisfied if y
evaluates to every value of x
.
Thus, the set of values of x
must be a subset of the set of values of y
.
(<~~>)
:: (Eq a, Show a) => a -> a -> Prop
The property x <~~> y
is satisfied if the multisets of the values of
x
and y
are equal.
A conditional property is tested if the condition evaluates to True
.
solutionOf
:: Data a => (a -> Bool) -> a
solutionOf p
returns (non-deterministically) a solution
of predicate p
. This operation is useful to test solutions
of predicates.
is
:: Show a => a -> (a -> Bool) -> Prop
The property is x p
is satisfied if x
has a deterministic value
which satisfies p
.
isAlways
:: Show a => a -> (a -> Bool) -> Prop
The property isAlways x p
is satisfied if all values of x
satisfy p
.
isEventually
:: Show a => a -> (a -> Bool) -> Prop
The property isEventually x p
is satisfied if some value of x
satisfies p
.
The property uniquely x
is satisfied if x
has a deterministic value
which is true.
The property always x
is satisfied if all values of x
are true.
eventually
:: Bool -> Prop
The property eventually x
is satisfied if some value of x
is true.
failing
:: Show a => a -> Prop
The property failing x
is satisfied if x
has no value.
successful
:: Show a => a -> Prop
The property successful x
is satisfied if x
has at least one value.
deterministic
:: Show a => a -> Prop
The property deterministic x
is satisfied if x
has exactly one value.
(#)
:: (Eq a, Show a) => a -> Int -> Prop
The property x # n
is satisfied if x
has n
values.
(#<)
:: (Eq a, Show a) => a -> Int -> Prop
The property x #< n
is satisfied if x
has less than n
values.
(#>)
:: (Eq a, Show a) => a -> Int -> Prop
The property x #> n
is satisfied if x
has more than n
values.
for
:: Show a => a -> (a -> Prop) -> Prop
The property for x p
is satisfied if all values y
of x
satisfy property p y
.
forAll
:: Show a => [a] -> (a -> Prop) -> Prop
The property forAll xs p
is satisfied if all values x
of the list xs
satisfy property p x
.
The property f <=> g
is satisfied if f
and g
are equivalent
operations, i.e., they can be replaced in any context without changing
the computed results.
label
:: String -> Prop -> Prop
Assign a label to a property. All labeled tests are counted and shown at the end.
classify
:: Bool -> String -> Prop -> Prop
Assign a label to a property if the first argument is True
.
All labeled tests are counted and shown at the end.
Hence, this combinator can be used to classify tests:
multIsComm x y = classify (x<0 || y<0) "Negative" $ x*y -=- y*x
trivial
:: Bool -> Prop -> Prop
Assign the label "trivial" to a property if the first argument is True
.
All labeled tests are counted and shown at the end.
collect
:: Show a => a -> Prop -> Prop
Assign a label showing the given argument to a property. All labeled tests are counted and shown at the end.
collectAs
:: Show a => String -> a -> Prop -> Prop
Assign a label showing a given name and the given argument to a property. All labeled tests are counted and shown at the end.
valuesOf
:: a -> [a]
Computes the list of all values of the given argument according to a given strategy (here: randomized diagonalization of levels with flattening).