prop_for_all

Check a property over generated values

Draws n values from the gen generator spec (using the shared seeded RNG — call set_seed first for reproducible runs) and evaluates property on each. The property may return a Bool, an Expect value from testcraft (e.g. expect_equal), or an Error. A property passes only when it returns true or Expect_pass; false, Expect_stop, Expect_hold, NA, and Error are all treated as failures. On the first failure, a deterministic shrunk counterexample is reported via an Expect_stop value, so assert(prop_for_all(...)) works inside test files run by t test.

Parameters

Returns

Expect_pass on success, Expect_stop on failure.

Examples

set_seed(42)
assert(prop_for_all(prop_gen_int_range(0, 100), \(x) x >= 0))
assert(prop_for_all(
prop_gen_df([x: prop_gen_float_range(0.0, 100.0)], nrows = 40, na_prob = 0.1),
\(df) nrow(mutate(df, $z = $x * 2)) == nrow(df)))

See Also

set_seed, expect_equal