Module
poke/model
src/poke/model.pookaCompare each real step with a small model of what ought to happen. Construct fresh real state for each property trial, using a fixture when it needs cleanup. Commands must be valid for the supplied initial model. Commands describes which steps can follow each model state; commands builds sequences from it and rejects illegal shrink candidates. Real effects run only through check or check_commands, after a complete precondition check.
API reference
check(
commands: List(c),
initial: s,
predict: fn(s, c) -> #(s, r),
perform: fn(c) -> r
) -> s
fn(List(a), b, fn(b, a) -> #(b, c), fn(a) -> c) -> bRun a deterministic command sequence. The first mismatch names its step.
interface Commands(s, c, r)
A pure description of legal commands and replies. Return None from generate when there is no legal next step. Never perform real effects in predict.
initial() -> s
generate(state: s, seed: Int, size: Int) -> Sample(Option(c))
valid(state: s, command: c) -> Bool
predict(state: s, command: c) -> #(s, r)
shrink(command: c) -> List(c)
commands(machine: Commands(s, c, r), maximum: Int) -> Generator(List(c))
fn(poke/model.Commands(a, b, c), Int) -> poke/generator.Generator(List(b))Generate from the evolving model. Shrinks are retained only when the whole smaller sequence remains legal, including commands after a removed step.
property.for_all(model.commands(machine, 30), fn(commands) {
// create fresh real state, then model.check_commands(commands, machine, perform)
})
check_commands(
commands: List(c),
machine: Commands(s, c, r),
perform: fn(c) -> r
) -> s
fn(List(a), poke/model.Commands(b, a, c), fn(a) -> c) -> bValidate a hand-written sequence before allowing it to touch real state.