public void testRemainder() { for (long a : UNSIGNED_INTS) { for (long b : UNSIGNED_INTS) { try { assertEquals((int) (a % b), UnsignedInts.remainder((int) a, (int) b)); assertFalse(b == 0); } catch (ArithmeticException e) { assertEquals(0, b); } } } }
@GwtIncompatible("Too slow in GWT (~3min fully optimized)") public void testDivideRemainderEuclideanProperty() { // Use a seed so that the test is deterministic: Random r = new Random(0L); for (int i = 0; i < 1000000; i++) { int dividend = r.nextInt(); int divisor = r.nextInt(); // Test that the Euclidean property is preserved: assertTrue( dividend - (divisor * UnsignedInts.divide(dividend, divisor) + UnsignedInts.remainder(dividend, divisor)) == 0); } }