f package:leancheck

Generic type F. Can be used to test polymorphic functions with five type variables. This type is homomorphic to A, B, C, D, E and Nat6.
Does a property fail for a number of test values?
> fails 1000 $ \xs -> xs ++ ys == ys ++ xs
True
> holds 1000 $ \xs -> length (sort xs) == length xs
False
This is the negation of holds.
filter tiers
filterT p [xs, yz, zs, ...]  =  [filter p xs, filter p ys, filter p zs]
filterT odd tiers  =  [[], [1], [-1], [], [], [3], [-3], [], [], [5], ...]
An error-catching version of fails that returns True in case of errors.
Transforms errors into a default value.
> fromError 0 (15 :: Int)
15
> fromError 0 (undefined :: Int)
0
Converts a function to a list of result values for each Listable argument value.
> list  ::  [Bool]
[False,True]
> funToList not
[True,False]
> list  ::  [(Bool,Bool)]
[(False,False),(False,True),(True,False),(True,True)]
> funToList $ uncurry (&&)
[False,False,False,True]
This function may return an infinite list, use take as required.
> take 10 $ list  ::  [Int]
[0,1,-1,2,-2,3,-3,4,-4,5]
> take 10 $ funToList (+1)  ::  [Int]
[1,2,0,3,-1,4,-2,5,-3,6]
Converts a function to a list of Just result values or Nothing on error.
> take 6 $ funToListEither $ head :: [Either String Int]
[Left "Prelude.head: empty list",Right 0,Right 0,Right 1,Right 0,Right 0]
This uses errorToLeft and consequently unsafePerformIO.
Converts a function to a list of Just result values or Nothing on error.
> take 6 $ funToListMaybe $ head :: [Maybe Int]
[Nothing,Just 0,Just 0,Just 1,Just 0,Just 0]
This uses errorToNothing and consequently unsafePerformIO.
Checks if a list-of-tiers is finite.
  • *Warning:** this is just an approximation, a list-of-tiers is considered finite if it has less than 13 values. This function may give false negatives.
Undefined Float value for use with type binding operators.
This module is part of LeanCheck, a simple enumerative property-based testing library. This module exports Listable and Show function typeclass instances. These can be useful for testing higher-order properties --- properties that take functions as arguments.
> import Test.LeanCheck
> import Test.LeanCheck.Function
> check $ \f p xs -> filter p (map f xs) == map f (filter p xs :: [Int])
*** Failed! Falsifiable (after 36 tests):
\_ -> 0
\x -> case x of
0 -> True
_ -> False
[1]
> check $ \f p xs -> filter p (map f xs) == map f (filter p xs :: [Bool])
*** Failed! Falsifiable (after 20 tests):
\_ -> False
\x -> case x of
False -> False
True -> True
[True]
> check $ \f z xs -> foldr f z xs == foldl f z (xs :: [Int])
*** Failed! Falsifiable (after 75 tests):
\x _ -> case x of
0 -> 1
_ -> 0
0
[0,0]
Warning: this is only intended to be used in testing modules. Avoid importing this on modules that are used as libraries. The Listable and Show function instance are defined in, respectively: The Show instance will work for all functions whose return types are instances of ShowFunction from Test.LeanCheck.Function.ShowFunction.
This module is part of LeanCheck, a simple enumerative property-based testing library. This module exports an orphan Show instance for functions. It shows functions as up to 4 case distinctions in a single line. Please see Test.LeanCheck.Function.Show.EightLines for an alternative that shows functions as up to 8 case distinctions, one per line. The Show -> instance only works for functions of which ultimate return types are instances of the ShowFunction typeclass. Please see Test.LeanCheck.Function.ShowFunction for how to define these instances for your user-defined algebraic datatypes. Warning: this is only intended to be used in testing modules. Avoid importing this on modules that are used as libraries.
Takes as argument tiers of element values; returns tiers of size-ordered lists of elements possibly with repetition.
bagsOf [[0],[1],[2],...] =
[ [[]]
, [[0]]
, [[0,0],[1]]
, [[0,0,0],[0,1],[2]]
, [[0,0,0,0],[0,0,1],[0,2],[1,1],[3]]
, [[0,0,0,0,0],[0,0,0,1],[0,0,2],[0,1,1],[0,3],[1,2],[4]]
, ...
]
Check a property for a given number of tests printing results on stdout
> checkFor 1000 $ \xs -> sort (sort xs) == sort (xs::[Int])
+++ OK, passed 1000 tests.
Test exhaustion is reported when the configured number of tests is larger than the number of available test values:
> checkFor 3 $ \p -> p == not (not p)
+++ OK, passed 2 tests (exhausted).
Check a property for a given number of tests printing results on stdout and returning True on success.
> checkResultFor 1000 $ \xs -> sort (sort xs) == sort (xs::[Int])
+++ OK, passed 1000 tests.
True
There is no option to silence this function: for silence, you should use holds.
Listing of Floating values. This can be used as the implementation of list for Floating types.
listFloating :: [Double]  =
[0.0, 1.0, -1.0, 0.5, -0.5, 2.0, Infinity, -Infinity, -2.0, 0.333, ...]
This follow the same Calkin-Wilf sequence of listFractional but positive and negative infinities are artificially included after two. NaN and -0 are excluded from this enumeration.
Listing of Fractional values. This can be used as the implementation of list for Fractional types.
listFractional :: [[Rational]]  =
[0 % 1, 1 % 1, (-1) % 1, 1 % 2, (-1) % 2, 2 % 1, (-2) % 1, 1 % 3, ...]
All rationals are included without repetition in their most simple form. This is the Calkin-Wilf sequence computed with the help of the fusc function (EWD 570). This also works for unsigned types that wrap around zero, yielding:
listFractional :: [Ratio Word]  =
[0 % 1, 1 % 1, 1 % 2, 2 % 1, 1 % 3, 3 % 2, 2 % 3, 3 % 1, 1 % 4, ...]
Takes as argument tiers of element values; returns tiers of lists of elements.
listsOf [[]]  =  [[[]]]
listsOf [[x]]  =  [ [[]]
, [[x]]
, [[x,x]]
, [[x,x,x]]
, ...
]
listsOf [[x],[y]]  =  [ [[]]
, [[x]]
, [[x,x],[y]]
, [[x,x,x],[x,y],[y,x]]
, ...
]
Takes as argument an integer length and tiers of element values; returns tiers of lists of element values of the given length.
listsOfLength 3 [[0],[1],[2],[3],[4]...] =
[ [[0,0,0]]
, [[0,0,1],[0,1,0],[1,0,0]]
, [[0,0,2],[0,1,1],[0,2,0],[1,0,1],[1,1,0],[2,0,0]]
, ...
]
Takes as argument tiers of element values; returns tiers of lists with no repeated elements.
noDupListsOf [[0],[1],[2],...] ==
[ [[]]
, [[0]]
, [[1]]
, [[0,1],[1,0],[2]]
, [[0,2],[2,0],[3]]
, ...
]
Resets the weight of a constructor or tiers.
> [ [], [], ..., xs, ys, zs, ... ] `ofWeight` 1
[ [], xs, ys, zs, ... ]
> [ xs, ys, zs, ... ] `ofWeight` 2
[ [], [], xs, ys, zs, ... ]
> [ [], xs, ys, zs, ... ] `ofWeight` 3
[ [], [], [], xs, ys, zs, ... ]
Typically used as an infix operator when defining Listable instances:
instance Listable <Type> where
tiers  =  ...
\/ cons<N> <Cons>  `ofWeight`  <W>
\/ ...
Warning: do not apply `ofWeight` 0 to recursive data structure constructors. In general this will make the list of size 0 infinite, breaking the tier invariant (each tier must be finite). `ofWeight` n is equivalent to reset followed by n applications of delay.
Takes as argument tiers of element values; returns tiers of size-ordered lists of elements without repetition.
setsOf [[0],[1],[2],...] =
[ [[]]
, [[0]]
, [[1]]
, [[0,1],[2]]
, [[0,2],[3]]
, [[0,3],[1,2],[4]]
, [[0,1,2],[0,4],[1,3],[5]]
, ...
]
Can be used in the constructor of specialized Listable instances. For Set (from Data.Set), we would have:
instance Listable a => Listable (Set a) where
tiers  =  mapT fromList $ setsOf tiers
Tiers of Floating values. This can be used as the implementation of tiers for Floating types. This function is equivalent to tiersFractional with positive and negative infinities included: 10 and -10. NaN and -0 are excluded from this enumeration. This function is deprecated. Please consider using listFloating instead or use toTiers listFloating.
Tiers of Fractional values. This can be used as the implementation of tiers for Fractional types. This function is deprecated. Please consider using listFractional instead or use toTiers listFractional.
Same as deriveListable but does not warn when the requested instance already exists. The function deriveListable is preferable in most situations.