diff options
author | Elliott Hughes <enh@google.com> | 2013-04-08 18:19:51 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-04-10 13:47:55 -0700 |
commit | b5ccf74bdea2d417d9e4820945fe3ba1f636a0d2 (patch) | |
tree | d5e7403979d3c04008c2e721d2dabc64d196046a /harmony-tests | |
parent | c5f088304766357ba8efae909bef6e5abc09c1f0 (diff) | |
download | libcore-b5ccf74bdea2d417d9e4820945fe3ba1f636a0d2.zip libcore-b5ccf74bdea2d417d9e4820945fe3ba1f636a0d2.tar.gz libcore-b5ccf74bdea2d417d9e4820945fe3ba1f636a0d2.tar.bz2 |
Fix BigInteger test failures.
We were hitting a couple of OpenSSL bugs. I've reported them upstream, and
work around them in the meantime.
Bug: 2943474
Change-Id: Ia06bcf3025f525a954d9b918669d09531631a266
Diffstat (limited to 'harmony-tests')
-rw-r--r-- | harmony-tests/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java | 59 | ||||
-rw-r--r-- | harmony-tests/src/test/java/tests/api/java/math/BigIntegerTest.java | 25 |
2 files changed, 38 insertions, 46 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java index 051ba5e..a81a021 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/math/BigIntegerConstructorsTest.java @@ -745,25 +745,42 @@ public class BigIntegerConstructorsTest extends TestCase { assertTrue("incorrect bitLength", aNumber.bitLength() <= bitLen); } - /** - * Create a prime number of 25 bits length. - */ - public void testConstructorPrime() { - int bitLen = 25; - Random rnd = new Random(); - BigInteger aNumber = new BigInteger(bitLen, 80, rnd); - assertTrue("incorrect bitLength", aNumber.bitLength() == bitLen); - } - - /** - * Create a prime number of 2 bits length. - */ - public void testConstructorPrime2() { - int bitLen = 2; - Random rnd = new Random(); - BigInteger aNumber = new BigInteger(bitLen, 80, rnd); - assertTrue("incorrect bitLength", aNumber.bitLength() == bitLen); - int num = aNumber.intValue(); - assertTrue("incorrect value", num == 2 || num == 3); - } + public void testConstructorPrime() { + for (int rep = 0; rep < 2048; ++rep) { + Random rnd = new Random(); + BigInteger b; + int bits; + + // Create a 128-bit prime number. + bits = 128; + b = new BigInteger(bits, 10, rnd); + assertEquals(b.toString(), bits, b.bitLength()); + + // Create a prime number of 25 bits length. + bits = 25; + b = new BigInteger(bits, 10, rnd); + assertEquals(b.toString(), bits, b.bitLength()); + + // Create a prime number of 18 bits length. + bits = 18; + b = new BigInteger(bits, 10, rnd); + assertEquals(b.toString(), bits, b.bitLength()); + + // On Android, anything less than 16 bits will be at least 16 bits + // because that's how OpenSSL behaves... + bits = 2; + b = new BigInteger(bits, 10, rnd); + assertEquals(b.toString(), 16, b.bitLength()); + + // ...unless you use the 2-arg constructor, which doesn't use OpenSSL. + bits = 2; + b = new BigInteger(bits, rnd); + assertTrue(b.toString(), b.bitLength() <= bits); + assertTrue(b.toString(), b.intValue() <= 3); + + bits = 16; + b = new BigInteger(bits, rnd); + assertTrue(b.toString(), b.bitLength() <= bits); + } + } } diff --git a/harmony-tests/src/test/java/tests/api/java/math/BigIntegerTest.java b/harmony-tests/src/test/java/tests/api/java/math/BigIntegerTest.java index 8cc703f..28995cb 100644 --- a/harmony-tests/src/test/java/tests/api/java/math/BigIntegerTest.java +++ b/harmony-tests/src/test/java/tests/api/java/math/BigIntegerTest.java @@ -101,31 +101,6 @@ public class BigIntegerTest extends junit.framework.TestCase { } /** - * @tests java.math.BigInteger#BigInteger(int, int, java.util.Random) - */ - public void test_ConstructorIILjava_util_Random() { - bi = new BigInteger(10, 5, rand); - bi2 = new BigInteger(10, 5, rand); - assertTrue("Random number one is negative", bi.compareTo(zero) >= 0); - assertTrue("Random number one is too big", - bi.compareTo(twoToTheTen) < 0); - assertTrue("Random number two is negative", bi2.compareTo(zero) >= 0); - assertTrue("Random number two is too big", - bi2.compareTo(twoToTheTen) < 0); - - Random rand = new Random(); - BigInteger bi; - int certainty[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -2, -1 }; - for (int i = 2; i <= 20; i++) { - for (int c = 0; c < certainty.length; c++) { - bi = new BigInteger(i, c, rand); // Create BigInteger - assertTrue("Bit length incorrect", bi.bitLength() == i); - } - } - } - - /** * @tests java.math.BigInteger#BigInteger(byte[]) */ public void test_Constructor$B() { |