jdk/test/java/math/BigDecimal/StringConstructor.java
changeset 30048 3424bede284d
parent 30046 cf2c86e1819e
child 30436 17827057ef5a
equal deleted inserted replaced
30047:63b6a16968d5 30048:3424bede284d
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @library ..
    26  * @library /lib/testlibrary/
    27  * @bug 4103117 4331084 4488017 4490929 6255285 6268365 8074460
    27  * @build jdk.testlibrary.*
       
    28  * @run main StringConstructor
       
    29  * @bug 4103117 4331084 4488017 4490929 6255285 6268365 8074460 8078672
    28  * @summary Tests the BigDecimal string constructor (use -Dseed=X to set PRNG seed).
    30  * @summary Tests the BigDecimal string constructor (use -Dseed=X to set PRNG seed).
    29  * @key randomness
    31  * @key randomness
    30  */
    32  */
    31 
    33 
    32 import java.math.*;
    34 import java.math.*;
       
    35 import java.util.Random;
    33 
    36 
    34 public class StringConstructor {
    37 public class StringConstructor {
    35 
    38 
    36     private static RandomSeed rndSeed = new RandomSeed(false);
       
    37 
       
    38     public static void main(String[] args) throws Exception {
    39     public static void main(String[] args) throws Exception {
    39         System.out.println("Random number generator seed = " + rndSeed.getSeed());
       
    40 
       
    41         constructWithError("");
    40         constructWithError("");
    42         constructWithError("+");
    41         constructWithError("+");
    43         constructWithError("-");
    42         constructWithError("-");
    44         constructWithError("+e");
    43         constructWithError("+e");
    45         constructWithError("-e");
    44         constructWithError("-e");
    70 
    69 
    71         leadingExponentZeroTest();
    70         leadingExponentZeroTest();
    72         nonAsciiZeroTest();
    71         nonAsciiZeroTest();
    73 
    72 
    74         // Roundtrip tests
    73         // Roundtrip tests
       
    74         Random random = RandomFactory.getRandom();
    75         for (int i=0; i<100; i++) {
    75         for (int i=0; i<100; i++) {
    76             int size = rndSeed.getRandom().nextInt(100) + 1;
    76             int size = random.nextInt(100) + 1;
    77             BigInteger bi = new BigInteger(size, rndSeed.getRandom());
    77             BigInteger bi = new BigInteger(size, random);
    78             if (rndSeed.getRandom().nextBoolean())
    78             if (random.nextBoolean())
    79                 bi = bi.negate();
    79                 bi = bi.negate();
    80             int decimalLength = bi.toString().length();
    80             int decimalLength = bi.toString().length();
    81             int scale = rndSeed.getRandom().nextInt(decimalLength);
    81             int scale = random.nextInt(decimalLength);
    82             BigDecimal bd = new BigDecimal(bi, scale);
    82             BigDecimal bd = new BigDecimal(bi, scale);
    83             String bdString = bd.toString();
    83             String bdString = bd.toString();
    84             // System.err.println("bi" + bi.toString() + "\tscale " + scale);
    84             // System.err.println("bi" + bi.toString() + "\tscale " + scale);
    85             // System.err.println("bd string: " + bdString);
    85             // System.err.println("bd string: " + bdString);
    86             BigDecimal bdDoppel = new BigDecimal(bdString);
    86             BigDecimal bdDoppel = new BigDecimal(bdString);