harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r387239 [17/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/BigDecimalScaleOperationsTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalScaleOperationsTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalScaleOperationsTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalScaleOperationsTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,323 @@
+/*
+ *  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;
+
+/**
+ * Class:  java.math.BigDecimal
+ * Methods: movePointLeft, movePointRight, scale, setScale, unscaledValue * 
+ */
+public class BigDecimalScaleOperationsTest extends TestCase {
+    /**
+     * Check the default scale
+     */
+    public void testScaleDefault() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int cScale = 0;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a));
+        assertTrue("incorrect scale", aNumber.scale() == cScale);
+    }
+
+    /**
+     * Check a negative scale
+     */
+    public void testScaleNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -10;
+        int cScale = -10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        assertTrue("incorrect scale", aNumber.scale() == cScale);
+    }
+
+    /**
+     * Check a positive scale
+     */
+    public void testScalePos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 10;
+        int cScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        assertTrue("incorrect scale", aNumber.scale() == cScale);
+    }
+
+    /**
+     * Check the zero scale
+     */
+    public void testScaleZero() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 0;
+        int cScale = 0;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        assertTrue("incorrect scale", aNumber.scale() == cScale);
+    }
+
+    /**
+     * Check the unscaled value
+     */
+    public void testUnscaledValue() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 100;
+        BigInteger bNumber = new BigInteger(a);
+        BigDecimal aNumber = new BigDecimal(bNumber, aScale);
+        assertTrue("incorrect unscaled value", aNumber.unscaledValue().equals(bNumber));
+    }
+    
+    /**
+     * Set a greater new scale
+     */
+    public void testSetScaleGreater() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 18;
+        int newScale = 28;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.compareTo(aNumber) == 0);
+    }
+
+    /**
+     * Set a less new scale; this.scale == 8; newScale == 5.
+     */
+    public void testSetScaleLess() {
+        String a = "2.345726458768760000E+10";
+        int newScale = 5;
+        BigDecimal aNumber = new BigDecimal(a);
+        BigDecimal bNumber = aNumber.setScale(newScale);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.compareTo(aNumber) == 0);
+    }
+
+    /**
+     * Verify an exception when setting a new scale
+     */
+    public void testSetScaleException() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        try {
+            BigDecimal bNumber = aNumber.setScale(newScale);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().
+                equals("rounding mode is ROUND_UNNECESSARY but the result is not exact"));
+        }
+    }
+
+    /**
+     * Set the same new scale
+     */
+    public void testSetScaleSame() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 18;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.equals(aNumber));
+    }
+
+    /**
+     * Set a new scale
+     */
+    public void testSetScaleRoundUp() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        String b = "123121247898748298842980877981045763478139";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale, BigDecimal.ROUND_UP);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(b));
+    }
+
+    /**
+     * Set a new scale
+     */
+    public void testSetScaleRoundDown() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        String b = "123121247898748298842980877981045763478138";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale, BigDecimal.ROUND_DOWN);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(b));
+    }
+
+    /**
+     * Set a new scale
+     */
+    public void testSetScaleRoundCeiling() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        String b = "123121247898748298842980877981045763478139";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale, BigDecimal.ROUND_CEILING);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(b));
+    }
+
+    /**
+     * Set a new scale
+     */
+    public void testSetScaleRoundFloor() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        String b = "123121247898748298842980877981045763478138";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale, BigDecimal.ROUND_FLOOR);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(b));
+    }
+
+    /**
+     * Set a new scale
+     */
+    public void testSetScaleRoundHalfUp() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        String b = "123121247898748298842980877981045763478138";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale, BigDecimal.ROUND_HALF_UP);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(b));
+    }
+
+    /**
+     * Set a new scale
+     */
+    public void testSetScaleRoundHalfDown() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        String b = "123121247898748298842980877981045763478138";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale, BigDecimal.ROUND_HALF_DOWN);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(b));
+    }
+
+    /**
+     * Set a new scale
+     */
+    public void testSetScaleRoundHalfEven() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        String b = "123121247898748298842980877981045763478138";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.setScale(newScale, BigDecimal.ROUND_HALF_EVEN);
+        assertTrue("incorrect scale", bNumber.scale() == newScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(b));
+    }
+    
+    /**
+     * Move the decimal point to the left; the shift value is positive
+     */
+    public void testMovePointLeftPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 28;
+        int shift = 18;
+        int resScale = 46;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.movePointLeft(shift);
+        assertTrue("incorrect scale", bNumber.scale() == resScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(a));
+    }
+        
+    /**
+     * Move the decimal point to the left; the shift value is positive
+     */
+    public void testMovePointLeftNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 28;
+        int shift = -18;
+        int resScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.movePointLeft(shift);
+        assertTrue("incorrect scale", bNumber.scale() == resScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(a));
+    }
+
+    /**
+     * Move the decimal point to the right; the shift value is positive
+     */
+    public void testMovePointRightPosGreater() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 28;
+        int shift = 18;
+        int resScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.movePointRight(shift);
+        assertTrue("incorrect scale", bNumber.scale() == resScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(a));
+    }
+        
+    /**
+     * Move the decimal point to the right; the shift value is positive
+     */
+    public void testMovePointRightPosLess() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        String b = "123121247898748298842980877981045763478138475679498700";
+        int aScale = 28;
+        int shift = 30;
+        int resScale = 0;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.movePointRight(shift);
+        assertTrue("incorrect scale", bNumber.scale() == resScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(b));
+    }
+        
+    /**
+     * Move the decimal point to the right; the shift value is positive
+     */
+    public void testMovePointRightNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 28;
+        int shift = -18;
+        int resScale = 46;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = aNumber.movePointRight(shift);
+        assertTrue("incorrect scale", bNumber.scale() == resScale);
+        assertTrue("incorrect value", bNumber.unscaledValue().toString().equals(a));
+    }
+
+    /**
+     * Move the decimal point to the right when the scale overflows
+     */
+    public void testMovePointRightException() {
+        String a = "12312124789874829887348723648726347429808779810457634781384756794987";
+        int aScale = Integer.MAX_VALUE; //2147483647
+        int shift = -18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        try {
+            BigDecimal bNumber = aNumber.movePointRight(shift);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("scale outside the range of a 32-bit integer"));
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerAddTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerAddTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerAddTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerAddTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,497 @@
+/*
+ *  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.5.6.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:  java.math.BigInteger
+ * Method: add 
+ */
+public class BigIntegerAddTest extends TestCase {
+    /**
+     * Add two positive 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[] = {11, 22, 33, 44, 55, 66, 77, 11, 22, 33};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two negative numbers of the same length
+     */
+    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[] = {-12, -23, -34, -45, -56, -67, -78, -12, -23, -33};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two numbers of the same length.
+     * The first one is positive and the second is negative.
+     * The first one is greater in absolute value.
+     */
+    public void testCase3() {
+        byte aBytes[] = {3, 4, 5, 6, 7, 8, 9};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte rBytes[] = {2, 2, 2, 2, 2, 2, 2};
+        int aSign = 1;
+        int bSign = -1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two numbers of the same length.
+     * The first one is negative and the second is positive.
+     * The first one is greater in absolute value.
+     */
+    public void testCase4() {
+        byte aBytes[] = {3, 4, 5, 6, 7, 8, 9};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte rBytes[] = {-3, -3, -3, -3, -3, -3, -2};
+        int aSign = -1;
+        int bSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two numbers of the same length.
+     * The first is positive and the second is negative.
+     * The first is less in absolute value.
+     */
+    public void testCase5() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {3, 4, 5, 6, 7, 8, 9};
+        byte rBytes[] = {-3, -3, -3, -3, -3, -3, -2};
+        int aSign = 1;
+        int bSign = -1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two numbers of the same length.
+     * The first one is negative and the second is positive.
+     * The first one is less in absolute value.
+     */
+    public void testCase6() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {3, 4, 5, 6, 7, 8, 9};
+        byte rBytes[] = {2, 2, 2, 2, 2, 2, 2};
+        int aSign = -1;
+        int bSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two positive numbers of different length.
+     * The first is longer.
+     */
+    public void testCase7() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {1, 2, 3, 4, 15, 26, 37, 41, 52, 63, 74, 15, 26, 37};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two positive numbers of different length.
+     * The second is longer.
+     */
+    public void testCase8() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {1, 2, 3, 4, 15, 26, 37, 41, 52, 63, 74, 15, 26, 37};
+        BigInteger aNumber = new BigInteger(aBytes);
+        BigInteger bNumber = new BigInteger(bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two negative numbers of different length.
+     * The first is longer.
+     */
+    public void testCase9() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {-2, -3, -4, -5, -16, -27, -38, -42, -53, -64, -75, -16, -27, -37};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two negative numbers of different length.
+     * The second is longer.
+     */
+    public void testCase10() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {-2, -3, -4, -5, -16, -27, -38, -42, -53, -64, -75, -16, -27, -37};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two numbers of different length and sign.
+     * The first is positive.
+     * The first is longer.
+     */
+    public void testCase11() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {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.add(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);
+    }
+
+    /**
+     * Add two numbers of different length and sign.
+     * The first is positive.
+     * The second is longer.
+     */
+    public void testCase12() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        int bSign = -1;        
+        byte rBytes[] = {-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.add(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);
+    }
+
+    /**
+     * Add two numbers of different length and sign.
+     * The first is negative.
+     * The first is longer.
+     */
+    public void testCase13() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {-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.add(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);
+    }
+
+    /**
+     * Add two numbers of different length and sign.
+     * The first is negative.
+     * The second is longer.
+     */
+    public void testCase14() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {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.add(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);
+    }
+    
+    /**
+     * Add two equal numbers of different signs
+     */
+    public void testCase15() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte rBytes[] = {0};
+        int aSign = -1;
+        int bSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(bNumber);
+        byte resBytes[] = new byte[rBytes.length];
+        for(int i = 0; i < resBytes.length; i++) {
+            assertTrue(resBytes[i] == rBytes[i]);
+        }
+        assertTrue("incorrect sign", result.signum() == 0);
+    }
+
+    /**
+     * Add zero to a number
+     */
+    public void testCase16() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte bBytes[] = {0};
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        int bSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add a number to zero
+     */
+    public void testCase17() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        int bSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+    
+    /**
+     * Add zero to zero
+     */
+    public void testCase18() {
+        byte aBytes[] = {0};
+        byte bBytes[] = {0};
+        byte rBytes[] = {0};
+        int aSign = 1;
+        int bSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+    
+    /**
+     * Add ZERO to a number
+     */
+    public void testCase19() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add a number to zero
+     */
+    public void testCase20() {
+        byte bBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int bSign = 1;
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+    
+    /**
+     * Add ZERO to ZERO
+     */
+    public void testCase21() {
+        byte rBytes[] = {0};
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add ONE to ONE
+     */
+    public void testCase22() {
+        byte rBytes[] = {2};
+        BigInteger aNumber = BigInteger.ONE;
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.add(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);
+    }
+
+    /**
+     * Add two numbers so that carry is 1
+     */
+    public void testCase23() {
+        byte aBytes[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+        byte bBytes[] = {-1, -1, -1, -1, -1, -1, -1, -1};
+        int aSign = 1;
+        int bSign = 1;
+        byte rBytes[] = {1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -2};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.add(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);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerAndTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerAndTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerAndTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerAndTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,432 @@
+/*
+ *  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
+ * Method: and 
+ */
+public class BigIntegerAndTest extends TestCase {
+    /**
+     * And 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};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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.and(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);
+    }
+
+    /**
+     * And for zero and one
+     */
+    public void testZeroOne() {
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.and(bNumber);
+        assertTrue(result.equals(BigInteger.ZERO));
+        assertTrue("incorrect sign", result.signum() == 0);
+    }
+
+    /**
+     * And for one and one
+     */
+    public void testOneOne() {
+        BigInteger aNumber = BigInteger.ONE;
+        BigInteger bNumber = BigInteger.ONE;
+        BigInteger result = aNumber.and(bNumber);
+        assertTrue(result.equals(BigInteger.ONE));
+        assertTrue("incorrect sign", result.signum() == 1);
+    }
+
+    /**
+     * And 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, -128, 56, 100, 4, 4, 17, 37, 16, 1, 64, 1, 10, 3};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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, -2, -76, 88, 44, 1, 2, 17, 35, 16, 9, 2, 5, 6, 21};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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, -2, -76, 88, 44, 1, 2, 17, 35, 16, 9, 2, 5, 6, 21};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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, 1, 2, 3, 3, 0, 65, -96, -48, -124, -60, 12, -40, -31, 97};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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, 127, -10, -57, -101, 1, 2, 2, 2, -96, -16, 8, -40, -59, 68, -88, -88, 16, 73};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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, 127, -10, -57, -101, 1, 2, 2, 2, -96, -16, 8, -40, -59, 68, -88, -88, 16, 73};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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[] = {0, -6, -80, 72, 8, 75, 2, -79, 34, 16, -119};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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[] = {0, -2, 125, -60, -104, 1, 10, 6, 2, 32, 56, 2, 4, 4, 21};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 3};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And for a negative and a positive 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[] = {0, -128, 9, 56, 100, 0, 0, 1, 1, 90, 1, -32, 0, 10, -126, 21, 82, -31, -95};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And 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[] = {0, -128, 9, 56, 100, 0, 0, 1, 1, 90, 1, -32, 0, 10, -126, 21, 82, -31, -95};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * And for a positive and a negative numbers; 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[] = {73, -92, -48, 4, 12, 6, 4, 32, 48, 64, 0, 8, 3};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * Test for a special case
+     */
+    public void testSpecialCase1() {
+        byte aBytes[] = {-1, -1, -1, -1};
+        byte bBytes[] = {5, -4, -3, -2};
+        int aSign = -1;
+        int bSign = -1;        
+        byte rBytes[] = {-1, 0, 0, 0, 0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+
+    /**
+     * Test for a special case
+     */
+    public void testSpecialCase2() {
+        byte aBytes[] = {-51};
+        byte bBytes[] = {-52, -51, -50, -49, -48};
+        int aSign = -1;
+        int bSign = 1;        
+        byte rBytes[] = {0, -52, -51, -50, -49, 16};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.and(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);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerCompareTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerCompareTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerCompareTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigIntegerCompareTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,584 @@
+/*
+ *  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.6.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:   java.math.BigInteger
+ * Methods: abs, compareTo, equals, max, min, negate, signum
+ */
+public class BigIntegerCompareTest extends TestCase {
+    /**
+     * abs() for a positive number
+     */
+    public void testAbsPositive() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int aSign = 1;
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.abs();
+        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);
+    }
+
+    /**
+     * abs() for a negative number
+     */
+    public void testAbsNegative() {
+        byte aBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        int aSign = -1;
+        byte rBytes[] = {1, 2, 3, 4, 5, 6, 7};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.abs();
+        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);
+    }
+
+    /**
+     * compareTo(BigInteger a).
+     * Compare two positive numbers.
+     * The first is greater.
+     */
+    public void testCompareToPosPos1() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = 1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == 1);
+    }
+    
+    /**
+     * compareTo(BigInteger a).
+     * Compare two positive numbers.
+     * The first is less.
+     */
+    public void testCompareToPosPos2() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        int result = aNumber.compareTo(bNumber);
+        assertTrue(aNumber.compareTo(bNumber) == -1);
+    }
+
+    /**
+     * compareTo(BigInteger a).
+     * Compare two equal positive numbers.
+     */
+    public void testCompareToEqualPos() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == 0);
+    }
+    
+    /**
+     * compareTo(BigInteger a).
+     * Compare two negative numbers.
+     * The first is greater in absolute value.
+     */
+    public void testCompareToNegNeg1() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = -1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == -1);
+    }
+    
+    /**
+     * compareTo(BigInteger a).
+     * Compare two negative numbers.
+     * The first is less  in absolute value.
+     */
+    public void testCompareNegNeg2() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = -1;
+        int bSign = -1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == 1);
+    }
+
+    /**
+     * compareTo(BigInteger a).
+     * Compare two equal negative numbers.
+     */
+    public void testCompareToEqualNeg() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = -1;
+        int bSign = -1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == 0);
+    }
+    
+    /**
+     * compareTo(BigInteger a).
+     * Compare two numbers of different signs.
+     * The first is positive.
+     */
+    public void testCompareToDiffSigns1() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = 1;
+        int bSign = -1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == 1);
+    }
+
+    /**
+     * compareTo(BigInteger a).
+     * Compare two numbers of different signs.
+     * The first is negative.
+     */
+    public void testCompareToDiffSigns2() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        int aSign = -1;
+        int bSign = 1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == -1);
+    }
+    
+    /**
+     * compareTo(BigInteger a).
+     * Compare a positive number to ZERO.
+     */
+    public void testCompareToPosZero() {
+        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);
+        BigInteger bNumber = BigInteger.ZERO;
+        int result = aNumber.compareTo(bNumber);
+        assertTrue(aNumber.compareTo(bNumber) == 1);
+    }
+
+    /**
+     * compareTo(BigInteger a).
+     * Compare ZERO to a positive number.
+     */
+    public void testCompareToZeroPos() {
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int bSign = 1;
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == -1);
+    }
+
+    /**
+     * compareTo(BigInteger a).
+     * Compare a negative number to ZERO.
+     */
+    public void testCompareToNegZero() {
+        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);
+        BigInteger bNumber = BigInteger.ZERO;
+        assertTrue(aNumber.compareTo(bNumber) == -1);
+    }
+
+    /**
+     * compareTo(BigInteger a).
+     * Compare ZERO to a negative number.
+     */
+    public void testCompareToZeroNeg() {
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int bSign = -1;
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == 1);
+    }
+
+    /**
+     * compareTo(BigInteger a).
+     * Compare ZERO to ZERO.
+     */
+    public void testCompareToZeroZero() {
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger bNumber = BigInteger.ZERO;
+        assertTrue(aNumber.compareTo(bNumber) == 0);
+    }
+
+    /**
+     * compareTo(Object obj).
+     * Verify throwing an exception if obj is not a BigInteger
+     */
+    public void testCompareToObjectException() {
+        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);
+        Object obj = new Object();
+        try {
+            int result = aNumber.compareTo(obj);
+            fail("ClassCastException has not been caught");
+        } catch (ClassCastException e) {
+            assertTrue("Improper exception class", e.getClass().getName().equals("java.lang.ClassCastException"));
+        }
+    }
+    
+    /**
+     * compareTo(Object obj).
+     * if obj is not a BigInteger, the exception should be thrown
+     */
+    public void testCompareToObject() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        Object hello = (Object)new String("Hello, World");
+        try {
+            aNumber.compareTo(hello);
+            fail("ClassCastException has not been caught");
+        } catch (ClassCastException e) {
+        }
+    }
+
+    /**
+     * compareTo(Object obj).
+     * obj should be a BigInteger
+     */
+    public void testCompareToObjectBI() {
+        byte aBytes[] = {10, 20, 30, 40, 50, 60, 70, 10, 20, 30};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        Object bNumber = (Object)new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.compareTo(bNumber) == -1);
+    }
+
+    /**
+     * equals(Object obj).
+     * obj is not a BigInteger
+     */
+    public void testEqualsObject() {
+        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);
+        Object obj = new Object();
+        assertFalse(aNumber.equals(obj));
+    }
+
+    /**
+     * equals(null).
+     */
+    public void testEqualsNull() {
+        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);
+        assertFalse(aNumber.equals(null));
+    }
+
+    /**
+     * equals(Object obj).
+     * obj is a BigInteger.
+     * numbers are equal.
+     */
+    public void testEqualsBigIntegerTrue() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        Object bNumber = (Object)new BigInteger(bSign, bBytes);
+        assertTrue(aNumber.equals(bNumber));
+    }
+
+    /**
+     * equals(Object obj).
+     * obj is a BigInteger.
+     * numbers are not equal.
+     */
+    public void testEqualsBigIntegerFalse() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        Object bNumber = (Object)new BigInteger(bSign, bBytes);
+        assertFalse(aNumber.equals(bNumber));
+    }
+
+    /**
+     * max(BigInteger val).
+     * the first is greater.
+     */
+    public void testMaxGreater() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.max(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);
+    }
+
+    /**
+     * max(BigInteger val).
+     * the first is less.
+     */
+    public void testMaxLess() {
+        byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.max(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);
+    }
+
+    /**
+     * max(BigInteger val).
+     * numbers are equal.
+     */
+    public void testMaxEqual() {
+        byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.max(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);
+    }
+
+    /**
+     * max(BigInteger val).
+     * max of negative and ZERO.
+     */
+    public void testMaxNegZero() {
+        byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = -1;
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.max(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);
+    }
+
+    /**
+     * min(BigInteger val).
+     * the first is greater.
+     */
+    public void testMinGreater() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.min(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);
+    }
+
+    /**
+     * min(BigInteger val).
+     * the first is less.
+     */
+    public void testMinLess() {
+        byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.min(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);
+    }
+
+    /**
+     * min(BigInteger val).
+     * numbers are equal.
+     */
+    public void testMinEqual() {
+        byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        byte bBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        int bSign = 1;        
+        byte rBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = new BigInteger(bSign, bBytes);
+        BigInteger result = aNumber.min(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);
+    }
+
+    /**
+     * max(BigInteger val).
+     * min of positive and ZERO.
+     */
+    public void testMinPosZero() {
+        byte aBytes[] = {45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        byte rBytes[] = {0};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger bNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.min(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);
+    }
+    
+    /**
+     * negate() a positive number.
+     */
+    public void testNegatePositive() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = 1;
+        byte rBytes[] = {-13, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -27, -4, -91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.negate();
+        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);
+    }
+
+    /**
+     * negate() a negative number.
+     */
+    public void testNegateNegative() {
+        byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        int aSign = -1;
+        byte rBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
+        BigInteger aNumber = new BigInteger(aSign, aBytes);
+        BigInteger result = aNumber.negate();
+        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);
+    }
+
+    /**
+     * negate() ZERO.
+     */
+    public void testNegateZero() {
+        byte rBytes[] = {0};
+        BigInteger aNumber = BigInteger.ZERO;
+        BigInteger result = aNumber.negate();
+        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);
+    }
+
+    /**
+     * signum() of a positive number.
+     */
+    public void testSignumPositive() {
+        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("incorrect sign", aNumber.signum() == 1);
+    }
+    
+    /**
+     * signum() of a negative number.
+     */
+    public void testSignumNegative() {
+        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("incorrect sign", aNumber.signum() == -1);
+    }
+    
+    /**
+     * signum() of ZERO.
+     */
+    public void testSignumZero() {
+        BigInteger aNumber = BigInteger.ZERO;
+        assertTrue("incorrect sign", aNumber.signum() == 0);
+    }
+}



Mime
View raw message