Move mod tests to BitMapTest
Consolidate the cases from EnhancedDoubleHasherTest and BitMapTest. Use Long.remainderUnsigned as the reference result.
This commit is contained in:
parent
81834a637d
commit
1624bdb89e
|
@ -104,18 +104,34 @@ public class BitMapTest {
|
|||
assertTrue(BitMap.contains(ary, 64));
|
||||
}
|
||||
|
||||
private void assertMod(long l, int i) {
|
||||
assertEquals(Math.floorMod(l, i), BitMap.mod(l, i));
|
||||
@Test
|
||||
public void testMod() {
|
||||
for (final long dividend : new long[] {0, -1, -2, -3, -6378683, -23567468136887892L,
|
||||
Long.MIN_VALUE, 345, 678686, 67868768686878924L, Long.MAX_VALUE, Long.MAX_VALUE - 1}) {
|
||||
for (final int divisor : new int[] {1, 2, 3, 5, 13, Integer.MAX_VALUE, Integer.MAX_VALUE - 1}) {
|
||||
assertMod(dividend, divisor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testMod() {
|
||||
assertMod(Long.MAX_VALUE, Integer.MAX_VALUE);
|
||||
assertMod(Long.MAX_VALUE, Integer.MAX_VALUE-1);
|
||||
assertThrows(ArithmeticException.class, () -> BitMap.mod(Long.MAX_VALUE, 0));
|
||||
assertMod(Long.MAX_VALUE-1, Integer.MAX_VALUE);
|
||||
assertMod(Long.MAX_VALUE-1, Integer.MAX_VALUE-1);
|
||||
assertMod(0, Integer.MAX_VALUE);
|
||||
public void testModEdgeCases() {
|
||||
for (final long dividend : new long[] {0, -1, 1, Long.MAX_VALUE}) {
|
||||
assertThrows(ArithmeticException.class, () -> BitMap.mod(dividend, 0));
|
||||
}
|
||||
assertNotEquals(Math.floorMod(5, -1), BitMap.mod(5, -1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the {@link BitMap#mod(long, int)} method functions as an unsigned modulus.
|
||||
*
|
||||
* @param dividend the dividend
|
||||
* @param divisor the divisor
|
||||
*/
|
||||
private void assertMod(long dividend, int divisor) {
|
||||
assertTrue(divisor > 0 && divisor <= Integer.MAX_VALUE,
|
||||
"Incorrect usage. Divisor must be strictly positive.");
|
||||
assertEquals((int) Long.remainderUnsigned(dividend, divisor), BitMap.mod(dividend, divisor),
|
||||
() -> String.format("failure with dividend=%s and divisor=%s.", dividend, divisor));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,15 +93,4 @@ public class EnhancedDoubleHasherTest extends AbstractHasherTest {
|
|||
// test empty buffer
|
||||
assertThrows(IllegalArgumentException.class, () -> new EnhancedDoubleHasher(new byte[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testModEdgeCases() {
|
||||
for (final long dividend : new long[] {-1, -2, -3, -6378683, -23567468136887892L, Long.MIN_VALUE, 345, 678686,
|
||||
67868768686878924L, Long.MAX_VALUE}) {
|
||||
for (final int divisor : new int[] {1, 2, 3, 5, 13, Integer.MAX_VALUE}) {
|
||||
assertEquals((int) Long.remainderUnsigned(dividend, divisor), BitMap.mod(dividend, divisor),
|
||||
() -> String.format("failure with dividend=%s and divisor=%s.", dividend, divisor));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue