metamon/generator/range
Bounds + shrink origin + size scaling for numeric generators.
A Range(Int) describes how a generator’s bounds widen as the test
size parameter grows from 0 (smallest) toward max_size, and where
shrinking should converge (“origin”). Modelled on Hedgehog’s Range.
Types
Values
pub fn bounds(
range: Range,
size: Int,
max_size: Int,
) -> #(Int, Int)
Compute the actual [lo, hi] bounds for a given size between 0
and max_size. size is clamped into [0, max_size].
pub fn constant(lo: Int, hi: Int) -> Range
A range that ignores size and always uses [lo, hi]. Origin is lo
(or 0 if 0 lies inside the interval, which usually shrinks better).
Inverted bounds (lo > hi) are auto-swapped to match the lenient
policy generator.float already uses. Use singleton when both
values are intentionally equal.
pub fn exponential(lo: Int, hi: Int) -> Range
Exponential scaling: bounds grow roughly like size^2 / max_size,
well-suited for ranges spanning many orders of magnitude.
Inverted bounds (lo > hi) are auto-swapped.
pub fn linear(lo: Int, hi: Int) -> Range
A range that scales linearly: at size = 0 returns [origin, origin]
and at size = max_size returns the full [lo, hi].
Inverted bounds (lo > hi) are auto-swapped.
pub fn linear_from(origin: Int, lo: Int, hi: Int) -> Range
Like linear but the origin is supplied explicitly. Useful when the
natural shrink target is not 0 (e.g. years near 2000 shrinking to
2000).
Inverted bounds (lo > hi) are auto-swapped. After that swap, the
function still panics if origin is outside the resulting
[lo, hi] — an origin outside the interval would silently emit
out-of-range values at small sizes (size = 0 collapses both
bounds to origin), so failing visibly catches the misuse. This
matches the invariant linear upholds automatically (its origin
is always either 0 when inside the interval, or lo).