PropCheck.forall
You're seeing just the macro
forall
, go back to PropCheck module for more information.
A property that should hold for all values generated.
iex> use PropCheck
iex> quickcheck(
...> forall n <- nat() do
...> n >= 0
...> end)
true
If you need more than one generator, collect the generator names and the generators definitions in tuples or lists, respectively:
iex> use PropCheck
iex> quickcheck(
...> forall [n, l] <- [nat(), list(nat())] do
...> n * Enum.sum(l) >= 0
...> end
...>)
true
Similar to let/2
, multiple types can also be combined in a list of bindings:
iex> use PropCheck
iex> quickcheck(
...> forall [n <- nat(), l <- list(nat())] do
...> n * Enum.sum(l) >= 0
...> end
...>)
true
forall
allows using ExUnit
assertions. By default (:quiet
), no output
is generated if an assertion does not hold:
iex> use PropCheck
iex> quickcheck(
...> forall n <- nat() do
...> assert n < 0
...> end
...>)
false
Use :verbose
to enable output on failed ExUnit
assertions.
Setting Verbosity on the Command Line
Apart from setting :verbose
or :quiet
explicitly in the source code,
the PROPCHECK_VERBOSE
environment variable can also be used to set the
verbosity. PROPCHECK_VERBOSE=1
sets :verbose
, while PROPCHECK_VERBOSE=0
sets :quiet
.