PropCheck.let_shrink
You're seeing just the macro
let_shrink
, go back to PropCheck module for more information.
A combination of a let
and a shrink
macro.
Instances
are generated by applying a randomly generated list of values inside
generator
(just like a let
, with the added constraint that the
variables and types must be provided in a list - alternatively,
list_of_types
may be a list or vector type). When shrinking instances
of such a type, the sub-instances that were combined to produce it are
first tried in place of the failing instance.
One possible use is shown in the tree
example. A recursive
tree generator with an efficient shrinking: pick each of the
subtrees in place of the tree that fails the property. l
and r
are assigned smaller versions of the tree thus achieving a better
(or more appropriate) shrinking.
iex> use PropCheck
iex> tree_gen = fn (0, _, _) -> :leaf
...> (s, g, tree) ->
...> frequency [
...> {1, tree.(0, g, tree)},
...> {9, let_shrink([
...> l <- tree.(div(s, 2), g, tree),
...> r <- tree.(div(s, 2), g, tree)
...> ]) do
...> {:node, g, l, r}
...> end
...> }
...> ]
...> end
iex> tree = fn(g) -> sized(s, tree_gen.(s, g, tree_gen)) end
iex> quickcheck(
...> forall t <- tree.(int()) do
...> t == :leaf or is_tuple(t)
...> end
...>)
true