Skip to content

std.property - ZZ

Seeded generators + shrinking for property-based tests. Pure ZZ — no engine support needed. Values derive from (seed, index) pairs, so a failing seed replays the exact same cases. check/for_all_int abort with the seed and the shrunk minimal case.

import std.property

std.property lets you write property-based tests: generators produce values from (seed, index) pairs, shrinkers reduce failing cases, and check asserts a property over generated inputs. Because values derive from (seed, index), a failing seed deterministically replays — ideal for CI flake-hunting.

import std.property
func gen_small(seed: int, i: int) -> int {
return property.int_in(seed, i, 0, 10)
}
func small(x: int) -> bool {
return x < 100
}
property.check(gen_small, property.shrink_int, small, 200, 7)
property.for_all_int(0, 10, small, 200, 7)
import std.property
@test
func test_roundtrip() {
gen := |seed: int, i: int| -> str { return property.alpha_str(seed, i, 5) }
prop := |s: str| -> bool { return len(s) == 5 }
property.check(gen, property.shrink_str, prop, 500, 42)
}

14 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
std.property.alpha_char alpha_char(seed: int, i: int) -> str Lowercase letter
std.property.alpha_str alpha_str(seed: int, i: int, len: int) -> str Lowercase string of len chars
std.property.boolean boolean(seed: int, i: int) -> bool Uniform bool
std.property.check check<T>(gen: func(int, int) -> T, shrink: func(T) -> [T], prop: func(T) -> bool, iters: int, seed: int) -> unit Assert prop over generated cases
std.property.for_all_int for_all_int(lo: int, hi: int, prop: func(int) -> bool, iters: int, seed: int) -> unit check for int ranges
std.property.int_in int_in(seed: int, i: int, lo: int, hi: int) -> int Uniform int in [lo,hi] (swaps reversed)
std.property.norm_state norm_state(s: int) -> int —
std.property.pick pick(seed: int, i: int, n: int) -> int Uniform int in [0,n) (0 when n<=0)
std.property.seed seed(n: int) -> int Normalize any int into LCG state
std.property.shrink_int shrink_int(v: int) -> [int] Simpler ints toward zero
std.property.shrink_str shrink_str(s: str) -> [str] Shorter prefixes
std.property.shrink_value shrink_value<T>(prop: func(T) -> bool, shrink: func(T) -> [T], v: T) -> T Minimize a falsifying value
std.property.step step(state: int) -> int —
std.property.stream stream(seed: int, i: int) -> int —
  • std.json — Parse, stringify and read individual values out of JSON.
  • std.map — Pure dictionary helpers over plain maps: lookup, merge and keys.
  • std.set — Arrays with uniqueness: membership, union, intersection and difference.
  • std.dec — Exact decimal arithmetic carried as strings, so money never becomes a float.
  • std.csv — An RFC 4180 subset: read rows, write rows, handle quotes and commas.

Full index: API reference · Standard library