test/jdk/java/math/BigDecimal/RangeTests.java
author thartmann
Thu, 22 Mar 2018 08:39:51 +0100
changeset 49483 d374b1634589
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199777: Deprecate -XX:+AggressiveOpts Summary: Deprecate -XX:+AggressiveOpts and remove it from testing. Reviewed-by: kvn, dholmes, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9272
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
     1
/*
49483
d374b1634589 8199777: Deprecate -XX:+AggressiveOpts
thartmann
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
9272
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
     4
 *
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
     8
 *
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    13
 * accompanied this code).
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    14
 *
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    18
 *
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    21
 * questions.
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    22
 */
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    23
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    24
/*
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    25
 * @test
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    26
 * @bug 7036582
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    27
 * @summary Some new tests for the add method and constructor with MathContext.
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    28
 * @run main RangeTests
49483
d374b1634589 8199777: Deprecate -XX:+AggressiveOpts
thartmann
parents: 47216
diff changeset
    29
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+EliminateAutoBox -XX:AutoBoxCacheMax=20000 RangeTests
9272
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    30
 * @author Sergey V. Kuksenko
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    31
 */
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    32
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    33
import java.math.BigDecimal;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    34
import java.math.BigInteger;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    35
import java.math.MathContext;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    36
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    37
public class RangeTests {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    38
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    39
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    40
    private static int addTest(BigDecimal arg1, BigDecimal arg2, BigDecimal expectedResult) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    41
        int failures = 0;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    42
        BigDecimal result = arg1.add(arg2);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    43
        if (!result.equals(expectedResult)) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    44
            System.out.println("Sum:" +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    45
                    arg1 + " + " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    46
                    arg2 + " == " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    47
                    result + "; expected  " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    48
                    expectedResult
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    49
            );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    50
            failures++;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    51
        }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    52
        result = arg2.add(arg1);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    53
        if (!result.equals(expectedResult)) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    54
            System.out.println("Sum:" +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    55
                    arg2 + " + " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    56
                    arg1 + " == " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    57
                    result + "; expected  " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    58
                    expectedResult
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    59
            );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    60
            failures++;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    61
        }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    62
        return failures;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    63
    }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    64
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    65
    /*
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    66
     *  Test BigDecimal.add(BigDecimal) when values are withing different ranges:
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    67
     *  1. within 32 bits
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    68
     *  2. within 64 bits
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    69
     *  3. outside 64 bits.
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    70
     */
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    71
    private static int addBoundaryTest() {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    72
        int failures = 0;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    73
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    74
                new BigDecimal("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    75
                BigDecimal.valueOf(0),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    76
                new BigDecimal("85070591730234615847396907784232501249") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    77
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    78
                new BigDecimal("-85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    79
                BigDecimal.valueOf(0),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    80
                new BigDecimal("-85070591730234615847396907784232501249") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    81
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    82
                new BigDecimal("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    83
                BigDecimal.valueOf(1),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    84
                new BigDecimal("85070591730234615847396907784232501250") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    85
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    86
                new BigDecimal("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    87
                BigDecimal.valueOf(-1),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    88
                new BigDecimal("85070591730234615847396907784232501248") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    89
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    90
                new BigDecimal("-85070591730234615847396907784232501250"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    91
                BigDecimal.valueOf(-1),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    92
                new BigDecimal("-85070591730234615847396907784232501251") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    93
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    94
                new BigDecimal("-85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    95
                BigDecimal.valueOf(1),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    96
                new BigDecimal("-85070591730234615847396907784232501248") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    97
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    98
                new BigDecimal("147573952589676412927"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
    99
                BigDecimal.valueOf(Integer.MAX_VALUE),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   100
                new BigDecimal("147573952591823896574") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   101
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   102
                new BigDecimal("-147573952589676412927"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   103
                BigDecimal.valueOf(Integer.MAX_VALUE),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   104
                new BigDecimal("-147573952587528929280") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   105
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   106
                new BigDecimal("79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   107
                BigDecimal.valueOf(999),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   108
                new BigDecimal("79228162514264337593543951334") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   109
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   110
                new BigDecimal("79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   111
                BigDecimal.valueOf(Integer.MAX_VALUE/2),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   112
                new BigDecimal("79228162514264337594617692158") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   113
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   114
                new BigDecimal("79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   115
                BigDecimal.valueOf(Integer.MIN_VALUE/2),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   116
                new BigDecimal("79228162514264337592470208511") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   117
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   118
                new BigDecimal("-79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   119
                BigDecimal.valueOf(Integer.MAX_VALUE/2),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   120
                new BigDecimal("-79228162514264337592470208512") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   121
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   122
                new BigDecimal("79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   123
                BigDecimal.valueOf(-(Integer.MIN_VALUE/2)),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   124
                new BigDecimal("79228162514264337594617692159") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   125
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   126
                new BigDecimal("79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   127
                BigDecimal.valueOf(Long.MAX_VALUE/2),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   128
                new BigDecimal("79228162518876023611971338238") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   129
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   130
                new BigDecimal("79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   131
                BigDecimal.valueOf(Long.MIN_VALUE/2),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   132
                new BigDecimal("79228162509652651575116562431") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   133
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   134
                new BigDecimal("-79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   135
                BigDecimal.valueOf(Long.MAX_VALUE/2),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   136
                new BigDecimal("-79228162509652651575116562432") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   137
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   138
                new BigDecimal("79228162514264337593543950335"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   139
                BigDecimal.valueOf(-(Long.MIN_VALUE/2)),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   140
                new BigDecimal("79228162518876023611971338239") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   141
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   142
                new BigDecimal("-9223372036854775808"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   143
                BigDecimal.valueOf(1),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   144
                new BigDecimal("-9223372036854775807") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   145
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   146
                new BigDecimal("-9223372036854775808"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   147
                BigDecimal.valueOf(Long.MAX_VALUE/2),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   148
                new BigDecimal("-4611686018427387905") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   149
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   150
                new BigDecimal("9223372036854775808"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   151
                BigDecimal.valueOf(-1),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   152
                new BigDecimal("9223372036854775807") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   153
        failures += addTest(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   154
                new BigDecimal("9223372036854775808"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   155
                BigDecimal.valueOf(-Long.MAX_VALUE/2),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   156
                new BigDecimal("4611686018427387905") );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   157
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   158
        return failures;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   159
    }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   160
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   161
    private static int testRoundingFromBigInteger(BigInteger bi, int scale, MathContext mc) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   162
        int failures = 0;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   163
        BigDecimal bd1 = new BigDecimal(bi,scale, mc);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   164
        BigDecimal bd2 = (new BigDecimal(bi,scale)).round(mc);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   165
        if (!bd1.equals(bd2)) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   166
            System.out.println("new BigDecimal(BigInteger,int,MathContext):" +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   167
                    "BigInteger == " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   168
                    bi + ";  scale == " + scale + "; result == " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   169
                    bd1 + "; expected  == " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   170
                    bd2
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   171
            );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   172
            failures++;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   173
        }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   174
        return failures;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   175
    }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   176
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   177
    private static int roundingConstructorTest() {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   178
        int failures = 0;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   179
        failures += testRoundingFromBigInteger(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   180
                new BigInteger("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   181
                7, MathContext.DECIMAL64);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   182
        failures += testRoundingFromBigInteger(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   183
                new BigInteger("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   184
                0, MathContext.DECIMAL64);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   185
        failures += testRoundingFromBigInteger(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   186
                new BigInteger("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   187
                -7, MathContext.DECIMAL64);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   188
        failures += testRoundingFromBigInteger(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   189
                new BigInteger("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   190
                7, MathContext.DECIMAL128);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   191
        failures += testRoundingFromBigInteger(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   192
                new BigInteger("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   193
                177, MathContext.DECIMAL128);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   194
        failures += testRoundingFromBigInteger(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   195
                new BigInteger("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   196
                177, MathContext.DECIMAL32);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   197
        failures += testRoundingFromBigInteger(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   198
                new BigInteger("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   199
                177, MathContext.UNLIMITED);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   200
        failures += testRoundingFromBigInteger(
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   201
                new BigInteger("85070591730234615847396907784232501249"),
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   202
                0, MathContext.UNLIMITED);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   203
        return failures;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   204
    }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   205
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   206
    private static int minLongConstructorTest(MathContext mc) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   207
        int failures = 0;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   208
        BigDecimal bd1 = new BigDecimal(Long.MIN_VALUE,mc);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   209
        BigDecimal bd2 = new BigDecimal(Long.MIN_VALUE).round(mc);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   210
        if (!bd1.equals(bd2)) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   211
            System.out.println("new BigDecimal(long,MathContext):" +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   212
                    "long == " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   213
                    Long.MIN_VALUE + "; result == " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   214
                    bd1 + "; expected  == " +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   215
                    bd2
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   216
            );
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   217
            failures++;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   218
        }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   219
        return failures;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   220
    }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   221
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   222
    private static int minLongConstructorTest() {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   223
        int failures = 0;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   224
        failures+=minLongConstructorTest(MathContext.UNLIMITED);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   225
        failures+=minLongConstructorTest(MathContext.DECIMAL32);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   226
        failures+=minLongConstructorTest(MathContext.DECIMAL64);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   227
        failures+=minLongConstructorTest(MathContext.DECIMAL128);
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   228
        return failures;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   229
    }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   230
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   231
    public static void main(String argv[]) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   232
        int failures = 0;
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   233
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   234
        failures += addBoundaryTest();
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   235
        failures += roundingConstructorTest();
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   236
        failures += minLongConstructorTest();
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   237
        if (failures > 0) {
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   238
            throw new RuntimeException("Incurred " + failures +
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   239
                                       " failures while testing.");
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   240
        }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   241
    }
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   242
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   243
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   244
4cfc3523e112 7036582: Improve test coverage of java.math.BigDecimal
alanb
parents:
diff changeset
   245
}