test/java/math/BigDecimal/StringConstructor.java
Print this page
rev 11823 : 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
Summary: Add ability to initial the random number generator from the system property "seed" and print to STDOUT the seed value actually used.
Reviewed-by: XXX
*** 21,45 ****
* questions.
*/
/*
* @test
! * @library ..
! * @bug 4103117 4331084 4488017 4490929 6255285 6268365 8074460
* @summary Tests the BigDecimal string constructor (use -Dseed=X to set PRNG seed).
* @key randomness
*/
import java.math.*;
public class StringConstructor {
- private static RandomSeed rndSeed = new RandomSeed(false);
-
public static void main(String[] args) throws Exception {
- System.out.println("Random number generator seed = " + rndSeed.getSeed());
-
constructWithError("");
constructWithError("+");
constructWithError("-");
constructWithError("+e");
constructWithError("-e");
--- 21,44 ----
* questions.
*/
/*
* @test
! * @library /lib/testlibrary/
! * @build jdk.testlibrary.*
! * @run main StringConstructor
! * @bug 4103117 4331084 4488017 4490929 6255285 6268365 8074460 8078672
* @summary Tests the BigDecimal string constructor (use -Dseed=X to set PRNG seed).
* @key randomness
*/
import java.math.*;
+ import java.util.Random;
public class StringConstructor {
public static void main(String[] args) throws Exception {
constructWithError("");
constructWithError("+");
constructWithError("-");
constructWithError("+e");
constructWithError("-e");
*** 70,86 ****
leadingExponentZeroTest();
nonAsciiZeroTest();
// Roundtrip tests
for (int i=0; i<100; i++) {
! int size = rndSeed.getRandom().nextInt(100) + 1;
! BigInteger bi = new BigInteger(size, rndSeed.getRandom());
! if (rndSeed.getRandom().nextBoolean())
bi = bi.negate();
int decimalLength = bi.toString().length();
! int scale = rndSeed.getRandom().nextInt(decimalLength);
BigDecimal bd = new BigDecimal(bi, scale);
String bdString = bd.toString();
// System.err.println("bi" + bi.toString() + "\tscale " + scale);
// System.err.println("bd string: " + bdString);
BigDecimal bdDoppel = new BigDecimal(bdString);
--- 69,86 ----
leadingExponentZeroTest();
nonAsciiZeroTest();
// Roundtrip tests
+ Random random = RandomFactory.getRandom();
for (int i=0; i<100; i++) {
! int size = random.nextInt(100) + 1;
! BigInteger bi = new BigInteger(size, random);
! if (random.nextBoolean())
bi = bi.negate();
int decimalLength = bi.toString().length();
! int scale = random.nextInt(decimalLength);
BigDecimal bd = new BigDecimal(bi, scale);
String bdString = bd.toString();
// System.err.println("bi" + bi.toString() + "\tscale " + scale);
// System.err.println("bd string: " + bdString);
BigDecimal bdDoppel = new BigDecimal(bdString);