Module

poke/model

src/poke/model.pooka

Compare 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

function

check

src/poke/model.pooka:17
check(
  commands: List(c),
  initial: s,
  predict: fn(s, c) -> #(s, r),
  perform: fn(c) -> r
) -> s
INFERREDfn(List(a), b, fn(b, a) -> #(b, c), fn(a) -> c) -> b

Run a deterministic command sequence. The first mismatch names its step.

interface

Commands

src/poke/model.pooka:50
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.

method

initial

src/poke/model.pooka:51
initial() -> s
method

generate

src/poke/model.pooka:53
generate(state: s, seed: Int, size: Int) -> Sample(Option(c))
method

valid

src/poke/model.pooka:55
valid(state: s, command: c) -> Bool
method

predict

src/poke/model.pooka:57
predict(state: s, command: c) -> #(s, r)
method

shrink

src/poke/model.pooka:59
shrink(command: c) -> List(c)
function

commands

src/poke/model.pooka:70
commands(machine: Commands(s, c, r), maximum: Int) -> Generator(List(c))
INFERREDfn(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.

Pooka
property.for_all(model.commands(machine, 30), fn(commands) {
  // create fresh real state, then model.check_commands(commands, machine, perform)
})
function

check_commands

src/poke/model.pooka:155
check_commands(
  commands: List(c),
  machine: Commands(s, c, r),
  perform: fn(c) -> r
) -> s
INFERREDfn(List(a), poke/model.Commands(b, a, c), fn(a) -> c) -> b

Validate a hand-written sequence before allowing it to touch real state.