1 /* 2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package test.java.math.BigDecimal; 24 25 /* 26 * @test 27 * @bug 6850606 28 * @summary Test BigDecimal.multiply(BigDecimal) 29 * @author xlu 30 */ 31 32 import java.math.*; 33 import static java.math.BigDecimal.*; 34 35 import org.testng.Assert; 36 import org.testng.annotations.Test; 37 38 // Android-changed: Replace error counting with asserts. 39 public class MultiplyTests { 40 41 @Test multiplyTests()42 public void multiplyTests() { 43 BigDecimal[] bd1 = { 44 new BigDecimal("123456789"), 45 new BigDecimal("1234567898"), 46 new BigDecimal("12345678987") 47 }; 48 49 BigDecimal[] bd2 = { 50 new BigDecimal("987654321"), 51 new BigDecimal("8987654321"), 52 new BigDecimal("78987654321") 53 }; 54 55 // Two dimensional array recording bd1[i] * bd2[j] & 56 // 0 <= i <= 2 && 0 <= j <= 2; 57 BigDecimal[][] expectedResults = { 58 {new BigDecimal("121932631112635269"), 59 new BigDecimal("1109586943112635269"), 60 new BigDecimal("9751562173112635269") 61 }, 62 { new BigDecimal("1219326319027587258"), 63 new BigDecimal("11095869503027587258"), 64 new BigDecimal("97515622363027587258") 65 }, 66 { new BigDecimal("12193263197189452827"), 67 new BigDecimal("110958695093189452827"), 68 new BigDecimal("975156224183189452827") 69 } 70 }; 71 72 for (int i = 0; i < bd1.length; i++) { 73 for (int j = 0; j < bd2.length; j++) { 74 Assert.assertEquals(bd1[i].multiply(bd2[j]), expectedResults[i][j], 75 bd1[i] + " * " + bd2[j] + " + is " + bd1[i].multiply(bd2[j]) + 76 " but expected: " + expectedResults[i][j]); 77 } 78 } 79 80 BigDecimal x = BigDecimal.valueOf(8L, 1); 81 BigDecimal xPower = BigDecimal.valueOf(-1L); 82 try { 83 for (int i = 0; i < 100; i++) { 84 xPower = xPower.multiply(x); 85 } 86 } catch (Exception ex) { 87 Assert.fail("Unexpected exception: " + ex.getMessage()); 88 } 89 } 90 } 91