Search in sources :

Example 71 with BigInteger

use of java.math.BigInteger in project guava by google.

the class IntMathTest method testCheckedMultiply.

// presumably slow
@AndroidIncompatible
public void testCheckedMultiply() {
    for (int a : ALL_INTEGER_CANDIDATES) {
        for (int b : ALL_INTEGER_CANDIDATES) {
            BigInteger expectedResult = valueOf(a).multiply(valueOf(b));
            boolean expectedSuccess = fitsInInt(expectedResult);
            try {
                assertEquals(a * b, IntMath.checkedMultiply(a, b));
                assertTrue(expectedSuccess);
            } catch (ArithmeticException e) {
                assertFalse(expectedSuccess);
            }
        }
    }
}
Also used : BigInteger(java.math.BigInteger)

Example 72 with BigInteger

use of java.math.BigInteger in project guava by google.

the class IntMathTest method testBinomial.

// Depends on the correctness of BigIntegerMath.binomial.
// BigIntegerMath // TODO(cpovirk): GWT-enable BigIntegerMath
@GwtIncompatible
public void testBinomial() {
    for (int n = 0; n <= 50; n++) {
        for (int k = 0; k <= n; k++) {
            BigInteger expectedBig = BigIntegerMath.binomial(n, k);
            int expectedInt = fitsInInt(expectedBig) ? expectedBig.intValue() : Integer.MAX_VALUE;
            assertEquals(expectedInt, IntMath.binomial(n, k));
        }
    }
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 73 with BigInteger

use of java.math.BigInteger in project guava by google.

the class IntMathTest method testCheckedAdd.

// slow
@AndroidIncompatible
public void testCheckedAdd() {
    for (int a : ALL_INTEGER_CANDIDATES) {
        for (int b : ALL_INTEGER_CANDIDATES) {
            BigInteger expectedResult = valueOf(a).add(valueOf(b));
            boolean expectedSuccess = fitsInInt(expectedResult);
            try {
                assertEquals(a + b, IntMath.checkedAdd(a, b));
                assertTrue(expectedSuccess);
            } catch (ArithmeticException e) {
                assertFalse(expectedSuccess);
            }
        }
    }
}
Also used : BigInteger(java.math.BigInteger)

Example 74 with BigInteger

use of java.math.BigInteger in project j2objc by google.

the class BigIntegerTest method test_Constructor$B.

/**
	 * @tests java.math.BigInteger#BigInteger(byte[])
	 */
public void test_Constructor$B() {
    byte[] myByteArray;
    myByteArray = new byte[] { (byte) 0x00, (byte) 0xFF, (byte) 0xFE };
    bi = new BigInteger(myByteArray);
    assertTrue("Incorrect value for pos number", bi.equals(BigInteger.ZERO.setBit(16).subtract(two)));
    myByteArray = new byte[] { (byte) 0xFF, (byte) 0xFE };
    bi = new BigInteger(myByteArray);
    assertTrue("Incorrect value for neg number", bi.equals(minusTwo));
}
Also used : BigInteger(java.math.BigInteger)

Example 75 with BigInteger

use of java.math.BigInteger in project j2objc by google.

the class BigIntegerTest method test_andNotLjava_math_BigInteger.

/**
	 * @tests java.math.BigInteger#andNot(java.math.BigInteger)
	 */
public void test_andNotLjava_math_BigInteger() {
    for (BigInteger[] element : booleanPairs) {
        BigInteger i1 = element[0], i2 = element[1];
        BigInteger res = i1.andNot(i2);
        int len = Math.max(i1.bitLength(), i2.bitLength()) + 66;
        for (int i = 0; i < len; i++) {
            assertTrue("andNot", (i1.testBit(i) && !i2.testBit(i)) == res.testBit(i));
        }
        // asymmetrical
        i1 = element[1];
        i2 = element[0];
        res = i1.andNot(i2);
        for (int i = 0; i < len; i++) {
            assertTrue("andNot reversed", (i1.testBit(i) && !i2.testBit(i)) == res.testBit(i));
        }
    }
    //regression for HARMONY-4653
    try {
        BigInteger.ZERO.andNot(null);
        fail("should throw NPE");
    } catch (Exception e) {
    //expected
    }
    BigInteger bi = new BigInteger(0, new byte[] {});
    assertEquals(BigInteger.ZERO, bi.andNot(BigInteger.ZERO));
}
Also used : BigInteger(java.math.BigInteger)

Aggregations

BigInteger (java.math.BigInteger)3500 BigDecimal (java.math.BigDecimal)635 Test (org.junit.Test)337 IOException (java.io.IOException)113 ArrayList (java.util.ArrayList)105 MessageDigest (java.security.MessageDigest)101 RoundingMode (java.math.RoundingMode)88 Date (java.util.Date)80 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)75 MathContext (java.math.MathContext)71 Random (java.util.Random)65 Test (org.junit.jupiter.api.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)47 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 KeyFactory (java.security.KeyFactory)46 HashMap (java.util.HashMap)45 List (java.util.List)44 SecureRandom (java.security.SecureRandom)42 X509Certificate (java.security.cert.X509Certificate)42 EllipticCurve (java.security.spec.EllipticCurve)40