harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r389715 [9/12] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/math/META-INF/ modules/math/make/ modules/math/make/common/ modules/math/src/main/java/java/math/ modules/math/src/test/java/org/ modules/math/src/test/java/org/a...
Date Wed, 29 Mar 2006 09:01:07 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/math/BigIntegerMultiplyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/math/BigIntegerMultiplyTest.java?rev=389715&r1=389571&r2=389715&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/math/BigIntegerMultiplyTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/math/BigIntegerMultiplyTest.java
Wed Mar 29 01:01:04 2006
@@ -1,389 +1,389 @@
-/*
- *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-/**
- * @author Elena Semukhina
- * @version $Revision: 1.6.2.2 $
- */
-
-package java.math;
-
-import junit.framework.TestCase;
-import java.math.BigInteger;
-
-/**
- * Class:  java.math.BigInteger
- * Method: multiply 
- */
-public class BigIntegerMultiplyTest extends TestCase {
-    /**
-     * Multiply two negative numbers of the same length
-     */
-    public void testCase1() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
-        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
-        int aSign = -1;
-        int bSign = -1;        
-        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 105, 4, 28, -86, -117,
-52, 100, 120, 90};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * Multiply two numbers of the same length and different signs.
-     * The first is negative.
-     */
-    public void testCase2() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
-        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
-        int aSign = -1;
-        int bSign = 1;        
-        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -106, -5, -29,
85, 116, 51, -101, -121, -90};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-
-    /**
-     * Multiply two positive numbers of different length.
-     * The first is longer.
-     */
-    public void testCase3() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 115, 44, -127, 
-                         115, -21, -62, -15, 85, 64, -87, -2, -36, -36, -106};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * Multiply two positive numbers of different length.
-     * The second is longer.
-     */
-    public void testCase4() {
-        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
-        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 115, 44, -127, 
-                         115, -21, -62, -15, 85, 64, -87, -2, -36, -36, -106};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * Multiply two numbers of different length and different signs.
-     * The first is positive.
-     * The first is longer.
-     */
-    public void testCase5() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -116, -45, 126,
-                         -116, 20, 61, 14, -86, -65, 86, 1, 35, 35, 106};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-
-    /**
-     * Multiply two numbers of different length and different signs.
-     * The first is positive.
-     * The second is longer.
-     */
-    public void testCase6() {
-        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
-        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -116, -45, 126,
-                         -116, 20, 61, 14, -86, -65, 86, 1, 35, 35, 106};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-
-    /**
-     * Multiply a number by zero.
-     */
-    public void testCase7() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        byte bBytes[] = {0};
-        int aSign = 1;
-        int bSign = 0;        
-        byte rBytes[] = {0};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 0);
-    }
-
-    /**
-     * Multiply a number by ZERO.
-     */
-    public void testCase8() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        int aSign = 1;
-        byte rBytes[] = {0};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = BigInteger.ZERO;
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 0);
-    }
-
-    /**
-     * Multiply a positive number by ONE.
-     */
-    public void testCase9() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        int aSign = 1;
-        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = BigInteger.ONE;
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * Multiply a negative number by ONE.
-     */
-    public void testCase10() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
-        int aSign = -1;
-        byte rBytes[] = {-2, -3, -4, -5, -6, -7, -8, -2, -3, -4, -2, -3, -4, -5, -5};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = BigInteger.ONE;
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-    
-    /**
-     * Multiply two numbers of 4 bytes length.
-     */
-    public void testIntbyInt1() {
-        byte aBytes[] = {10, 20, 30, 40};
-        byte bBytes[] = {1, 2, 3, 4};
-        int aSign = 1;
-        int bSign = -1;        
-        byte rBytes[] = {-11, -41, -101, 55, 5, 15, 96};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-    
-    /**
-     * Multiply two numbers of 4 bytes length.
-     */
-    public void testIntbyInt2() {
-        byte aBytes[] = {-1, -1, -1, -1};
-        byte bBytes[] = {-1, -1, -1, -1};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {0, -1, -1, -1, -2, 0, 0, 0, 1};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.multiply(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-    
-    /**
-     * Negative exponent.
-     */
-    public void testPowException() {
-        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
-        int aSign = 1;
-        int exp = -5;
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        try {
-            BigInteger result = aNumber.pow(exp);
-            fail("ArithmeticException has not been caught");
-        } catch (ArithmeticException e) {
-            assertTrue("Improper exception message", e.getMessage().equals("exponent is negative"));
-        }
-    }
-
-    /**
-     * Exponentiation of a negative number to an odd exponent.
-     */
-    public void testPowNegativeNumToOddExp() {
-        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
-        int aSign = -1;
-        int exp = 5;
-        byte rBytes[] = {-21, -94, -42, -15, -127, 113, -50, -88, 115, -35, 3,
-            59, -92, 111, -75, 103, -42, 41, 34, -114, 99, -32, 105, -59, 127,
-            45, 108, 74, -93, 105, 33, 12, -5, -20, 17, -21, -119, -127, -115,
-            27, -122, 26, -67, 109, -125, 16, 91, -70, 109};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger result = aNumber.pow(exp);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-
-    /**
-     * Exponentiation of a negative number to an even exponent.
-     */
-    public void testPowNegativeNumToEvenExp() {
-        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
-        int aSign = -1;
-        int exp = 4;
-        byte rBytes[] = {102, 107, -122, -43, -52, -20, -27, 25, -9, 88, -13,
-            75, 78, 81, -33, -77, 39, 27, -37, 106, 121, -73, 108, -47, -101,
-            80, -25, 71, 13, 94, -7, -33, 1, -17, -65, -70, -61, -3, -47};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger result = aNumber.pow(exp);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * Exponentiation of a negative number to zero exponent.
-     */
-    public void testPowNegativeNumToZeroExp() {
-        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
-        int aSign = -1;
-        int exp = 0;
-        byte rBytes[] = {1};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger result = aNumber.pow(exp);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * Exponentiation of a positive number.
-     */
-    public void testPowPositiveNum() {
-        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
-        int aSign = 1;
-        int exp = 5;
-        byte rBytes[] = {20, 93, 41, 14, 126, -114, 49, 87, -116, 34, -4, -60,
-            91, -112, 74, -104, 41, -42, -35, 113, -100, 31, -106, 58, -128,
-            -46, -109, -75, 92, -106, -34, -13, 4, 19, -18, 20, 118, 126, 114,
-            -28, 121, -27, 66, -110, 124, -17, -92, 69, -109};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger result = aNumber.pow(exp);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * Exponentiation of a negative number to zero exponent.
-     */
-    public void testPowPositiveNumToZeroExp() {
-        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
-        int aSign = 1;
-        int exp = 0;
-        byte rBytes[] = {1};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger result = aNumber.pow(exp);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-}
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Elena Semukhina
+ * @version $Revision: 1.6.2.2 $
+ */
+
+package org.apache.harmony.tests.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:  java.math.BigInteger
+ * Method: multiply 
+ */
+public class BigIntegerMultiplyTest extends TestCase {
+    /**
+     * Multiply two negative numbers of the same length
+     */
+    public void testCase1() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 105, 4, 28, -86, -117,
-52, 100, 120, 90};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Multiply two numbers of the same length and different signs.
+     * The first is negative.
+     */
+    public void testCase2() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -106, -5, -29,
85, 116, 51, -101, -121, -90};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Multiply two positive numbers of different length.
+     * The first is longer.
+     */
+    public void testCase3() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 115, 44, -127, 
+                         115, -21, -62, -15, 85, 64, -87, -2, -36, -36, -106};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Multiply two positive numbers of different length.
+     * The second is longer.
+     */
+    public void testCase4() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {10, 40, 100, -55, 96, 51, 76, 40, -45, 85, 115, 44, -127, 
+                         115, -21, -62, -15, 85, 64, -87, -2, -36, -36, -106};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Multiply two numbers of different length and different signs.
+     * The first is positive.
+     * The first is longer.
+     */
+    public void testCase5() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -116, -45, 126,
+                         -116, 20, 61, 14, -86, -65, 86, 1, 35, 35, 106};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Multiply two numbers of different length and different signs.
+     * The first is positive.
+     * The second is longer.
+     */
+    public void testCase6() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-11, -41, -101, 54, -97, -52, -77, -41, 44, -86, -116, -45, 126,
+                         -116, 20, 61, 14, -86, -65, 86, 1, 35, 35, 106};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Multiply a number by zero.
+     */
+    public void testCase7() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        byte bBytes[] = {0};
+        int aSign = 1;
+        int bSign = 0;        
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 0);
+    }
+
+    /**
+     * Multiply a number by ZERO.
+     */
+    public void testCase8() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = 1;
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 0);
+    }
+
+    /**
+     * Multiply a positive number by ONE.
+     */
+    public void testCase9() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = 1;
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Multiply a negative number by ONE.
+     */
+    public void testCase10() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 1, 2, 3, 4, 5};
+        int aSign = -1;
+        byte rBytes[] = {-2, -3, -4, -5, -6, -7, -8, -2, -3, -4, -2, -3, -4, -5, -5};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+    
+    /**
+     * Multiply two numbers of 4 bytes length.
+     */
+    public void testIntbyInt1() {
+        byte aBytes[] = {10, 20, 30, 40};
+        byte bBytes[] = {1, 2, 3, 4};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-11, -41, -101, 55, 5, 15, 96};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+    
+    /**
+     * Multiply two numbers of 4 bytes length.
+     */
+    public void testIntbyInt2() {
+        byte aBytes[] = {-1, -1, -1, -1};
+        byte bBytes[] = {-1, -1, -1, -1};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {0, -1, -1, -1, -2, 0, 0, 0, 1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.multiply(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+    
+    /**
+     * Negative exponent.
+     */
+    public void testPowException() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        int exp = -5;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        try {
+            BigInteger result = aNumber.pow(exp);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("exponent is negative"));
+        }
+    }
+
+    /**
+     * Exponentiation of a negative number to an odd exponent.
+     */
+    public void testPowNegativeNumToOddExp() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = -1;
+        int exp = 5;
+        byte rBytes[] = {-21, -94, -42, -15, -127, 113, -50, -88, 115, -35, 3,
+            59, -92, 111, -75, 103, -42, 41, 34, -114, 99, -32, 105, -59, 127,
+            45, 108, 74, -93, 105, 33, 12, -5, -20, 17, -21, -119, -127, -115,
+            27, -122, 26, -67, 109, -125, 16, 91, -70, 109};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Exponentiation of a negative number to an even exponent.
+     */
+    public void testPowNegativeNumToEvenExp() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = -1;
+        int exp = 4;
+        byte rBytes[] = {102, 107, -122, -43, -52, -20, -27, 25, -9, 88, -13,
+            75, 78, 81, -33, -77, 39, 27, -37, 106, 121, -73, 108, -47, -101,
+            80, -25, 71, 13, 94, -7, -33, 1, -17, -65, -70, -61, -3, -47};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Exponentiation of a negative number to zero exponent.
+     */
+    public void testPowNegativeNumToZeroExp() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = -1;
+        int exp = 0;
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Exponentiation of a positive number.
+     */
+    public void testPowPositiveNum() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = 1;
+        int exp = 5;
+        byte rBytes[] = {20, 93, 41, 14, 126, -114, 49, 87, -116, 34, -4, -60,
+            91, -112, 74, -104, 41, -42, -35, 113, -100, 31, -106, 58, -128,
+            -46, -109, -75, 92, -106, -34, -13, 4, 19, -18, 20, 118, 126, 114,
+            -28, 121, -27, 66, -110, 124, -17, -92, 69, -109};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Exponentiation of a negative number to zero exponent.
+     */
+    public void testPowPositiveNumToZeroExp() {
+        byte aBytes[] = {50, -26, 90, 69, 120, 32, 63, -103, -14, 35};
+        int aSign = 1;
+        int exp = 0;
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.pow(exp);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/math/BigIntegerNotTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/math/BigIntegerNotTest.java?rev=389715&r1=389571&r2=389715&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/math/BigIntegerNotTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/math/BigIntegerNotTest.java
Wed Mar 29 01:01:04 2006
@@ -1,192 +1,192 @@
-/*
- *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-/**
- * @author Elena Semukhina
- * @version $Revision: 1.3.6.2 $
- */
-
-package java.math;
-
-import junit.framework.TestCase;
-import java.math.BigInteger;
-
-/**
- * Class:  java.math.BigInteger
- * Methods: and, andNot
- */
-public class BigIntegerNotTest extends TestCase {
-    /**
-     * andNot for two positive numbers; the first is longer
-     */
-    public void testAndNotPosPosFirstLonger() {
-        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23,
87, -25, -75};
-        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {0, -128, 9, 56, 100, 0, 0, 1, 1, 90, 1, -32, 0, 10, -126, 21, 82,
-31, -96};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.andNot(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * andNot for two positive numbers; the first is shorter
-     */
-    public void testAndNotPosPosFirstShorter() {
-        byte aBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
-        byte bBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23,
87, -25, -75};
-        int aSign = 1;
-        int bSign = 1;        
-        byte rBytes[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 2};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.andNot(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * andNot for two negative numbers; the first is longer
-     */
-    public void testAndNotNegNegFirstLonger() {
-        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23,
87, -25, -75};
-        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
-        int aSign = -1;
-        int bSign = -1;        
-        byte rBytes[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 2};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.andNot(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * andNot for a negative and a positive numbers; the first is longer
-     */
-    public void testNegPosFirstLonger() {
-        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23,
87, -25, -75};
-        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
-        int aSign = -1;
-        int bSign = 1;        
-        byte rBytes[] = {-1, 127, -10, -57, -101, 1, 2, 2, 2, -96, -16, 8, -40, -59, 68,
-88, -88, 16, 72};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger bNumber = new BigInteger(bSign, bBytes);
-        BigInteger result = aNumber.andNot(bNumber);
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-
-    /**
-     * Not for ZERO 
-     */
-    public void testNotZero() {
-        byte rBytes[] = {-1};
-        BigInteger aNumber = BigInteger.ZERO;
-        BigInteger result = aNumber.not();
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-
-    /**
-     * Not for ONE
-     */
-    public void testNotOne() {
-        byte rBytes[] = {-2};
-        BigInteger aNumber = BigInteger.ONE;
-        BigInteger result = aNumber.not();
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-
-    /**
-     * Not for a positive number
-     */
-    public void testNotPos() {
-        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
-        int aSign = 1;
-        byte rBytes[] = {-1, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -27, 116};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger result = aNumber.not();
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
-
-    /**
-     * Not for a negative number
-     */
-    public void testNotNeg() {
-        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
-        int aSign = -1;
-        byte rBytes[] = {0, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -118};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger result = aNumber.not();
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == 1);
-    }
-
-    /**
-     * Not for a negative number
-     */
-
-    public void testNotSpecialCase() {
-        byte aBytes[] = {-1, -1, -1, -1};
-        int aSign = 1;
-        byte rBytes[] = {-1, 0, 0, 0, 0};
-        BigInteger aNumber = new BigInteger(aSign, aBytes);
-        BigInteger result = aNumber.not();
-        byte resBytes[] = new byte[rBytes.length];
-        resBytes = result.toByteArray();
-        for(int i = 0; i < resBytes.length; i++) {
-            assertTrue(resBytes[i] == rBytes[i]);
-        }
-        assertTrue("incorrect sign", result.signum() == -1);
-    }
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Elena Semukhina
+ * @version $Revision: 1.3.6.2 $
+ */
+
+package org.apache.harmony.tests.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:  java.math.BigInteger
+ * Methods: and, andNot
+ */
+public class BigIntegerNotTest extends TestCase {
+    /**
+     * andNot for two positive numbers; the first is longer
+     */
+    public void testAndNotPosPosFirstLonger() {
+        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23,
87, -25, -75};
+        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {0, -128, 9, 56, 100, 0, 0, 1, 1, 90, 1, -32, 0, 10, -126, 21, 82,
-31, -96};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.andNot(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * andNot for two positive numbers; the first is shorter
+     */
+    public void testAndNotPosPosFirstShorter() {
+        byte aBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        byte bBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23,
87, -25, -75};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 2};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.andNot(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * andNot for two negative numbers; the first is longer
+     */
+    public void testAndNotNegNegFirstLonger() {
+        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23,
87, -25, -75};
+        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 2};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.andNot(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * andNot for a negative and a positive numbers; the first is longer
+     */
+    public void testNegPosFirstLonger() {
+        byte aBytes[] = {-128, 9, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117, 23,
87, -25, -75};
+        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-1, 127, -10, -57, -101, 1, 2, 2, 2, -96, -16, 8, -40, -59, 68,
-88, -88, 16, 72};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.andNot(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Not for ZERO 
+     */
+    public void testNotZero() {
+        byte rBytes[] = {-1};
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Not for ONE
+     */
+    public void testNotOne() {
+        byte rBytes[] = {-2};
+        BigInteger aNumber = BigInteger.ONE;
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Not for a positive number
+     */
+    public void testNotPos() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
+        int aSign = 1;
+        byte rBytes[] = {-1, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -27, 116};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
+
+    /**
+     * Not for a negative number
+     */
+    public void testNotNeg() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
+        int aSign = -1;
+        byte rBytes[] = {0, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -118};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * Not for a negative number
+     */
+
+    public void testNotSpecialCase() {
+        byte aBytes[] = {-1, -1, -1, -1};
+        int aSign = 1;
+        byte rBytes[] = {-1, 0, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.not();
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == -1);
+    }
 }



Mime
View raw message