qcheck/qtest
This module provides functions for running property-based tests.
Example
Here is a basic example to get you started. It assumes you are using gleeunit to run the tests.
import gleeunit/should
import qcheck/generator
import qcheck/qtest
import qcheck/qtest/config as qtest_config
pub fn small_positive_or_zero_int__test() {
qtest.run(
config: qtest_config.default(),
generator: generator.small_positive_or_zero_int(),
property: fn(n) { n + 1 == 1 + n },
)
|> should.equal(Ok(Nil))
}
pub fn small_positive_or_zero_int__failures_shrink_to_zero__test() {
qtest.run(
config: qtest_config.default(),
generator: generator.small_positive_or_zero_int(),
property: fn(n) { n + 1 != 1 + n },
)
|> should.equal(Error(0))
}
Functions
pub fn run(
config config: Config,
generator generator: Generator(a),
property property: fn(a) -> Bool,
) -> Result(Nil, a)
run(config, generator, property)
runs the property
function against some
test cases generated by the generator
function according to the specified
config
The run
function returns Ok(Nil)
if the property holds (i.e., return
True
for all test cases), and returns Error(a)
if the property does not
hold for some test case a
. The value returned in the Error case will be a
shrunk value if possible.
pub fn run_result(
config config: Config,
generator generator: Generator(a),
property property: fn(a) -> Result(b, c),
) -> Result(Nil, a)
run_result(config, generator, property)
is like run
but the property
function returns a Result
instead of a Bool
.
The run_result
function returns Ok(Nil)
if the property holds (i.e.,
returns Ok
for all test cases), and returns Error(a)
if the property
does not hold for some test case a
. The value returned in the Error case
will be a shrunk value if possible.