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).
Panics at construction if lo > hi. An inverted pair is almost always
a bug (swapped arguments), so failing visibly catches it earlier than
silently normalising.
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.
Panics at construction if lo > hi.
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].
Panics at construction if lo > hi.
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).
Panics at construction if lo > hi or if origin is outside
[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).