Path: blob/master/test/jdk/java/math/BigDecimal/MultiplyTests.java
41149 views
/*1* Copyright (c) 2006, 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 685060626* @summary Test BigDecimal.multiply(BigDecimal)27* @author xlu28*/2930import java.math.*;31import static java.math.BigDecimal.*;3233public class MultiplyTests {3435private static int multiplyTests() {36int failures = 0;3738BigDecimal[] bd1 = {39new BigDecimal("123456789"),40new BigDecimal("1234567898"),41new BigDecimal("12345678987")42};4344BigDecimal[] bd2 = {45new BigDecimal("987654321"),46new BigDecimal("8987654321"),47new BigDecimal("78987654321")48};4950// Two dimensonal array recording bd1[i] * bd2[j] &51// 0 <= i <= 2 && 0 <= j <= 2;52BigDecimal[][] expectedResults = {53{new BigDecimal("121932631112635269"),54new BigDecimal("1109586943112635269"),55new BigDecimal("9751562173112635269")56},57{ new BigDecimal("1219326319027587258"),58new BigDecimal("11095869503027587258"),59new BigDecimal("97515622363027587258")60},61{ new BigDecimal("12193263197189452827"),62new BigDecimal("110958695093189452827"),63new BigDecimal("975156224183189452827")64}65};6667for (int i = 0; i < bd1.length; i++) {68for (int j = 0; j < bd2.length; j++) {69if (!bd1[i].multiply(bd2[j]).equals(expectedResults[i][j])) {70failures++;71}72}73}7475BigDecimal x = BigDecimal.valueOf(8L, 1);76BigDecimal xPower = BigDecimal.valueOf(-1L);77try {78for (int i = 0; i < 100; i++) {79xPower = xPower.multiply(x);80}81} catch (Exception ex) {82failures++;83}84return failures;85}8687public static void main(String[] args) {88int failures = 0;8990failures += multiplyTests();9192if (failures > 0) {93throw new RuntimeException("Incurred " + failures +94" failures while testing multiply.");95}96}97}9899100