Skip to content

Commit

Permalink
Fixed bug #544
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Feb 1, 2024
1 parent 28012bb commit 0313063
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# 1.8.3

- Fix integer generation bug: https://github.com/jqwik-team/jqwik/issues/544

- Summon preconfigured arbitrary. See https://github.com/jqwik-team/jqwik/issues/527

# 1.8.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public RandomNumericGenerator createGenerator(
}

private static boolean isWithinIntegerRange(BigInteger min, BigInteger max) {
return min.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) >= 0
&& max.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) <= 0;
boolean rangeIsSmallerThanIntegerMax = max.subtract(min).compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) < 0;
boolean minAndMaxAreWithinInt = min.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) >= 0
&& max.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) <= 0;
return rangeIsSmallerThanIntegerMax && minAndMaxAreWithinInt;
}

@Override
Expand Down
18 changes: 18 additions & 0 deletions engine/src/test/java/net/jqwik/api/ArbitrariesTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,24 @@ void integersInt(@ForAll Random random) {
checkAllGenerated(generator, random, value -> value >= -10 && value <= 10);
}

@Property(tries = 10)
void integersFullRangeWithUniformDistribution(@ForAll Random random) {
Arbitrary<Integer> integerArbitrary =
Arbitraries.integers()
.withDistribution(RandomDistribution.uniform());
RandomGenerator<Integer> generator = integerArbitrary.generator(1);

TestingSupport.checkAllGenerated(
generator,
random,
value -> value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE
);
TestingSupport.checkAtLeastOneGenerated(generator, random, value -> value > 0 && value < Integer.MAX_VALUE);
TestingSupport.checkAtLeastOneGenerated(generator, random, value -> value < 0 && value > Integer.MIN_VALUE);
}



@Example
void longMinsAndMaxesWithEdgeCases(@ForAll Random random) {
RandomGenerator<Long> generator = Arbitraries.longs().generator(1, true);
Expand Down

0 comments on commit 0313063

Please sign in to comment.