Module
poke/property
src/poke/property.pookaAsk the same question of many small worlds.
Checks use an explicit seed and bounded shrinking. A counterexample carries the original value, the smaller failure and the exact seed/size for replay. Properties should be pure: shrinking repeats the callback. Exceptions are failures too, but callbacks have no automatic timeout.
API reference
class Config(seed: Int, cases: Int, max_size: Int, max_shrinks: Int)
cases must be positive; sizes and shrink budgets must be nonnegative.
seed: Int
Intcases: Int
Intmax_size: Int
Intmax_shrinks: Int
Int
fn(Int, Int, Int, Int) -> poke/property.Configclass Report(seed: Int, cases: Int)
seed: Int
Intcases: Int
Int
fn(Int, Int) -> poke/property.Reportclass Failure(
seed: Int,
trial: Int,
case_seed: Int,
size: Int,
original: a,
minimal: a,
reason: String,
shrinks: Int
)
seed: Int
Inttrial: Int
Intcase_seed: Int
Intsize: Int
Intoriginal: a
aminimal: a
areason: String
Stringshrinks: Int
Int
fn(Int, Int, Int, Int, a, a, String, Int) -> poke/property.Failure(a)defaults() -> Config
fn() -> poke/property.ConfigA repeatable default, rather than a fresh mystery on every run.
check(source: Generator(a), predicate: fn(a) -> Bool, config: Config) -> Result(
Report,
Failure(a)
)
fn(poke/generator.Generator(a), fn(a) -> Bool, poke/property.Config) -> Result(poke/property.Report, poke/property.Failure(a))Check a Boolean predicate, returning a replayable failure instead of raising.
property.check(generator.integers(-20, 20), fn(n) { n + 0 == n }, property.defaults())
for_all(source: Generator(a), assertion: fn(a) -> Nil) -> Nil
fn(poke/generator.Generator(a), fn(a) -> Nil) -> NilRun assertion-style properties with the default seed and bounds.
property.for_all(generator.integers(-100, 100), fn(n) {
should.equal(n + 0, n)
})
for_all_with(source: Generator(a), assertion: fn(a) -> Nil, config: Config) -> Nil
fn(poke/generator.Generator(a), fn(a) -> Nil, poke/property.Config) -> NilChoose a seed and bounds explicitly. The failure message includes replay data.
replay(source: Generator(a), case_seed: Int, size: Int) -> a
fn(poke/generator.Generator(a), Int, Int) -> aReplay just one failing sample using Failure.case_seed and Failure.size.
describe(problem: Failure(a)) -> String
fn(poke/property.Failure(a)) -> StringShow a counterexample without hiding the seed behind a stack trace.