harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r387239 [20/21] - in /incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math: ./ Harmony/ doc/ doc/images/ make/ src/ src/common/ src/common/javasrc/ src/common/javasrc/java/ src/common/javasrc/java/applet/ src/common/javasrc/ja...
Date Mon, 20 Mar 2006 16:31:33 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerOperateBitsTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerOperateBitsTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerOperateBitsTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerOperateBitsTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,1379 @@
+/*
+ *  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.10.2.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:   java.math.BigInteger
+ * Methods: bitLength, shiftLeft, shiftRight,
+ * clearBit, flipBit, setBit, testBit
+ */
+public class BigIntegerOperateBitsTest extends TestCase {
+    /**
+     * bitCount() of zero.
+     */
+    public void testBitCountZero() {
+        BigInteger aNumber = new BigInteger("0");
+        assertTrue(aNumber.bitCount() == 0);
+    }
+
+    /**
+     * bitCount() of a negative number.
+     */
+    public void testBitCountNeg() {
+        BigInteger aNumber = new BigInteger("-12378634756382937873487638746283767238657872368748726875");
+        assertTrue(aNumber.bitCount() == 87);
+    }
+
+    /**
+     * bitCount() of a negative number.
+     */
+    public void testBitCountPos() {
+        BigInteger aNumber = new BigInteger("12378634756343564757582937873487638746283767238657872368748726875");
+        assertTrue(aNumber.bitCount() == 107);
+    }
+
+    /**
+     * bitLength() of zero.
+     */
+    public void testBitLengthZero() {
+        BigInteger aNumber = new BigInteger("0");
+        assertTrue(aNumber.bitLength() == 0);
+    }
+
+    /**
+     * bitLength() of a positive number.
+     */
+    public void testBitLengthPositive1() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.bitLength() == 108);
+    }
+
+    /**
+     * bitLength() of a positive number with the leftmost bit set
+     */
+    public void testBitLengthPositive2() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.bitLength() == 96);
+    }
+
+    /**
+     * bitLength() of a positive number which is a power of 2
+     */
+    public void testBitLengthPositive3() {
+        byte aBytes[] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+        int aSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.bitLength() == 81);
+    }
+
+    /**
+     * bitLength() of a negative number.
+     */
+    public void testBitLengthNegative1() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = -1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.bitLength() == 108);
+    }
+
+    /**
+     * bitLength() of a negative number with the leftmost bit set
+     */
+    public void testBitLengthNegative2() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.bitLength() == 96);
+    }
+    
+    /**
+     * bitLength() of a negative number which is a power of 2
+     */
+    public void testBitLengthNegative3() {
+        byte aBytes[] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+        int aSign = -1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.bitLength() == 80);
+    }
+
+    /**
+     * clearBit(int n) of a negative n
+     */
+    public void testClearBitException() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = -7;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        try {
+            BigInteger result = aNumber.clearBit(number);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("negative bit number"));
+        }
+    }
+
+    /**
+     * clearBit(int n) outside zero
+     */
+    public void testClearBitZero() {
+        byte aBytes[] = {0};
+        int aSign = 0;
+        int number = 0;
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) outside zero
+     */
+    public void testClearBitZeroOutside1() {
+        byte aBytes[] = {0};
+        int aSign = 0;
+        int number = 95;
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) inside a negative number
+     */
+    public void testClearBitNegativeInside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 15;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, 92, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) inside a negative number
+     */
+    public void testClearBitNegativeInside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 44;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -62, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(2) in the negative number with all ones in bit representation
+     */
+    public void testClearBitNegativeInside3() {
+        String as = "-18446744073709551615";
+        int number = 2;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.clearBit(number);
+        assertEquals(as, result.toString());
+    }
+
+    /**
+     * clearBit(0) in the negative number of length 1
+     * with all ones in bit representation.
+     * the resulting number's length is 2.
+     */
+    public void testClearBitNegativeInside4() {
+        String as = "-4294967295";
+        String res = "-4294967296";
+        int number = 0;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.clearBit(number);
+        assertEquals(res, result.toString());
+    }
+
+    /**
+     * clearBit(0) in the negative number of length 2
+     * with all ones in bit representation.
+     * the resulting number's length is 3.
+     */
+    public void testClearBitNegativeInside5() {
+        String as = "-18446744073709551615";
+        String res = "-18446744073709551616";
+        int number = 0;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.clearBit(number);
+        assertEquals(res, result.toString());
+    }
+
+    /**
+     * clearBit(int n) outside a negative number
+     */
+    public void testClearBitNegativeOutside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 150;
+        byte rBytes[] = {-65, -1, -1, -1, -1, -1, -2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) outside a negative number
+     */
+    public void testClearBitNegativeOutside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 165;
+        byte rBytes[] = {-33, -1, -1, -1, -1, -1, -1, -1, -2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) inside a positive number
+     */
+    public void testClearBitPositiveInside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 20;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -31, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) inside a positive number
+     */
+    public void testClearBitPositiveInside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 17;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) inside a positive number
+     */
+    public void testClearBitPositiveInside3() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 45;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 13, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) inside a positive number
+     */
+    public void testClearBitPositiveInside4 () {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 50;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) inside a positive number
+     */
+    public void testClearBitPositiveInside5 () {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 63;
+        byte rBytes[] = {1, -128, 56, 100, -2, 52, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) outside a positive number
+     */
+    public void testClearBitPositiveOutside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 150;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) outside a positive number
+     */
+    public void testClearBitPositiveOutside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 191;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * clearBit(int n) the leftmost bit in a negative number
+     */
+    public void testClearBitTopNegative() {
+        byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
+        int aSign = -1;
+        int number = 63;
+        byte rBytes[] = {-1, 127, -2, 127, -57, -101, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.clearBit(number);
+        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);
+    }
+
+    /**
+     * flipBit(int n) of a negative n
+     */
+    public void testFlipBitException() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = -7;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        try {
+            BigInteger result = aNumber.flipBit(number);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("negative bit number"));
+        }
+    }
+
+    /**
+     * flipBit(int n) zero
+     */
+    public void testFlipBitZero() {
+        byte aBytes[] = {0};
+        int aSign = 0;
+        int number = 0;
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+
+    /**
+     * flipBit(int n) outside zero
+     */
+    public void testFlipBitZeroOutside1() {
+        byte aBytes[] = {0};
+        int aSign = 0;
+        int number = 62;
+        byte rBytes[] = {64, 0, 0, 0, 0, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue("incorrect value", resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * flipBit(int n) outside zero
+     */
+    public void testFlipBitZeroOutside2() {
+        byte aBytes[] = {0};
+        int aSign = 0;
+        int number = 63;
+        byte rBytes[] = {0, -128, 0, 0, 0, 0, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        byte resBytes[] = new byte[rBytes.length];
+        resBytes = result.toByteArray();
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue("incorrect value", resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * flipBit(int n) the leftmost bit in a negative number
+     */
+    public void testFlipBitLeftmostNegative() {
+        byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
+        int aSign = -1;
+        int number = 48;
+        byte rBytes[] = {-1, 127, -57, -101, 14, -36, -26, 49};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+    
+    /**
+     * flipBit(int n) the leftmost bit in a positive number
+     */
+    public void testFlipBitLeftmostPositive() {
+        byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
+        int aSign = 1;
+        int number = 48;
+        byte rBytes[] = {0, -128, 56, 100, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+
+    /**
+     * flipBit(int n) inside a negative number
+     */
+    public void testFlipBitNegativeInside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 15;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, 92, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+
+    /**
+     * flipBit(int n) inside a negative number
+     */
+    public void testFlipBitNegativeInside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 45;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -14, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+
+    /**
+     * flipBit(int n) inside a negative number with all ones in bit representation 
+     */
+    public void testFlipBitNegativeInside3() {
+        String as = "-18446744073709551615";
+        String res = "-18446744073709551611";
+        int number = 2;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.flipBit(number);
+        assertEquals(res, result.toString());
+    }
+
+    /**
+     * flipBit(0) in the negative number of length 1
+     * with all ones in bit representation.
+     * the resulting number's length is 2.
+     */
+    public void testFlipBitNegativeInside4() {
+        String as = "-4294967295";
+        String res = "-4294967296";
+        int number = 0;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.flipBit(number);
+        assertEquals(res, result.toString());
+    }
+
+    /**
+     * flipBit(0) in the negative number of length 2
+     * with all ones in bit representation.
+     * the resulting number's length is 3.
+     */
+    public void testFlipBitNegativeInside5() {
+        String as = "-18446744073709551615";
+        String res = "-18446744073709551616";
+        int number = 0;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.flipBit(number);
+        assertEquals(res, result.toString());
+    }
+
+    /**
+     * flipBit(int n) outside a negative number
+     */
+    public void testFlipBitNegativeOutside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 150;
+        byte rBytes[] = {-65, -1, -1, -1, -1, -1, -2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+    
+    /**
+     * flipBit(int n) outside a negative number
+     */
+    public void testFlipBitNegativeOutside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 191;
+        byte rBytes[] = {-1, 127, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+    
+    /**
+     * flipBit(int n) inside a positive number
+     */
+    public void testFlipBitPositiveInside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 15;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, -93, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+
+    /**
+     * flipBit(int n) inside a positive number
+     */
+    public void testFlipBitPositiveInside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 45;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 13, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+
+    /**
+     * flipBit(int n) outside a positive number
+     */
+    public void testFlipBitPositiveOutside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 150;
+        byte rBytes[] = {64, 0, 0, 0, 0, 0, 1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+
+    /**
+     * flipBit(int n) outside a positive number
+     */
+    public void testFlipBitPositiveOutside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 191;
+        byte rBytes[] = {0, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.flipBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) of a negative n
+     */
+    public void testSetBitException() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = -7;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        try {
+            BigInteger result = aNumber.setBit(number);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("negative bit number"));
+        }
+    }
+
+    /**
+     * setBit(int n) outside zero
+     */
+    public void testSetBitZero() {
+        byte aBytes[] = {0};
+        int aSign = 0;
+        int number = 0;
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) outside zero
+     */
+    public void testSetBitZeroOutside1() {
+        byte aBytes[] = {0};
+        int aSign = 0;
+        int number = 95;
+        byte rBytes[] = {0, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) inside a positive number
+     */
+    public void testSetBitPositiveInside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 20;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) inside a positive number
+     */
+    public void testSetBitPositiveInside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 17;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -13, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) inside a positive number
+     */
+    public void testSetBitPositiveInside3() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 45;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) inside a positive number
+     */
+    public void testSetBitPositiveInside4 () {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 50;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 93, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) outside a positive number
+     */
+    public void testSetBitPositiveOutside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 150;
+        byte rBytes[] = {64, 0, 0, 0, 0, 0, 1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) outside a positive number
+     */
+    public void testSetBitPositiveOutside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 223;
+        byte rBytes[] = {0, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) the leftmost bit in a positive number
+     */
+    public void testSetBitTopPositive() {
+        byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
+        int aSign = 1;
+        int number = 63;
+        byte rBytes[] = {0, -128, 1, -128, 56, 100, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) the leftmost bit in a negative number
+     */
+    public void testSetBitLeftmostNegative() {
+        byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
+        int aSign = -1;
+        int number = 48;
+        byte rBytes[] = {-1, 127, -57, -101, 14, -36, -26, 49};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+    
+    /**
+     * setBit(int n) inside a negative number
+     */
+    public void testSetBitNegativeInside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 15;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) inside a negative number
+     */
+    public void testSetBitNegativeInside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 44;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+
+    /**
+     * setBit(int n) inside a negative number with all ones in bit representation
+     */
+    public void testSetBitNegativeInside3() {
+        String as = "-18446744073709551615";
+        String res = "-18446744073709551611";
+        int number = 2;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.setBit(number);
+        assertEquals(res, result.toString());
+    }
+
+    /**
+     * setBit(0) in the negative number of length 1
+     * with all ones in bit representation.
+     * the resulting number's length is 2.
+     */
+    public void testSetBitNegativeInside4() {
+        String as = "-4294967295";
+        int number = 0;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.setBit(number);
+        assertEquals(as, result.toString());
+    }
+
+    /**
+     * setBit(0) in the negative number of length 2
+     * with all ones in bit representation.
+     * the resulting number's length is 3.
+     */
+    public void testSetBitNegativeInside5() {
+        String as = "-18446744073709551615";
+        int number = 0;
+        BigInteger aNumber = new BigInteger(as);
+        BigInteger result = aNumber.setBit(number);
+        assertEquals(as, result.toString());
+    }
+
+    /**
+     * setBit(int n) outside a negative number
+     */
+    public void testSetBitNegativeOutside1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 150;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+    
+    /**
+     * setBit(int n) outside a negative number
+     */
+    public void testSetBitNegativeOutside2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 191;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.setBit(number);
+        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);
+    }
+    
+    /**
+     * setBit: check the case when the number of bit to be set can be
+     * represented as n * 32 + 31, where n is an arbitrary integer.
+     * Here 191 = 5 * 32 + 31 
+     */
+    public void testSetBitBug1331() {
+        BigInteger result = BigInteger.valueOf(0L).setBit(191);
+        assertTrue("incorrect value", result.toString().equals("3138550867693340381917894711603833208051177722232017256448"));
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+    
+    /**
+     * shiftLeft(int n), n = 0
+     */
+    public void testShiftLeft1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 0;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftLeft(number);
+        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);
+    }
+    
+    /**
+     * shiftLeft(int n), n < 0
+     */
+    public void testShiftLeft2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = -27;
+        byte rBytes[] = {48, 7, 12, -97, -42, -117, 37, -85, 96};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftLeft(number);
+        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);
+    }
+
+    /**
+     * shiftLeft(int n) a positive number, n > 0
+     */
+    public void testShiftLeft3() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 27;
+        byte rBytes[] = {12, 1, -61, 39, -11, -94, -55, 106, -40, 31, -119, 24, -48, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftLeft(number);
+        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);
+    }
+    
+    /**
+     * shiftLeft(int n) a positive number, n > 0
+     */
+    public void testShiftLeft4() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 45;
+        byte rBytes[] = {48, 7, 12, -97, -42, -117, 37, -85, 96, 126, 36, 99, 64, 0, 0, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftLeft(number);
+        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);
+    }
+
+    /**
+     * shiftLeft(int n) a negative number, n > 0
+     */
+    public void testShiftLeft5() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 45;
+        byte rBytes[] = {-49, -8, -13, 96, 41, 116, -38, 84, -97, -127, -37, -100, -64, 0, 0, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftLeft(number);
+        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);
+    }
+    
+    /**
+     * shiftRight(int n), n = 0
+     */
+    public void testShiftRight1() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 0;
+        byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+    
+    /**
+     * shiftRight(int n), n < 0
+     */
+    public void testShiftRight2() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = -27;
+        byte rBytes[] = {12, 1, -61, 39, -11, -94, -55, 106, -40, 31, -119, 24, -48, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+
+    /**
+     * shiftRight(int n), 0 < n < 32
+     */
+    public void testShiftRight3() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 27;
+        byte rBytes[] = {48, 7, 12, -97, -42, -117, 37, -85, 96};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+    
+    /**
+     * shiftRight(int n), n > 32
+     */
+    public void testShiftRight4() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 45;
+        byte rBytes[] = {12, 1, -61, 39, -11, -94, -55};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+
+    /**
+     * shiftRight(int n), n is greater than bitLength()
+     */
+    public void testShiftRight5() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 300;
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+    
+    /**
+     * shiftRight a negative number;
+     * shift distance is multiple of 32;
+     * shifted bits are NOT zeroes. 
+     */
+    public void testShiftRightNegNonZeroesMul32() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 1, 0, 0, 0, 0, 0, 0, 0};
+        int aSign = -1;
+        int number = 64;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+
+    /**
+     * shiftRight a negative number;
+     * shift distance is NOT multiple of 32;
+     * shifted bits are NOT zeroes. 
+     */
+    public void testShiftRightNegNonZeroes() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 0, 0, 0, 0, 0, 0, 0, 0};
+        int aSign = -1;
+        int number = 68;
+        byte rBytes[] = {-25, -4, 121, -80, 20, -70, 109, 42};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+
+    /**
+     * shiftRight a negative number;
+     * shift distance is NOT multiple of 32;
+     * shifted bits are zeroes. 
+     */
+    public void testShiftRightNegZeroes() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+        int aSign = -1;
+        int number = 68;
+        byte rBytes[] = {-25, -4, 121, -80, 20, -70, 109, 48};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+
+    /**
+     * shiftRight a negative number;
+     * shift distance is multiple of 32;
+     * shifted bits are zeroes. 
+     */
+    public void testShiftRightNegZeroesMul32() {
+        byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 0, 0, 0, 0, 0, 0, 0, 0};
+        int aSign = -1;
+        int number = 64;
+        byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.shiftRight(number);
+        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);
+    }
+
+    /**
+     * testBit(int n) of a negative n
+     */
+    public void testTestBitException() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = -7;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        try {
+            boolean result = aNumber.testBit(number);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("negative bit number"));
+        }
+    }
+
+    /**
+     * testBit(int n) of a positive number
+     */
+    public void testTestBitPositive1() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 7;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(!aNumber.testBit(number));
+    }
+
+    /**
+     * testBit(int n) of a positive number
+     */
+    public void testTestBitPositive2() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 45;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.testBit(number));
+    }
+    
+    /**
+     * testBit(int n) of a positive number, n > bitLength()
+     */
+    public void testTestBitPositive3() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = 1;
+        int number = 300;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(!aNumber.testBit(number));
+    }
+
+    /**
+     * testBit(int n) of a negative number
+     */
+    public void testTestBitNegative1() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 7;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.testBit(number));
+    }
+
+    /**
+     * testBit(int n) of a positive n
+     */
+    public void testTestBitNegative2() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 45;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(!aNumber.testBit(number));
+    }
+    
+    /**
+     * testBit(int n) of a positive n, n > bitLength()
+     */
+    public void testTestBitNegative3() {
+        byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
+        int aSign = -1;
+        int number = 300;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        assertTrue(aNumber.testBit(number));
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerOrTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerOrTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerOrTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerOrTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,410 @@
+/*
+ *  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.4.6.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:  java.math.BigInteger
+ * Method: or 
+ */
+public class BigIntegerOrTest extends TestCase {
+    /**
+     * Or for zero and a positive number
+     */
+    public void testZeroPos() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        int aSign = 0;
+        int bSign = 1;        
+        byte rBytes[] = {0, -2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for zero and a negative number
+     */
+    public void testZeroNeg() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        int aSign = 0;
+        int bSign = -1;        
+        byte rBytes[] = {-1, 1, 2, 3, 3, -6, -15, -24, -40, -49, -58, -67, -6, -15, -23};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for a positive number and zero 
+     */
+    public void testPosZero() {
+        byte aBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        byte bBytes[] = {0};
+        int aSign = 1;
+        int bSign = 0;        
+        byte rBytes[] = {0, -2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for a negative number and zero  
+     */
+    public void testNegPos() {
+        byte aBytes[] = {-2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5, 14, 23};
+        byte bBytes[] = {0};
+        int aSign = -1;
+        int bSign = 0;        
+        byte rBytes[] = {-1, 1, 2, 3, 3, -6, -15, -24, -40, -49, -58, -67, -6, -15, -23};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for zero and zero
+     */
+    public void testZeroZero() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {0};
+        int aSign = 0;
+        int bSign = 0;        
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for zero and one
+     */
+    public void testZeroOne() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {1};
+        int aSign = 0;
+        int bSign = 1;        
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for one and one
+     */
+    public void testOneOne() {
+        byte aBytes[] = {1};
+        byte bBytes[] = {1};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {1};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two positive numbers of the same length
+     */
+    public void testPosPosSameLength() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
+        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, -2, -3, -4, -4, -1, -66, 95, 47, 123, 59, -13, 39, 30, -97};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two positive numbers; the first is longer
+     */
+    public void testPosPosFirstLonger() {
+        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, -2, -3, -3, -3, 95, 15, -9, 39, 58, -69, 87, 87, -17, -73};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two positive numbers; the first is shorter
+     */
+    public void testPosPosFirstShorter() {
+        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[] = {0, -128, 9, 56, 100, -2, -3, -3, -3, 95, 15, -9, 39, 58, -69, 87, 87, -17, -73};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two negative numbers of the same length
+     */
+    public void testNegNegSameLength() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
+        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, -57, -101, -5, -5, -18, -38, -17, -2, -65, -2, -11, -3};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two negative numbers; the first is longer
+     */
+    public void testNegNegFirstLonger() {
+        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, 1, 75, -89, -45, -2, -3, -18, -36, -17, -10, -3, -6, -7, -21};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two negative numbers; the first is shorter
+     */
+    public void testNegNegFirstShorter() {
+        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[] = {-1, 1, 75, -89, -45, -2, -3, -18, -36, -17, -10, -3, -6, -7, -21};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two numbers of different signs and the same length
+     */
+    public void testPosNegSameLength() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
+        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, 1, -126, 59, 103, -2, -11, -7, -3, -33, -57, -3, -5, -5, -21};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two numbers of different signs and the same length
+     */
+    public void testNegPosSameLength() {
+        byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, -117};
+        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, 5, 79, -73, -9, -76, -3, 78, -35, -17, 119};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or 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, -1, -2, -2, -91, -2, 31, -1, -11, 125, -22, -83, 30, 95};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for two negative numbers; the first is shorter
+     */
+    public void testNegPosFirstShorter() {
+        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[] = {-74, 91, 47, -5, -13, -7, -5, -33, -49, -65, -1, -9, -3};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for a positive and a negative numbers; the first is longer
+     */
+    public void testPosNegFirstLonger() {
+        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[] = {-74, 91, 47, -5, -13, -7, -5, -33, -49, -65, -1, -9, -3};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+
+    /**
+     * Or for a positive and a negative number; the first is shorter
+     */
+    public void testPosNegFirstShorter() {
+        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[] = {-1, 127, -10, -57, -101, -1, -1, -2, -2, -91, -2, 31, -1, -11, 125, -22, -83, 30, 95};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.or(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);
+    }
+}



Mime
View raw message