/** * @pwngh/economy-lab * * Copyright (c) Preston Neal * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ /** * A hand-rolled property-based testing core, not fast-check: seeded `Arbitrary` generators that * compose, and a multi-axis `minimize` that reduces a failing value to its smallest still-failing * form. Seeds are always explicit, so a failing run reproduces byte-identically. This is the shrinker * the seeded programs in `scripts/prove.ts` never had — that one only trims the tail. */ /** Uniform in [0, 1). */ export type Rng = () => number; export declare function mulberry32(seed: number): Rng; /** Knows how to generate a value and how to shrink one into simpler candidates, simplest first. */ export type Arbitrary = { generate: (rng: Rng) => T; shrink: (value: T) => T[]; }; /** Integer in [min, max], shrinking toward `min` by halving the remaining distance. */ export declare function int(min: number, max: number): Arbitrary; /** One of a fixed set, shrinking toward earlier values (so 'other' can simplify to 'system'). */ export declare function choice(...values: T[]): Arbitrary; /** A record of Arbitraries; shrinks one field at a time. */ export declare function record(shape: { [K in keyof T]: Arbitrary; }): Arbitrary; /** * A variable-length array; shrinks by dropping elements — empty, each half, then one at a time — and * by shrinking individual elements. Dropping a middle element is what a prefix-only shrinker misses. */ export declare function array(elem: Arbitrary, maxLen: number): Arbitrary; export type Property = (value: T) => boolean | Promise; export type Report = { ok: true; runs: number; } | { ok: false; seed: number; counterexample: T; shrinks: number; }; /** * Greedily reduces a failing value: repeatedly takes the first simpler candidate that still fails, * until nothing simpler fails. Deterministic given the property. Results are memoized per call — * different shrink axes reproduce the same candidate, and for a property that replays a whole * program, re-testing it is the expensive part. */ export declare function minimize(arb: Arbitrary, prop: Property, value: T): Promise<[T, number]>; /** * Runs `prop` over `runs` values from `seed`. On the first failure, minimizes it and reports the * smallest counterexample plus the exact seed that produced it. The seed is required — a property * test with no reproducible seed is a flaky test. */ export declare function check(arb: Arbitrary, prop: Property, opts: { seed: number; runs?: number; }): Promise>;