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

Closed integer interval with a shrink origin and a size-dependent growth strategy.

pub opaque type Range

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.

pub fn origin(range: Range) -> Int

The shrink target for this range.

pub fn singleton(value: Int) -> Range

A range that always returns exactly value.

Search Document