181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes/* 281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Licensed to the Apache Software Foundation (ASF) under one or more 381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * contributor license agreements. See the NOTICE file distributed with 481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * this work for additional information regarding copyright ownership. 581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * (the "License"); you may not use this file except in compliance with 781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * the License. You may obtain a copy of the License at 881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * 981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 1081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * 1181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Unless required by applicable law or agreed to in writing, software 1281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 1381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * See the License for the specific language governing permissions and 1581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * limitations under the License. 1681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 1781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes/** 1881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * @author Elena Semukhina 1981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 2081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 2181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughespackage org.apache.harmony.tests.java.math; 2281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 2381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughesimport junit.framework.TestCase; 2481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughesimport java.math.BigInteger; 2581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 2681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes/** 2781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Class: java.math.BigInteger 2881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Method: multiply 2981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 3081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughespublic class BigIntegerMultiplyTest extends TestCase { 3181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 3281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply two negative numbers of the same length 3381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 3481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase1() { 3581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3}; 3681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30}; 3781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = -1; 3881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = -1; 3981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 105, 4, 28, -86, -117, -52, 100, 120, 90}; 4081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 4181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 4281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 4381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 4481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 4581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 4681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 4781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 4881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 4981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 5081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 5181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 5281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply two numbers of the same length and different signs. 5381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * The first is negative. 5481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 5581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase2() { 5681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3}; 5781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30}; 5881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = -1; 5981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = 1; 6081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -106, -5, -29, 85, 116, 51, -101, -121, -90}; 6181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 6281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 6381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 6481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 6581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 6681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 6781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 6881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 6981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", -1, result.signum()); 7081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 7181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 7281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 7381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply two positive numbers of different length. 7481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * The first is longer. 7581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 7681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase3() { 7781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 7881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30}; 7981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 8081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = 1; 8181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 115, 44, -127, 8281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 115, -21, -62, -15, 85, 64, -87, -2, -36, -36, -106}; 8381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 8481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 8581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 8681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 8781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 8881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 8981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 9081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 9181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 9281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 9381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 9481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 9581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply two positive numbers of different length. 9681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * The second is longer. 9781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 9881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase4() { 9981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30}; 10081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 10181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 10281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = 1; 10381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 115, 44, -127, 10481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 115, -21, -62, -15, 85, 64, -87, -2, -36, -36, -106}; 10581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 10681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 10781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 10881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 10981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 11081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 11181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 11281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 11381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 11481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 11581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 11681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 11781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply two numbers of different length and different signs. 11881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * The first is positive. 11981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * The first is longer. 12081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 12181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase5() { 12281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 12381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30}; 12481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 12581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = -1; 12681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -116, -45, 126, 12781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes -116, 20, 61, 14, -86, -65, 86, 1, 35, 35, 106}; 12881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 12981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 13081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 13181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 13281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 13381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 13481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 13581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 13681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", -1, result.signum()); 13781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 13881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 13981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 14081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply two numbers of different length and different signs. 14181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * The first is positive. 14281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * The second is longer. 14381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 14481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase6() { 14581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30}; 14681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 14781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 14881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = -1; 14981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -116, -45, 126, 15081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes -116, 20, 61, 14, -86, -65, 86, 1, 35, 35, 106}; 15181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 15281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 15381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 15481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 15581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 15681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 15781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 15881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 15981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", -1, result.signum()); 16081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 16181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 16281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 16381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply a number by zero. 16481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 16581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase7() { 16681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 16781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {0}; 16881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 16981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = 0; 17081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {0}; 17181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 17281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 17381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 17481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 17581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 17681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 17781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 17881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 17981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 0, result.signum()); 18081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 18181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 18281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 18381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply a number by ZERO. 18481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 18581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase8() { 18681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 18781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 18881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {0}; 18981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 19081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = BigInteger.ZERO; 19181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 19281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 19381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 19481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 19581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 19681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 19781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 0, result.signum()); 19881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 19981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 20081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 20181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply a positive number by ONE. 20281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 20381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase9() { 20481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 20581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 20681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 20781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 20881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = BigInteger.ONE; 20981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 21081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 21181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 21281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 21381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 21481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 21581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 21681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 21781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 21881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 21981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply a negative number by ONE. 22081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 22181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testCase10() { 22281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5}; 22381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = -1; 22481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {-2, -3, -4, -5, -6, -7, -8, -2, -3, -4, -2, -3, -4, -5, -5}; 22581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 22681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = BigInteger.ONE; 22781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 22881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 22981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 23081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 23181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 23281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 23381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", -1, result.signum()); 23481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 23581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 23681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 23781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply two numbers of 4 bytes length. 23881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 23981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testIntbyInt1() { 24081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {10, 20, 30, 40}; 24181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {1, 2, 3, 4}; 24281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 24381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = -1; 24481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {-11, -41, -101, 55, 5, 15, 96}; 24581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 24681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 24781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 24881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 24981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 25081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 25181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 25281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 25381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", -1, result.signum()); 25481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 25581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 25681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 25781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Multiply two numbers of 4 bytes length. 25881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 25981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testIntbyInt2() { 26081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {-1, -1, -1, -1}; 26181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte bBytes[] = {-1, -1, -1, -1}; 26281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 26381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int bSign = 1; 26481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {0, -1, -1, -1, -2, 0, 0, 0, 1}; 26581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 26681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger bNumber = new BigInteger(bSign, bBytes); 26781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.multiply(bNumber); 26881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 26981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 27081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 27181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 27281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 27381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 27481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 27581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 27681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 27781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Negative exponent. 27881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 27981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testPowException() { 28081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {1, 2, 3, 4, 5, 6, 7}; 28181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 28281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int exp = -5; 28381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 28481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes try { 28581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes aNumber.pow(exp); 28681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes fail("ArithmeticException has not been caught"); 28781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } catch (ArithmeticException e) { 28881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 28981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 29081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 29181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 29281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Exponentiation of a negative number to an odd exponent. 29381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 29481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testPowNegativeNumToOddExp() { 29581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35}; 29681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = -1; 29781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int exp = 5; 29881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {-21, -94, -42, -15, -127, 113, -50, -88, 115, -35, 3, 29981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 59, -92, 111, -75, 103, -42, 41, 34, -114, 99, -32, 105, -59, 127, 30081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 45, 108, 74, -93, 105, 33, 12, -5, -20, 17, -21, -119, -127, -115, 30181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 27, -122, 26, -67, 109, -125, 16, 91, -70, 109}; 30281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 30381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.pow(exp); 30481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 30581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 30681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 30781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 30881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 30981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", -1, result.signum()); 31081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 31181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 31281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 31381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Exponentiation of a negative number to an even exponent. 31481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 31581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testPowNegativeNumToEvenExp() { 31681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35}; 31781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = -1; 31881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int exp = 4; 31981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {102, 107, -122, -43, -52, -20, -27, 25, -9, 88, -13, 32081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 75, 78, 81, -33, -77, 39, 27, -37, 106, 121, -73, 108, -47, -101, 32181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 80, -25, 71, 13, 94, -7, -33, 1, -17, -65, -70, -61, -3, -47}; 32281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 32381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.pow(exp); 32481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 32581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 32681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 32781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 32881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 32981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 33081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 33181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 33281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 33381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Exponentiation of a negative number to zero exponent. 33481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 33581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testPowNegativeNumToZeroExp() { 33681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35}; 33781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = -1; 33881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int exp = 0; 33981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {1}; 34081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 34181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.pow(exp); 34281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 34381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 34481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 34581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 34681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 34781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 34881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 34981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 35081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 35181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Exponentiation of a positive number. 35281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 35381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testPowPositiveNum() { 35481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35}; 35581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 35681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int exp = 5; 35781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {20, 93, 41, 14, 126, -114, 49, 87, -116, 34, -4, -60, 35881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 91, -112, 74, -104, 41, -42, -35, 113, -100, 31, -106, 58, -128, 35981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes -46, -109, -75, 92, -106, -34, -13, 4, 19, -18, 20, 118, 126, 114, 36081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes -28, 121, -27, 66, -110, 124, -17, -92, 69, -109}; 36181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 36281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.pow(exp); 36381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 36481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 36581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 36681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 36781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 36881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 36981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 37081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes 37181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes /** 37281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes * Exponentiation of a negative number to zero exponent. 37381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes */ 37481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes public void testPowPositiveNumToZeroExp() { 37581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35}; 37681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int aSign = 1; 37781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes int exp = 0; 37881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte rBytes[] = {1}; 37981ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger aNumber = new BigInteger(aSign, aBytes); 38081ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes BigInteger result = aNumber.pow(exp); 38181ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes byte resBytes[] = new byte[rBytes.length]; 38281ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes resBytes = result.toByteArray(); 38381ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes for(int i = 0; i < resBytes.length; i++) { 38481ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertTrue(resBytes[i] == rBytes[i]); 38581ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 38681ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes assertEquals("incorrect sign", 1, result.signum()); 38781ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes } 38881ccea015ba3d2a2da1c641b14dd3713c6b40a76Elliott Hughes} 389