Skip to content

fix: use range-aware shrinker in Int64Range to stay within bounds#92

Open
Yanhu007 wants to merge 1 commit intoleanovate:masterfrom
Yanhu007:fix/int-range-shrink-bounds
Open

fix: use range-aware shrinker in Int64Range to stay within bounds#92
Yanhu007 wants to merge 1 commit intoleanovate:masterfrom
Yanhu007:fix/int-range-shrink-bounds

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #81

Problem

gen.IntRange(min, max) uses the generic Int64Shrinker which shrinks toward 0. When the range doesn't include 0 (e.g., IntRange(5, 10)), the shrinker produces values outside the range during shrinking.

While the Sieve filters these out in some contexts, stateful command-based tests may not apply the sieve during the shrink phase, causing panics from out-of-bounds values.

Fix

Add a range-aware int64RangeShrinker(min, max) that shrinks toward min by halving the distance from min, guaranteeing all shrunk values stay within [min, max].

All existing tests pass with -race.

Int64Range used the generic Int64Shrinker which shrinks toward 0,
producing values outside the [min, max] range during shrinking.
While the Sieve filters these out, some property-based test
frameworks (like stateful commands) may not apply the sieve during
the shrink phase, causing panics from out-of-bounds values.

Add int64RangeShrinker that shrinks toward min by halving the
distance from min, guaranteeing all shrunk values stay within
[min, max].

Fixes leanovate#81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getting values outside of range when using gen.IntRange (probably during shrink)

1 participant