Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public boolean maxValue(final BigInteger value, final long max) {
* or equal to the minimum.
*/
public boolean minValue(final BigInteger value, final long min) {
return value.longValue() >= min;
return value.compareTo(BigInteger.valueOf(min)) >= 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void testBigIntegerAboveLongMaxValue() {
assertTrue(resultAboveLong.compareTo(BigInteger.ZERO) > 0);
assertTrue(resultAboveLong.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0);
assertTrue(instance.minValue(resultAboveLong, Long.MIN_VALUE));
assertFalse(instance.minValue(resultAboveLong, Long.MAX_VALUE));
assertTrue(instance.minValue(resultAboveLong, Long.MAX_VALUE));
assertFalse(instance.maxValue(resultAboveLong, Long.MIN_VALUE));
assertFalse(instance.maxValue(resultAboveLong, Long.MAX_VALUE));
assertFalse(instance.isInRange(resultAboveLong, Long.MIN_VALUE, Long.MAX_VALUE));
Expand All @@ -105,7 +105,7 @@ void testBigIntegerBelowLongMinValue() {
assertTrue(resultBelowLong.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) < 0);
assertTrue(resultBelowLong.compareTo(BigInteger.ZERO) < 0);
assertTrue(resultBelowLong.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) < 0);
assertTrue(instance.minValue(resultBelowLong, Long.MIN_VALUE));
assertFalse(instance.minValue(resultBelowLong, Long.MIN_VALUE));
assertFalse(instance.minValue(resultBelowLong, Long.MAX_VALUE));
assertTrue(instance.maxValue(resultBelowLong, Long.MIN_VALUE));
assertTrue(instance.maxValue(resultBelowLong, Long.MAX_VALUE));
Expand All @@ -114,6 +114,22 @@ void testBigIntegerBelowLongMinValue() {
assertEquals(BigDecimalValidator.getInstance().validate(belowLongStr, "#").toBigInteger(), resultBelowLong);
}

/**
* Test minValue() against bounds for values outside the long range, using exact BigIntegers so the comparison is not affected by double rounding.
*/
@Test
void testMinValueOutsideLongRange() {
final BigIntegerValidator instance = BigIntegerValidator.getInstance();
final BigInteger aboveMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
final BigInteger belowMin = BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE);
// aboveMax is greater than every long, so it is >= any long minimum
assertTrue(instance.minValue(aboveMax, Long.MAX_VALUE));
assertTrue(instance.minValue(aboveMax, Long.MIN_VALUE));
// belowMin is smaller than every long, so it is not >= any long minimum
assertFalse(instance.minValue(belowMin, Long.MIN_VALUE));
assertFalse(instance.minValue(belowMin, Long.MAX_VALUE));
}

/**
* Test BigInteger Range/Min/Max
*/
Expand Down
Loading