package windtrap
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=2241b294b24ed5d56ea8b834d296e6fabc5dbdd924a89f51c14b00da66c50a25
sha512=c6cf83028bb09d0f2afeb38fce6825620873a6bbeff4b5b77e928bc2fc69262d49fe341961cba2b451c9dc9bd0df414f06bb73020c7131b125c6abd85c6bc5dd
doc/windtrap.prop/Windtrap_prop/Gen/index.html
Module Windtrap_prop.GenSource
Random value generators with integrated shrinking.
Random value generators with integrated shrinking.
Generators produce shrink trees, coupling generated values with their shrink candidates. This ensures shrinks automatically respect generator invariants (e.g., int_range 10 100 shrinks stay within bounds).
A generator takes random state and produces a shrink tree.
Combinators
bind gen f generates with gen, then uses result to select next generator.
ap fgen xgen applies generated function to generated value. Shrinks are interleaved from both generators.
Primitives
make_primitive ~gen ~shrink builds a generator from a raw generation function and a shrink function. This is the escape hatch for building custom generators when the standard combinators are not sufficient.
int_range low high generates integers in [low, high]. Shrinks toward origin (default: closest to 0 within range).
Generates non-negative integers in [0, 10_000], biased toward small values. Shrinks toward 0.
Generates integers in [-10_000, 10_000], biased toward small absolute values. Shrinks toward 0.
int32_range low high generates 32-bit integers in [low, high]. Shrinks toward origin (default: closest to 0l within range).
int64_range low high generates 64-bit integers in [low, high]. Shrinks toward origin (default: closest to 0L within range).
Generates native integers using full platform range. Shrinks toward 0n.
Generates floats using bit manipulation over the full IEEE 754 range, including NaN, infinity, and subnormal values. Shrinks toward 0.0.
float_range low high generates floats between low (inclusive) and high (exclusive). Shrinks toward origin (default: closest to 0.0 within range).
char_range low high generates characters in [low, high]. Shrinks toward origin (default: low).
string_of char_gen generates strings using char_gen for characters. Length biased toward small values (see nat).
string_size size_gen char_gen generates strings with length from size_gen and characters from char_gen.
Containers
result ok_gen err_gen generates Ok or Error.
either left_gen right_gen generates Left or Right.
list gen generates lists. Length biased toward small. Uses efficient bisection shrinking for large lists.
list_size size_gen gen generates lists with size from size_gen.
quad a b c d generates 4-tuples.
Choice
oneofl xs picks one element uniformly at random. Shrinks toward earlier elements in the list.
frequency weighted_gens picks a generator with probability proportional to its weight.
Size Control
sized f generates a size in [0, 1000] biased toward small values, then calls f with that size.
Shrink Control
add_shrink_invariant p gen filters shrinks to only those satisfying p.
Recursive Generators
delay f delays generator construction. Useful for recursive generators.
fix f creates a recursive generator. f receives the generator being defined as its argument.
type tree = Leaf | Node of tree * tree
let tree_gen =
Gen.fix (fun self ->
Gen.frequency
[
(3, Gen.pure Leaf);
( 1,
let+ l, r = Gen.pair self self in
Node (l, r) );
])Search
find ~f gen state attempts to find a generated value satisfying f. Tries up to count generations (default: 100). Returns None if no match is found. Does not shrink; returns the first match.