Search in sources :

Example 71 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class BigIntegerMathTest method testLog10Exact.

// Relies on the correctness of log10(BigInteger, FLOOR).
// TODO
@GwtIncompatible
public void testLog10Exact() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
        int logFloor = BigIntegerMath.log10(x, FLOOR);
        boolean expectSuccess = TEN.pow(logFloor).equals(x);
        try {
            assertEquals(logFloor, BigIntegerMath.log10(x, UNNECESSARY));
            assertTrue(expectSuccess);
        } catch (ArithmeticException e) {
            assertFalse(expectSuccess);
        }
    }
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 72 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class BigIntegerMathTest method testLog10Floor.

// TODO
@GwtIncompatible
public void testLog10Floor() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
        for (RoundingMode mode : asList(FLOOR, DOWN)) {
            int result = BigIntegerMath.log10(x, mode);
            assertTrue(TEN.pow(result).compareTo(x) <= 0);
            assertTrue(TEN.pow(result + 1).compareTo(x) > 0);
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 73 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class BigIntegerMathTest method testDivNonZeroExact.

// TODO
@GwtIncompatible
// slow
@AndroidIncompatible
public void testDivNonZeroExact() {
    boolean isAndroid = System.getProperty("java.runtime.name").contains("Android");
    for (BigInteger p : NONZERO_BIGINTEGER_CANDIDATES) {
        for (BigInteger q : NONZERO_BIGINTEGER_CANDIDATES) {
            if (isAndroid && p.equals(BAD_FOR_ANDROID_P) && q.equals(BAD_FOR_ANDROID_Q)) {
                // https://code.google.com/p/android/issues/detail?id=196555
                continue;
            }
            if (isAndroid && p.equals(BAD_FOR_GINGERBREAD_P) && q.equals(BAD_FOR_GINGERBREAD_Q)) {
                // Works fine under Marshmallow, so I haven't filed a bug.
                continue;
            }
            boolean dividesEvenly = p.remainder(q).equals(ZERO);
            try {
                BigInteger quotient = BigIntegerMath.divide(p, q, UNNECESSARY);
                BigInteger undone = quotient.multiply(q);
                if (!p.equals(undone)) {
                    failFormat("expected %s.multiply(%s) = %s; got %s", quotient, q, p, undone);
                }
                assertTrue(dividesEvenly);
            } catch (ArithmeticException e) {
                assertFalse(dividesEvenly);
            }
        }
    }
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 74 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class BigIntegerMathTest method testRoundToDouble_minDoubleMinusOne.

@GwtIncompatible
public void testRoundToDouble_minDoubleMinusOne() {
    BigInteger minDoubleAsBI = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY).subtract(BigInteger.ONE);
    new RoundToDoubleTester(minDoubleAsBI).setExpectation(-Double.MAX_VALUE, DOWN, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN).setExpectation(Double.NEGATIVE_INFINITY, UP, FLOOR).roundUnnecessaryShouldThrow().test();
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 75 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class BigIntegerMathTest method testLog10ZeroAlwaysThrows.

// TODO
@GwtIncompatible
public void testLog10ZeroAlwaysThrows() {
    for (RoundingMode mode : ALL_ROUNDING_MODES) {
        try {
            BigIntegerMath.log10(ZERO, mode);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Aggregations

GwtIncompatible (com.google.common.annotations.GwtIncompatible)361 NullPointerTester (com.google.common.testing.NullPointerTester)105 TestSuite (junit.framework.TestSuite)54 BigInteger (java.math.BigInteger)40 RoundingMode (java.math.RoundingMode)39 CountDownLatch (java.util.concurrent.CountDownLatch)25 ExecutorService (java.util.concurrent.ExecutorService)18 CancellationException (java.util.concurrent.CancellationException)17 Random (java.util.Random)16 ListTestSuiteBuilder (com.google.common.collect.testing.ListTestSuiteBuilder)15 ExecutionException (java.util.concurrent.ExecutionException)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 IOException (java.io.IOException)14 BigDecimal (java.math.BigDecimal)14 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)11 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)11 TimeoutException (java.util.concurrent.TimeoutException)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 EqualsTester (com.google.common.testing.EqualsTester)10 List (java.util.List)10