code wiki / (root) / prop_test.nx

prop_test.nx

buildroot/runtime/prop_test.nx

6748 B207 linesdepth 3pulls 4 transitivereach 2 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

prop_test.nx -- property-based testing infrastructure. Verify that a property holds across a LARGE random sample of inputs instead of enumerating hand-picked cases. Catches bugs that manual test cases miss. Inspired by QuickCheck (Haskell, 2000), Hypothesis (Python), proptest (Rust). Pattern: 1. Define a property P(x) that should be true for all x of some type T. 2. Write a generator that produces random T values from a seeded PRNG. 3. Run P(gen()) for N iterations (default 1000). 4. On failure, record the first counter-example + shrink it to a minimal case. This scaffold ships the GENERATOR + RUNNER primitives. Each property test lives in its own .nx file (see prop_*_test.nx). Reference: Claessen & Hughes 2000 "QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs"; MacIver 2019 "Hypothesis: A new approach to property-based testing" (particularly the shrinking algorithm).

dependencies 2 imports · 2 importers

syscalls.nx nx_assert.nx prop_test.nx prop_lex_number_test.nx prop_nxtask_store_test.nx

imports: syscalls.nxnx_assert.nx

imported by: prop_lex_number_test.nxprop_nxtask_store_test.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main prop_gen_new prop_gen_i64 prop_report nx_puti_err sys_mmap sys_write nx_putx_err sys_mmap ↻ sys_write ↻ nx_puts_err sys_write ↻ prop_gen_range prop_gen_i64 ↻ prop_gen_bytes prop_gen_i64 ↻

structs

35struct PropGen {

consts

41const PROP_GEN_BYTES: i64 = 32

functions

43func prop_gen_new(seed: i64) -> *PropGen {
called by 3: mainmainmain
61func prop_gen_i64(g: *PropGen) -> i64 {
72func prop_gen_range(g: *PropGen, lo: i64, hi: i64) -> i64 {
called by 3: mainmainmain calls 1: prop_gen_i64
86func prop_gen_small(g: *PropGen) -> i64 {
calls 1: prop_gen_i64
95func prop_gen_bytes(g: *PropGen, buf: *u8, n: i64) -> i64 {
called by 1: main calls 1: prop_gen_i64
106func prop_gen_printable(g: *PropGen) -> i64 {
called by 1: main calls 1: prop_gen_i64
128func prop_report(g: *PropGen, tag: *u8) -> i64 {
147func main() -> i64 {