proptest.nx
buildroot/runtime/proptest.nx
about
proptest.nx -- property-based testing.
EFFICIENCY_ROADMAP ยง5.1. Runtime: sample N random inputs,
run a property on each, shrink failing input to minimal
example. Quickcheck / Hypothesis / proptest equivalent.
Property-based tests complement unit tests: where a unit test
says "f(5) = 25", a property test says "forall n, f(n) >= 0
AND n*n >= n for n>=1". Covers input space unit tests miss.
Usage shape (pseudocode until parse.nx grows lambdas):
let cfg: *PropConfig = prop_config_new()
cfg.n_trials = 100
let rc: i64 = prop_run(cfg, "divides_correctly",
gen_i64, check_divide)
if rc != 0 { /* failure */ }
Generators + check functions are plain `func` values today;
phase B introduces closure syntax so properties are one-liners.
Invariants:
PT1 Every failing trial is reported + shrunk before return.
PT2 RNG state is DETERMINISTIC given the same seed so
reproduction is trivial.
PT3 Max trials cap respected; partial success (N-1 of N)
counts as success + reports the failing seed.
dependencies 2 imports · 0 importers
imports: syscalls.nxxoshiro.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 36 | struct PropConfig { |
consts
| 32 | const PT_OK: i64 = 0 |
| 33 | const PT_ERR_FAIL: i64 = -1 |
| 34 | const PT_ERR_TIMEOUT: i64 = -2 |
functions
| 43 | func prop_config_new() -> *PropConfig {
called by 1: main |
| 58 | func prop_shrink_i64(failing: i64, cfg: *PropConfig, |
| 70 | func prop_run_i64(cfg: *PropConfig,
called by 1: main |
| 87 | func prop_gen_i64(rng: *Xoshiro, cfg: *PropConfig) -> i64 {
calls 1: xoshiro_bounded |
| 94 | func prop_gen_nonneg(rng: *Xoshiro, cfg: *PropConfig) -> i64 { |
| 99 | func prop_gen_small(rng: *Xoshiro, cfg: *PropConfig) -> i64 { |
| 104 | func main() -> i64 { |