Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/math/BigDecimal/LongValueExactTests.java
38812 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 680626126* @summary Tests of BigDecimal.longValueExact27*/28import java.math.*;2930public class LongValueExactTests {3132private static int longValueExactTests() {33int failures = 0;3435String[] testStrings = {36"9223372036854775807",37"9223372036854775807.0",38"9223372036854775807.00",39"-9223372036854775808",40"-9223372036854775808.0",41"-9223372036854775808.00",42};4344for (String longValue : testStrings) {45try {46BigDecimal bd = new BigDecimal(longValue);47long longValueExact = bd.longValueExact();48} catch (Exception e) {49failures++;50}51}5253// The following Strings are supposed to make longValueExact throw54// ArithmeticException.55String[] testStrings2 = {56"9223372036854775808",57"9223372036854775808.0",58"9223372036854775808.00",59"-9223372036854775809",60"-9223372036854775808.1",61"-9223372036854775808.01",62};6364for (String bigValue : testStrings2) {65try {66BigDecimal bd = new BigDecimal(bigValue);67long longValueExact = bd.longValueExact();68failures++;69} catch (ArithmeticException e) {70// Success;71}72}73return failures;74}7576public static void main(String argv[]) {77int failures = 0;7879failures += longValueExactTests();8081if (failures > 0) {82throw new RuntimeException("Incurred " + failures +83" failures while testing longValueExact.");84}85}86}878889