Search in sources :

Example 76 with GwtIncompatible

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

the class BigIntegerMathTest method testSqrtHalfUp.

// TODO
@GwtIncompatible
public void testSqrtHalfUp() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
        BigInteger result = BigIntegerMath.sqrt(x, HALF_UP);
        BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE);
        BigInteger x4 = x.shiftLeft(2);
        // sqrt(x) < result + 0.5, so 4 * x < (result + 0.5)^2 * 4
        // (result + 0.5)^2 * 4 = (result^2 + result)*4 + 1
        assertTrue(x4.compareTo(plusHalfSquared) < 0);
        BigInteger minusHalfSquared = result.pow(2).subtract(result).shiftLeft(2).add(ONE);
        // sqrt(x) > result - 0.5, so 4 * x > (result - 0.5)^2 * 4
        // (result - 0.5)^2 * 4 = (result^2 - result)*4 + 1
        assertTrue(result.equals(ZERO) || x4.compareTo(minusHalfSquared) >= 0);
    }
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 77 with GwtIncompatible

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

the class BigIntegerMathTest method testSqrtHalfEven.

// Relies on the correctness of sqrt(BigInteger, {HALF_UP,HALF_DOWN}).
// TODO
@GwtIncompatible
public void testSqrtHalfEven() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
        BigInteger halfEven = BigIntegerMath.sqrt(x, HALF_EVEN);
        // Now figure out what rounding mode we should behave like (it depends if FLOOR was
        // odd/even).
        boolean floorWasOdd = BigIntegerMath.sqrt(x, FLOOR).testBit(0);
        assertEquals(BigIntegerMath.sqrt(x, floorWasOdd ? HALF_UP : HALF_DOWN), halfEven);
    }
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 78 with GwtIncompatible

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

the class BigIntegerMathTest method testRoundToDouble_wayTooBig.

@GwtIncompatible
public void testRoundToDouble_wayTooBig() {
    BigInteger bi = BigInteger.ONE.shiftLeft(2 * Double.MAX_EXPONENT);
    new RoundToDoubleTester(bi).setExpectation(Double.MAX_VALUE, DOWN, FLOOR, HALF_EVEN, HALF_UP, HALF_DOWN).setExpectation(Double.POSITIVE_INFINITY, UP, CEILING).roundUnnecessaryShouldThrow().test();
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 79 with GwtIncompatible

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

the class BigIntegerMathTest method testLog10HalfDown.

// TODO
@GwtIncompatible
public void testLog10HalfDown() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
        int result = BigIntegerMath.log10(x, HALF_DOWN);
        BigInteger x2 = x.pow(2);
        // x^2 <= 10^(2 * result + 1), or else we would have rounded up
        assertTrue(TEN.pow(2 * result + 1).compareTo(x2) >= 0);
        // x^2 > 10^(2 * result - 1), or else we would have rounded down
        assertTrue(result == 0 || TEN.pow(2 * result - 1).compareTo(x2) < 0);
    }
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 80 with GwtIncompatible

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

the class BigIntegerMathTest method testLog10Ceiling.

// TODO
@GwtIncompatible
public void testLog10Ceiling() {
    for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
        for (RoundingMode mode : asList(CEILING, UP)) {
            int result = BigIntegerMath.log10(x, mode);
            assertTrue(TEN.pow(result).compareTo(x) >= 0);
            assertTrue(result == 0 || TEN.pow(result - 1).compareTo(x) < 0);
        }
    }
}
Also used : RoundingMode(java.math.RoundingMode) BigInteger(java.math.BigInteger) 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