harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r446491 [14/24] - in /incubator/harmony/enhanced/classlib/trunk/modules: luni-kernel/.settings/ luni-kernel/META-INF/ luni-kernel/make/ luni-kernel/src/main/java/java/lang/ luni-kernel/src/main/java/java/lang/ref/ luni-kernel/src/main/java/...
Date Fri, 15 Sep 2006 03:08:13 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java?view=diff&rev=446491&r1=446490&r2=446491
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java Thu Sep 14 20:08:07 2006
@@ -1,349 +1,349 @@
-/*
- *  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$
- */
-
-package org.apache.harmony.tests.java.math;
-
-import junit.framework.TestCase;
-import java.math.*;
-
-/**
- * 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);
-        assertEquals("incorrect value", 0, bNumber.compareTo(aNumber));
-    }
-
-    /**
-     * 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);
-        assertEquals("incorrect value", 0, bNumber.compareTo(aNumber));
-    }
-
-    /**
-     * 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) {
-            assertEquals("Improper exception message", "Rounding necessary", e.getMessage());
-        }
-    }
-
-    /**
-     * 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));
-    }
-    
-    /**
-     * SetScale(int, RoundingMode)
-     */
-    public void testSetScaleIntRoundingMode() {
-        String a = "1231212478987482988429808779810457634781384756794987";
-        int aScale = 28;
-        int newScale = 18;
-        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
-        BigDecimal result = aNumber.setScale(newScale, RoundingMode.HALF_EVEN);
-        String res = "123121247898748298842980.877981045763478138";
-        int resScale = 18;
-        assertEquals("incorrect value", res, result.toString());
-        assertEquals("incorrect scale", resScale, result.scale());
-    }
-    
-    /**
-     * 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) {
-            assertEquals("Improper exception message", "Underflow", e.getMessage());
-        }
-    }
-
-    /**
-     * precision()
-     */
-    public void testPrecision() {
-        String a = "12312124789874829887348723648726347429808779810457634781384756794987";
-        int aScale = 14;
-        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
-        int prec = aNumber.precision();
-        assertEquals(68, prec);
-    }
-}
+/*
+ *  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$
+ */
+
+package org.apache.harmony.tests.java.math;
+
+import junit.framework.TestCase;
+import java.math.*;
+
+/**
+ * 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);
+        assertEquals("incorrect value", 0, bNumber.compareTo(aNumber));
+    }
+
+    /**
+     * 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);
+        assertEquals("incorrect value", 0, bNumber.compareTo(aNumber));
+    }
+
+    /**
+     * 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) {
+            assertEquals("Improper exception message", "Rounding necessary", e.getMessage());
+        }
+    }
+
+    /**
+     * 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));
+    }
+    
+    /**
+     * SetScale(int, RoundingMode)
+     */
+    public void testSetScaleIntRoundingMode() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 28;
+        int newScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.setScale(newScale, RoundingMode.HALF_EVEN);
+        String res = "123121247898748298842980.877981045763478138";
+        int resScale = 18;
+        assertEquals("incorrect value", res, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+    
+    /**
+     * 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) {
+            assertEquals("Improper exception message", "Underflow", e.getMessage());
+        }
+    }
+
+    /**
+     * precision()
+     */
+    public void testPrecision() {
+        String a = "12312124789874829887348723648726347429808779810457634781384756794987";
+        int aScale = 14;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        int prec = aNumber.precision();
+        assertEquals(68, prec);
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalScaleOperationsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerAddTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerAddTest.java?view=diff&rev=446491&r1=446490&r2=446491
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerAddTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerAddTest.java Thu Sep 14 20:08:07 2006
@@ -1,497 +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$
- */
-
-package org.apache.harmony.tests.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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", -1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-    
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 0, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-    
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 0, result.signum());
-    }
-    
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-    
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 0, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-
-    /**
-     * 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]);
-        }
-        assertEquals("incorrect sign", 1, result.signum());
-    }
-}
+/*
+ *  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$
+ */
+
+package org.apache.harmony.tests.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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", -1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+    
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 0, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+    
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 0, result.signum());
+    }
+    
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+    
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 0, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+
+    /**
+     * 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]);
+        }
+        assertEquals("incorrect sign", 1, result.signum());
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigIntegerAddTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message