harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r387239 [16/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/BigDecimalArithmeticTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalArithmeticTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalArithmeticTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalArithmeticTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,762 @@
+/*
+ *  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.3 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+import java.math.BigInteger;
+
+/**
+ * Class:  java.math.BigDecimal
+ * Methods: add, subtract, multiply, divide 
+ */
+public class BigDecimalArithmeticTest extends TestCase {
+    /**
+     * Add two numbers of equal positive scales
+     */
+    public void testAddEqualScalePosPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 10;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "123121247898748373566323807282924555312937.1991359555";
+        int cScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.add(bNumber);
+        assertTrue("incorrect value " + result.toString(), result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Add two numbers of equal negative scales
+     */
+    public void testAddEqualScaleNegNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -10;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "1.231212478987483735663238072829245553129371991359555E+61";
+        int cScale = -10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.add(bNumber);
+        assertTrue("incorrect value " + result.toString(), result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Add two numbers of different scales; the first is positive
+     */
+    public void testAddDiffScalePosNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "7472334294161400358170962860775454459810457634.781384756794987";
+        int cScale = 15;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.add(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Add two numbers of different scales; the first is negative
+     */
+    public void testAddDiffScaleNegPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "1231212478987482988429808779810457634781459480137916301878791834798.7234564568";
+        int cScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.add(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Add two zeroes of different scales; the first is negative
+     */
+    public void testAddDiffScaleZeroZero() {
+        String a = "0";
+        int aScale = -15;
+        String b = "0";
+        int bScale = 10;
+        String c = "0E-10";
+        int cScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.add(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Subtract two numbers of equal positive scales
+     */
+    public void testSubtractEqualScalePosPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 10;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "123121247898748224119637948679166971643339.7522230419";
+        int cScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.subtract(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Subtract two numbers of equal negative scales
+     */
+    public void testSubtractEqualScaleNegNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -10;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "1.231212478987482241196379486791669716433397522230419E+61";
+        int cScale = -10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.subtract(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Subtract two numbers of different scales; the first is positive
+     */
+    public void testSubtractDiffScalePosNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "-7472334291698975400195996883915836900189542365.218615243205013";
+        int cScale = 15;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.subtract(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Subtract two numbers of different scales; the first is negative
+     */
+    public void testSubtractDiffScaleNegPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "1231212478987482988429808779810457634781310033452057698121208165201.2765435432";
+        int cScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.subtract(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Multiply two numbers of positive scales
+     */
+    public void testMultiplyScalePosPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "92000312286217574978643009574114545567010139156902666284589309.1880727173060570190220616";
+        int cScale = 25;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.multiply(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Multiply two numbers of negative scales
+     */
+    public void testMultiplyEqualScaleNegNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "9.20003122862175749786430095741145455670101391569026662845893091880727173060570190220616E+111";
+        int cScale = -25;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.multiply(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Multiply two numbers of different scales
+     */
+    public void testMultiplyDiffScalePosNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 10;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "920003122862175749786430095741145455670101391569026662845893091880727173060570190220616";
+        int cScale = 0;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.multiply(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Multiply two numbers of different scales
+     */
+    public void testMultiplyDiffScaleNegPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "9.20003122862175749786430095741145455670101391569026662845893091880727173060570190220616E+91";
+        int cScale = -5;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.multiply(bNumber);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == cScale);
+    }
+
+    /**
+     * Divide by zero
+     */
+    public void testDivideByZero() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = BigDecimal.valueOf(0L);
+        try {
+            BigDecimal result = aNumber.divide(bNumber, BigDecimal.ROUND_UNNECESSARY);
+            fail("ArithmeticException has not been caught");
+        } catch (ArithmeticException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("division by zero"));
+        }
+    }
+
+    /**
+     * Divide with ROUND_UNNECESSARY
+     */
+    public void testDivideExceptionRM() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        try {
+            BigDecimal result = aNumber.divide(bNumber, BigDecimal.ROUND_UNNECESSARY);
+            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"));
+        }
+    }
+
+    /**
+     * Divide with invalid rounding mode
+     */
+    public void testDivideExceptionInvalidRM() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        try {
+            BigDecimal result = aNumber.divide(bNumber, 100);
+            fail("IllegalArgumentException has not been caught");
+        } catch (IllegalArgumentException e) {
+            assertTrue("Improper exception message", e.getMessage().equals("invalid rounding mode"));
+        }
+    }
+
+    /**
+     * Divide: local variable exponent is less than zero
+     */
+    public void testDivideExpLessZero() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "1.64770E+10";
+        int resScale = -5;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_CEILING);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: local variable exponent is equal to zero
+     */
+    public void testDivideExpEqualsZero() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "1.64769459009933764189139568605273529E+40";
+        int resScale = -5;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_CEILING);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: local variable exponent is greater than zero
+     */
+    public void testDivideExpGreaterZero() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 20;
+        String c = "1.647694590099337641891395686052735285121058381E+50";
+        int resScale = -5;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_CEILING);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: remainder is zero
+     */
+    public void testDivideRemainderIsZero() {
+        String a = "8311389578904553209874735431110";
+        int aScale = -15;
+        String b = "237468273682987234567849583746";
+        int bScale = 20;
+        String c = "3.5000000000000000000000000000000E+36";
+        int resScale = -5;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_CEILING);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_UP, result is negative
+     */
+    public void testDivideRoundUpNeg() {
+        String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "-1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_UP);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_UP, result is positive
+     */
+    public void testDivideRoundUpPos() {
+        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_UP);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_DOWN, result is negative
+     */
+    public void testDivideRoundDownNeg() {
+        String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "-1.24390557635720517122423359799283E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_DOWN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_DOWN, result is positive
+     */
+    public void testDivideRoundDownPos() {
+        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "1.24390557635720517122423359799283E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_DOWN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_FLOOR, result is positive
+     */
+    public void testDivideRoundFloorPos() {
+        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "1.24390557635720517122423359799283E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_FLOOR);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_FLOOR, result is negative
+     */
+    public void testDivideRoundFloorNeg() {
+        String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "-1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_FLOOR);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_CEILING, result is positive
+     */
+    public void testDivideRoundCeilingPos() {
+        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_CEILING);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_CEILING, result is negative
+     */
+    public void testDivideRoundCeilingNeg() {
+        String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "-1.24390557635720517122423359799283E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_CEILING);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_HALF_UP, result is positive; distance = -1
+     */
+    public void testDivideRoundHalfUpPos() {
+        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_UP);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_UP, result is negative; distance = -1
+     */
+    public void testDivideRoundHalfUpNeg() {
+        String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "-1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_UP);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_HALF_UP, result is positive; distance = 1
+     */
+    public void testDivideRoundHalfUpPos1() {
+        String a = "92948782094488478231212478987482988798104576347813847567949855464535634534563456";
+        int aScale = -24;
+        String b = "74723342238476237823754692930187879183479";
+        int bScale = 13;
+        String c = "1.2439055763572051712242335979928354832010167729111113605E+76";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_UP);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_UP, result is negative; distance = 1
+     */
+    public void testDivideRoundHalfUpNeg1() {
+        String a = "-92948782094488478231212478987482988798104576347813847567949855464535634534563456";
+        int aScale = -24;
+        String b = "74723342238476237823754692930187879183479";
+        int bScale = 13;
+        String c = "-1.2439055763572051712242335979928354832010167729111113605E+76";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_UP);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_HALF_UP, result is negative; equidistant
+     */
+    public void testDivideRoundHalfUpNeg2() {
+        String a = "-37361671119238118911893939591735";
+        int aScale = 10;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        String c = "-1E+5";
+        int resScale = -5;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_UP);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_HALF_DOWN, result is positive; distance = -1
+     */
+    public void testDivideRoundHalfDownPos() {
+        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_DOWN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_DOWN, result is negative; distance = -1
+     */
+    public void testDivideRoundHalfDownNeg() {
+        String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "-1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_DOWN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_HALF_DOWN, result is positive; distance = 1
+     */
+    public void testDivideRoundHalfDownPos1() {
+        String a = "92948782094488478231212478987482988798104576347813847567949855464535634534563456";
+        int aScale = -24;
+        String b = "74723342238476237823754692930187879183479";
+        int bScale = 13;
+        String c = "1.2439055763572051712242335979928354832010167729111113605E+76";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_DOWN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_DOWN, result is negative; distance = 1
+     */
+    public void testDivideRoundHalfDownNeg1() {
+        String a = "-92948782094488478231212478987482988798104576347813847567949855464535634534563456";
+        int aScale = -24;
+        String b = "74723342238476237823754692930187879183479";
+        int bScale = 13;
+        String c = "-1.2439055763572051712242335979928354832010167729111113605E+76";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_DOWN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_UP, result is negative; equidistant
+     */
+    public void testDivideRoundHalfDownNeg2() {
+        String a = "-37361671119238118911893939591735";
+        int aScale = 10;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        String c = "0E+5";
+        int resScale = -5;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_DOWN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_EVEN, result is positive; distance = -1
+     */
+    public void testDivideRoundHalfEvenPos() {
+        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_EVEN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_EVEN, result is negative; distance = -1
+     */
+    public void testDivideRoundHalfEvenNeg() {
+        String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+        int aScale = -24;
+        String b = "7472334223847623782375469293018787918347987234564568";
+        int bScale = 13;
+        String c = "-1.24390557635720517122423359799284E+53";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_EVEN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+    
+    /**
+     * Divide: rounding mode is ROUND_HALF_EVEN, result is positive; distance = 1
+     */
+    public void testDivideRoundHalfEvenPos1() {
+        String a = "92948782094488478231212478987482988798104576347813847567949855464535634534563456";
+        int aScale = -24;
+        String b = "74723342238476237823754692930187879183479";
+        int bScale = 13;
+        String c = "1.2439055763572051712242335979928354832010167729111113605E+76";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_EVEN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_EVEN, result is negative; distance = 1
+     */
+    public void testDivideRoundHalfEvenNeg1() {
+        String a = "-92948782094488478231212478987482988798104576347813847567949855464535634534563456";
+        int aScale = -24;
+        String b = "74723342238476237823754692930187879183479";
+        int bScale = 13;
+        String c = "-1.2439055763572051712242335979928354832010167729111113605E+76";
+        int resScale = -21;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_EVEN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+
+    /**
+     * Divide: rounding mode is ROUND_HALF_EVEN, result is negative; equidistant
+     */
+    public void testDivideRoundHalfEvenNeg2() {
+        String a = "-37361671119238118911893939591735";
+        int aScale = 10;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        String c = "0E+5";
+        int resScale = -5;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, resScale, BigDecimal.ROUND_HALF_EVEN);
+        assertTrue("incorrect value", result.toString().equals(c));
+        assertTrue("incorrect scale", result.scale() == resScale);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalCompareTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalCompareTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalCompareTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalCompareTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,372 @@
+/*
+ *  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: abs, compareTo, equals, hashCode, 
+ * max, min, negate, signum
+ */
+public class BigDecimalCompareTest extends TestCase {
+    /**
+     * Abs() of a negative BigDecimal
+     */
+    public void testAbsNeg() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        String result = "123809648392384754573567356745735635678902957849027687.87678287";
+        assertTrue("incorrect value", aNumber.abs().toString().equals(result));
+    }
+
+    /**
+     * Abs() of a positive BigDecimal
+     */
+    public void testAbsPos() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        String result = "123809648392384754573567356745735635678902957849027687.87678287";
+        assertTrue("incorrect value", aNumber.abs().toString().equals(result));
+    }
+
+    /**
+     * Compare to a number of an equal scale
+     */
+    public void testCompareEqualScale1() {
+        String a = "12380964839238475457356735674573563567890295784902768787678287";
+        int aScale = 18;
+        String b = "4573563567890295784902768787678287";
+        int bScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        int result = 1;
+        assertTrue("incorrect result", aNumber.compareTo(bNumber) == result);
+    }
+
+    /**
+     * Compare to a number of an equal scale
+     */
+    public void testCompareEqualScale2() {
+        String a = "12380964839238475457356735674573563567890295784902768787678287";
+        int aScale = 18;
+        String b = "4573563923487289357829759278282992758247567890295784902768787678287";
+        int bScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        int result = -1;
+        assertTrue("incorrect result", aNumber.compareTo(bNumber) == result);
+    }
+
+    /**
+     * Compare to a number of an greater scale
+     */
+    public void testCompareGreaterScale1() {
+        String a = "12380964839238475457356735674573563567890295784902768787678287";
+        int aScale = 28;
+        String b = "4573563567890295784902768787678287";
+        int bScale = 18;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        int result = 1;
+        assertTrue("incorrect result", aNumber.compareTo(bNumber) == result);
+    }
+
+    /**
+     * Compare to a number of an greater scale
+     */
+    public void testCompareGreaterScale2() {
+        String a = "12380964839238475457356735674573563567890295784902768787678287";
+        int aScale = 48;
+        String b = "4573563567890295784902768787678287";
+        int bScale = 2;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        int result = -1;
+        assertTrue("incorrect result", aNumber.compareTo(bNumber) == result);
+    }
+
+    /**
+     * Compare to a number of an less scale
+     */
+    public void testCompareLessScale1() {
+        String a = "12380964839238475457356735674573563567890295784902768787678287";
+        int aScale = 18;
+        String b = "4573563567890295784902768787678287";
+        int bScale = 28;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        int result = 1;
+        assertTrue("incorrect result", aNumber.compareTo(bNumber) == result);
+    }
+
+    /**
+     * Compare to a number of an less scale
+     */
+    public void testCompareLessScale2() {
+        String a = "12380964839238475457356735674573";
+        int aScale = 36;
+        String b = "45735635948573894578349572001798379183767890295784902768787678287";
+        int bScale = 48;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        int result = -1;
+        assertTrue("incorrect result", aNumber.compareTo(bNumber) == result);
+    }
+
+    /**
+     * Equals() for unequal BigDecimals
+     */
+    public void testEqualsUnequal1() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = -24;
+       String b = "7472334223847623782375469293018787918347987234564568";
+       int bScale = 13;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       assertTrue(!aNumber.equals(bNumber));
+    }
+
+    /**
+     * Equals() for unequal BigDecimals
+     */
+    public void testEqualsUnequal2() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = -24;
+       String b = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int bScale = 13;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       assertTrue(!aNumber.equals(bNumber));
+    }
+
+    /**
+     * Equals() for unequal BigDecimals
+     */
+    public void testEqualsUnequal3() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = -24;
+       String b = "92948782094488478231212478987482988429808779810457634781384756794987";
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       assertTrue(!aNumber.equals(b));
+    }
+
+    /**
+     * equals() for equal BigDecimals
+     */
+    public void testEqualsEqual() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = -24;
+       String b = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int bScale = -24;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       assertTrue(aNumber.equals(bNumber));
+    }
+
+    /**
+     * equals() for equal BigDecimals
+     */
+    public void testEqualsNull() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = -24;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       assertFalse(aNumber.equals(null));
+    }
+
+    /**
+     * hashCode() for equal BigDecimals
+     */
+    public void testHashCodeEqual() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = -24;
+       String b = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int bScale = -24;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       assertTrue("incorrect value", aNumber.hashCode() == bNumber.hashCode());
+    }
+
+    /**
+     * hashCode() for unequal BigDecimals
+     */
+    public void testHashCodeUnequal() {
+       String a = "8478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       String b = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int bScale = -24;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       assertTrue("incorrect value", aNumber.hashCode() != bNumber.hashCode());
+    }
+
+    /**
+     * max() for equal BigDecimals
+     */
+    public void testMaxEqual() {
+       String a = "8478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       String b = "8478231212478987482988429808779810457634781384756794987";
+       int bScale = 41;
+       String c = "8478231212478987482988429808779810457634781384756794987";
+       int cScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale);
+       assertTrue("incorrect value", aNumber.max(bNumber).equals(cNumber));
+    }
+
+    /**
+     * max() for unequal BigDecimals
+     */
+    public void testMaxUnequal1() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 24;
+       String b = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int bScale = 41;
+       String c = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int cScale = 24;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale);
+       assertTrue("incorrect value", aNumber.max(bNumber).equals(cNumber));
+    }
+
+    /**
+     * max() for unequal BigDecimals
+     */
+    public void testMaxUnequal2() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       String b = "94488478231212478987482988429808779810457634781384756794987";
+       int bScale = 41;
+       String c = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int cScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale);
+       assertTrue("incorrect value", aNumber.max(bNumber).equals(cNumber));
+    }
+
+    /**
+     * min() for equal BigDecimals
+     */
+    public void testMinEqual() {
+       String a = "8478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       String b = "8478231212478987482988429808779810457634781384756794987";
+       int bScale = 41;
+       String c = "8478231212478987482988429808779810457634781384756794987";
+       int cScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale);
+       assertTrue("incorrect value", aNumber.min(bNumber).equals(cNumber));
+    }
+
+    /**
+     * min() for unequal BigDecimals
+     */
+    public void testMinUnequal1() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 24;
+       String b = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int bScale = 41;
+       String c = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int cScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale);
+       assertTrue("incorrect value", aNumber.min(bNumber).equals(cNumber));
+    }
+
+    /**
+     * min() for unequal BigDecimals
+     */
+    public void testMinUnequal2() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       String b = "94488478231212478987482988429808779810457634781384756794987";
+       int bScale = 41;
+       String c = "94488478231212478987482988429808779810457634781384756794987";
+       int cScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+       BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale);
+       assertTrue("incorrect value", aNumber.min(bNumber).equals(cNumber));
+    }
+
+    /**
+     * negate() for a positive BigDecimal
+     */
+    public void testNegatePositive() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       String c = "-92948782094488478231212478987482988429808779810457634781384756794987";
+       int cScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale);
+       assertTrue("incorrect value", aNumber.negate().equals(cNumber));
+    }
+
+    /**
+     * negate() for a negative BigDecimal
+     */
+    public void testNegateNegative() {
+       String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       String c = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int cScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale);
+       assertTrue("incorrect value", aNumber.negate().equals(cNumber));
+    }
+
+    /**
+     * signum() for a positive BigDecimal
+     */
+    public void testSignumPositive() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       assertTrue("incorrect value", aNumber.signum() == 1);
+    }
+
+    /**
+     * signum() for a negative BigDecimal
+     */
+    public void testSignumNegative() {
+       String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       assertTrue("incorrect value", aNumber.signum() == -1);
+    }
+
+    /**
+     * signum() for zero
+     */
+    public void testSignumZero() {
+       String a = "0";
+       int aScale = 41;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       assertTrue("incorrect value", aNumber.signum() == 0);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalConstructorsTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalConstructorsTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalConstructorsTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalConstructorsTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,458 @@
+/*
+ *  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.4.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+
+/**
+ * Class:  java.math.BigDecimal
+ * Methods: constructors and fields
+ */
+public class BigDecimalConstructorsTest extends TestCase {
+    /**
+     * check ONE
+     */
+    public void testFieldONE() {
+        String oneS = "1";
+        double oneD = 1.0;
+        assertTrue("incorrect string value", BigDecimal.ONE.toString().equals(oneS));
+        assertTrue("incorrect double value", BigDecimal.ONE.doubleValue() == oneD);
+    }
+
+    /**
+     * check TEN
+     */
+    public void testFieldTEN() {
+        String oneS = "10";
+        double oneD = 10.0;
+        assertTrue("incorrect string value", BigDecimal.TEN.toString().equals(oneS));
+        assertTrue("incorrect double value", BigDecimal.TEN.doubleValue() == oneD);
+    }
+
+    /**
+     * check ZERO
+     */
+    public void testFieldZERO() {
+        String oneS = "0";
+        double oneD = 0.0;
+        assertTrue("incorrect string value", BigDecimal.ZERO.toString().equals(oneS));
+        assertTrue("incorrect double value", BigDecimal.ZERO.doubleValue() == oneD);
+    }
+
+    /**
+     * new BigDecimal(BigInteger value)
+     */
+    public void testConstrBI() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        BigInteger bA = new BigInteger(a);
+        BigDecimal aNumber = new BigDecimal(bA);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == 0);
+    }
+     
+    /**
+     * new BigDecimal(BigInteger value, int scale)
+     */
+    public void testConstrBIScale() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        BigInteger bA = new BigInteger(a);
+        int aScale = 10;
+        BigDecimal aNumber = new BigDecimal(bA, aScale);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(double value) when value is NaN
+     */
+    public void testConstrDoubleNaN() {
+        double a = Double.NaN;
+        try {
+            BigDecimal aNumber = new BigDecimal(a);
+           fail("NumberFormatException has not been caught");
+       } catch (NumberFormatException e) {
+           assertTrue("Improper exception message", e.getMessage().equals("argument is NaN"));
+       }
+    }
+
+    /**
+     * new BigDecimal(double value) when value is positive infinity
+     */
+    public void testConstrDoublePosInfinity() {
+        double a = Double.POSITIVE_INFINITY;
+        try {
+            BigDecimal aNumber = new BigDecimal(a);
+           fail("NumberFormatException has not been caught");
+       } catch (NumberFormatException e) {
+           assertTrue("Improper exception message", e.getMessage().equals("argument is infinite"));
+       }
+    }
+
+    /**
+     * new BigDecimal(double value) when value is positive infinity
+     */
+    public void testConstrDoubleNegInfinity() {
+        double a = Double.NEGATIVE_INFINITY;
+        try {
+            BigDecimal aNumber = new BigDecimal(a);
+           fail("NumberFormatException has not been caught");
+       } catch (NumberFormatException e) {
+           assertTrue("Improper exception message", e.getMessage().equals("argument is infinite"));
+       }
+    }
+
+    /**
+     * new BigDecimal(double value)
+     */
+    public void testConstrDouble() {
+        double a = 732546982374982347892379283571094797.287346782359284756;
+        int aScale = 0;
+        BigInteger bA = new BigInteger("732546982374982285073458350476230656");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(0.1)
+     */
+    public void testConstrDouble01() {
+        double a = 1.E-1;
+        int aScale = 55;
+        BigInteger bA = new BigInteger("1000000000000000055511151231257827021181583404541015625");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(0.555)
+     */
+    public void testConstrDouble02() {
+        double a = 0.555;
+        int aScale = 53;
+        BigInteger bA = new BigInteger("55500000000000004884981308350688777863979339599609375");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(-0.1)
+     */
+    public void testConstrDoubleMinus01() {
+        double a = -1.E-1;
+        int aScale = 55;
+        BigInteger bA = new BigInteger("-1000000000000000055511151231257827021181583404541015625");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(double value) when value is denormalized
+     */
+    public void testConstrDoubleDenormalized() {
+        double a = 2.274341322658976E-309;
+        int aScale = 1073;
+        BigInteger bA = new BigInteger("227434132265897633950269241702666687639731047124115603942986140264569528085692462493371029187342478828091760934014851133733918639492582043963243759464684978401240614084312038547315281016804838374623558434472007664427140169018817050565150914041833284370702366055678057809362286455237716100382057360123091641959140448783514464639706721250400288267372238950016114583259228262046633530468551311769574111763316146065958042194569102063373243372766692713192728878701004405568459288708477607744497502929764155046100964958011009313090462293046650352146796805866786767887226278836423536035611825593567576424943331337401071583562754098901412372708947790843318760718495117047155597276492717187936854356663665005157041552436478744491526494952982062613955349661409854888916015625");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+     
+    /**
+     * new BigDecimal(String value)
+     * when value is not a valid representation of BigDecimal.
+     */
+    public void testConstrStringException() {
+        String a = "-238768.787678287a+10";
+        try {
+            BigDecimal aNumber = new BigDecimal(a);
+           fail("NumberFormatException has not been caught");
+       } catch (NumberFormatException e) {
+       }
+    }
+
+    /**
+     * new BigDecimal(String value)
+     * when exponent is empty.
+     */
+    public void testConstrStringExceptionEmptyExponent1() {
+        String a = "-238768.787678287e";
+        try {
+            BigDecimal aNumber = new BigDecimal(a);
+           fail("NumberFormatException has not been caught");
+       } catch (NumberFormatException e) {
+           assertTrue("Improper exception message", e.getMessage().equals("empty exponent"));
+       }
+    }
+
+    /**
+     * new BigDecimal(String value)
+     * when exponent is empty.
+     */
+    public void testConstrStringExceptionEmptyExponent2() {
+        String a = "-238768.787678287e-";
+        try {
+            BigDecimal aNumber = new BigDecimal(a);
+           fail("NumberFormatException has not been caught");
+       } catch (NumberFormatException e) {
+           assertTrue("Improper exception message", e.getMessage().equals("empty exponent"));
+       }
+    }
+
+    /**
+     * new BigDecimal(String value)
+     * when exponent is greater than Integer.MAX_VALUE.
+     */
+    public void testConstrStringExceptionExponentGreaterIntegerMax() {
+        String a = "-238768.787678287e214748364767876";
+        try {
+            BigDecimal aNumber = new BigDecimal(a);
+           fail("NumberFormatException has not been caught");
+       } catch (NumberFormatException e) {
+           assertTrue("Improper exception message", e.getMessage().equals("exponent is not signed integer"));
+       }
+    }
+
+    /**
+     * new BigDecimal(String value)
+     * when exponent is less than Integer.MIN_VALUE.
+     */
+    public void testConstrStringExceptionExponentLessIntegerMin() {
+        String a = "-238768.787678287e-214748364767876";
+        try {
+            BigDecimal aNumber = new BigDecimal(a);
+           fail("NumberFormatException has not been caught");
+       } catch (NumberFormatException e) {
+           assertTrue("Improper exception message", e.getMessage().equals("exponent is not signed integer"));
+       }
+    }
+
+    /**
+     * new BigDecimal(String value)
+     * when exponent is Integer.MAX_VALUE.
+     */
+    public void testConstrStringExponentIntegerMax() {
+        String a = "-238768.787678287e2147483647";
+        int aScale = -2147483638;
+        BigInteger bA = new BigInteger("-238768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(String value)
+     * when exponent is Integer.MIN_VALUE.
+     */
+    public void testConstrStringExponentIntegerMin() {
+        String a = ".238768e-2147483648";
+        int aScale = -2147483638;
+        BigInteger bA = new BigInteger("-238768787678287");
+        try {
+           BigDecimal aNumber = new BigDecimal(a);
+       } catch (NumberFormatException e) {
+           assertTrue("Improper exception message", 
+               e.getMessage().equals("resulting scale out of range"));
+       }
+    }
+
+    /**
+     * new BigDecimal(String value); value does not contain exponent
+     */
+      public void testConstrStringWithoutExpPos1() {
+        String a = "732546982374982347892379283571094797.287346782359284756";
+        int aScale = 18;
+        BigInteger bA = new BigInteger("732546982374982347892379283571094797287346782359284756");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(String value); value does not contain exponent
+     */
+      public void testConstrStringWithoutExpPos2() {
+        String a = "+732546982374982347892379283571094797.287346782359284756";
+        int aScale = 18;
+        BigInteger bA = new BigInteger("732546982374982347892379283571094797287346782359284756");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+       
+    /**
+     * new BigDecimal(String value); value does not contain exponent
+     */
+      public void testConstrStringWithoutExpNeg() {
+        String a = "-732546982374982347892379283571094797.287346782359284756";
+        int aScale = 18;
+        BigInteger bA = new BigInteger("-732546982374982347892379283571094797287346782359284756");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+       
+    /**
+     * new BigDecimal(String value); value does not contain exponent
+     * and decimal point
+     */
+      public void testConstrStringWithoutExpWithoutPoint() {
+        String a = "-732546982374982347892379283571094797287346782359284756";
+        int aScale = 0;
+        BigInteger bA = new BigInteger("-732546982374982347892379283571094797287346782359284756");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+       
+    /**
+     * new BigDecimal(String value); value contains exponent
+     * and does not contain decimal point
+     */
+    public void testConstrStringWithExponentWithoutPoint1() {
+        String a = "-238768787678287e214";
+        int aScale = -214;
+        BigInteger bA = new BigInteger("-238768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(String value); value contains exponent
+     * and does not contain decimal point
+     */
+    public void testConstrStringWithExponentWithoutPoint2() {
+        String a = "-238768787678287e-214";
+        int aScale = 214;
+        BigInteger bA = new BigInteger("-238768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+     
+    /**
+     * new BigDecimal(String value); value contains exponent
+     * and does not contain decimal point
+     */
+    public void testConstrStringWithExponentWithoutPoint3() {
+        String a = "238768787678287e-214";
+        int aScale = 214;
+        BigInteger bA = new BigInteger("238768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(String value); value contains exponent
+     * and does not contain decimal point
+     */
+    public void testConstrStringWithExponentWithoutPoint4() {
+        String a = "238768787678287e+214";
+        int aScale = -214;
+        BigInteger bA = new BigInteger("238768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(String value); value contains exponent
+     * and does not contain decimal point
+     */
+    public void testConstrStringWithExponentWithoutPoint5() {
+        String a = "238768787678287E214";
+        int aScale = -214;
+        BigInteger bA = new BigInteger("238768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(String value); 
+     * value contains both exponent and decimal point
+     */
+    public void testConstrStringWithExponentWithPoint1() {
+        String a = "23985439837984782435652424523876878.7678287e+214";
+        int aScale = -207;
+        BigInteger bA = new BigInteger("239854398379847824356524245238768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(String value); 
+     * value contains both exponent and decimal point
+     */
+    public void testConstrStringWithExponentWithPoint2() {
+        String a = "238096483923847545735673567457356356789029578490276878.7678287e-214";
+        int aScale = 221;
+        BigInteger bA = new BigInteger("2380964839238475457356735674573563567890295784902768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+
+    /**
+     * new BigDecimal(String value); 
+     * value contains both exponent and decimal point
+     */
+    public void testConstrStringWithExponentWithPoint3() {
+        String a = "2380964839238475457356735674573563567890.295784902768787678287E+21";
+        int aScale = 0;
+        BigInteger bA = new BigInteger("2380964839238475457356735674573563567890295784902768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+     
+    /**
+     * new BigDecimal(String value); 
+     * value contains both exponent and decimal point
+     */
+    public void testConstrStringWithExponentWithPoint4() {
+        String a = "23809648392384754573567356745735635678.90295784902768787678287E+21";
+        int aScale = 2;
+        BigInteger bA = new BigInteger("2380964839238475457356735674573563567890295784902768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+     
+    /**
+     * new BigDecimal(String value); 
+     * value contains both exponent and decimal point
+     */
+    public void testConstrStringWithExponentWithPoint5() {
+        String a = "238096483923847545735673567457356356789029.5784902768787678287E+21";
+        int aScale = -2;
+        BigInteger bA = new BigInteger("2380964839238475457356735674573563567890295784902768787678287");
+        BigDecimal aNumber = new BigDecimal(a);
+        assertTrue("incorrect value", aNumber.unscaledValue().equals(bA));
+        assertTrue("incorrect scale", aNumber.scale() == aScale);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalConvertTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalConvertTest.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalConvertTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/test/common/unit/java/math/BigDecimalConvertTest.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,414 @@
+/*
+ *  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.4.2 $
+ */
+
+package java.math;
+
+import junit.framework.TestCase;
+
+/**
+ * Class:  java.math.BigDecimal
+ * Methods: doubleValue, floatValue, intValue, longValue,  
+ * valueOf, toString, toBigInteger
+ */
+public class BigDecimalConvertTest extends TestCase {
+    /**
+     * Double value of a negative BigDecimal
+     */
+    public void testDoubleValueNeg() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        double result = -1.2380964839238476E53;
+        assertTrue("incorrect value", aNumber.doubleValue() == result);
+    }
+
+    /**
+     * Double value of a positive BigDecimal
+     */
+    public void testDoubleValuePos() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        double result = 1.2380964839238476E53;
+        assertTrue("incorrect value", aNumber.doubleValue() == result);
+    }
+
+    /**
+     * Double value of a large positive BigDecimal
+     */
+    public void testDoubleValuePosInfinity() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+400";
+        BigDecimal aNumber = new BigDecimal(a);
+        double result = Double.POSITIVE_INFINITY;
+        assertTrue("incorrect value", aNumber.doubleValue() == result);
+    }
+
+    /**
+     * Double value of a large negative BigDecimal
+     */
+    public void testDoubleValueNegInfinity() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+400";
+        BigDecimal aNumber = new BigDecimal(a);
+        double result = Double.NEGATIVE_INFINITY;
+        assertTrue("incorrect value", aNumber.doubleValue() == result);
+    }
+
+    /**
+     * Double value of a small negative BigDecimal
+     */
+    public void testDoubleValueMinusZero() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E-400";
+        BigDecimal aNumber = new BigDecimal(a);
+        long minusZero = -9223372036854775808L;
+        double result = aNumber.doubleValue();
+        assertTrue("incorrect value", Double.doubleToLongBits(result) == minusZero);
+    }
+
+    /**
+     * Double value of a small positive BigDecimal
+     */
+    public void testDoubleValuePlusZero() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E-400";
+        BigDecimal aNumber = new BigDecimal(a);
+        long zero = 0;
+        double result = aNumber.doubleValue();
+        assertTrue("incorrect value", Double.doubleToLongBits(result) == zero);
+    }
+
+    /**
+     * Float value of a negative BigDecimal
+     */
+    public void testFloatValueNeg() {
+        String a = "-1238096483923847.6356789029578E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        float result = -1.2380965E36F;
+        assertTrue("incorrect value", aNumber.floatValue() == result);
+    }
+
+    /**
+     * Float value of a positive BigDecimal
+     */
+    public void testFloatValuePos() {
+        String a = "1238096483923847.6356789029578E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        float result = 1.2380965E36F;
+        assertTrue("incorrect value", aNumber.floatValue() == result);
+    }
+
+    /**
+     * Float value of a large positive BigDecimal
+     */
+    public void testFloatValuePosInfinity() {
+        String a = "123809648373567356745735.6356789787678287E+200";
+        BigDecimal aNumber = new BigDecimal(a);
+        float result = Float.POSITIVE_INFINITY;
+        assertTrue("incorrect value", aNumber.floatValue() == result);
+    }
+
+    /**
+     * Float value of a large negative BigDecimal
+     */
+    public void testFloatValueNegInfinity() {
+        String a = "-123809648392384755735.63567887678287E+200";
+        BigDecimal aNumber = new BigDecimal(a);
+        float result = Float.NEGATIVE_INFINITY;
+        assertTrue("incorrect value", aNumber.floatValue() == result);
+    }
+
+    /**
+     * Float value of a small negative BigDecimal
+     */
+    public void testFloatValueMinusZero() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E-400";
+        BigDecimal aNumber = new BigDecimal(a);
+        int minusZero = -2147483648;
+        float result = aNumber.floatValue();
+        assertTrue("incorrect value", Float.floatToIntBits(result) == minusZero);
+    }
+
+    /**
+     * Float value of a small positive BigDecimal
+     */
+    public void testFloatValuePlusZero() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E-400";
+        BigDecimal aNumber = new BigDecimal(a);
+        int zero = 0;
+        float result = aNumber.floatValue();
+        assertTrue("incorrect value", Float.floatToIntBits(result) == zero);
+    }
+
+    /**
+     * Integer value of a negative BigDecimal
+     */
+    public void testIntValueNeg() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        int result = 218520473;
+        assertTrue("incorrect value", aNumber.intValue() == result);
+    }
+
+    /**
+     * Integer value of a positive BigDecimal
+     */
+    public void testIntValuePos() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        int result = -218520473;
+        assertTrue("incorrect value", aNumber.intValue() == result);
+    }
+
+    /**
+     * Long value of a negative BigDecimal
+     */
+    public void testLongValueNeg() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        long result = -1246043477766677607L;
+        assertTrue("incorrect value", aNumber.longValue() == result);
+    }
+
+    /**
+     * Long value of a positive BigDecimal
+     */
+    public void testLongValuePos() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        long result = 1246043477766677607L;
+        assertTrue("incorrect value", aNumber.longValue() == result);
+    }
+
+    /**
+     * Convert a positive BigDecimal to BigInteger
+     */
+    public void testToBigIntegerPos1() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigInteger bNumber = new BigInteger("123809648392384754573567356745735635678902957849027687");
+        BigDecimal aNumber = new BigDecimal(a);
+        BigInteger result = aNumber.toBigInteger();
+        assertTrue("incorrect value", result.equals(bNumber));
+    }
+
+    /**
+     * Convert a positive BigDecimal to BigInteger
+     */
+    public void testToBigIntegerPos2() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+15";
+        BigInteger bNumber = new BigInteger("123809648392384754573567356745735635678902957849");
+        BigDecimal aNumber = new BigDecimal(a);
+        BigInteger result = aNumber.toBigInteger();
+        assertTrue("incorrect value", result.equals(bNumber));
+    }
+
+    /**
+     * Convert a positive BigDecimal to BigInteger
+     */
+    public void testToBigIntegerPos3() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+45";
+        BigInteger bNumber = new BigInteger("123809648392384754573567356745735635678902957849027687876782870000000000000000");
+        BigDecimal aNumber = new BigDecimal(a);
+        BigInteger result = aNumber.toBigInteger();
+        assertTrue("incorrect value", result.equals(bNumber));
+    }
+
+    /**
+     * Convert a negative BigDecimal to BigInteger
+     */
+    public void testToBigIntegerNeg1() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigInteger bNumber = new BigInteger("-123809648392384754573567356745735635678902957849027687");
+        BigDecimal aNumber = new BigDecimal(a);
+        BigInteger result = aNumber.toBigInteger();
+        assertTrue("incorrect value", result.equals(bNumber));
+    }
+
+    /**
+     * Convert a negative BigDecimal to BigInteger
+     */
+    public void testToBigIntegerNeg2() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+15";
+        BigInteger bNumber = new BigInteger("-123809648392384754573567356745735635678902957849");
+        BigDecimal aNumber = new BigDecimal(a);
+        BigInteger result = aNumber.toBigInteger();
+        assertTrue("incorrect value", result.equals(bNumber));
+    }
+
+    /**
+     * Convert a negative BigDecimal to BigInteger
+     */
+    public void testToBigIntegerNeg3() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+45";
+        BigInteger bNumber = new BigInteger("-123809648392384754573567356745735635678902957849027687876782870000000000000000");
+        BigDecimal aNumber = new BigDecimal(a);
+        BigInteger result = aNumber.toBigInteger();
+         assertTrue("incorrect value", result.equals(bNumber));
+    }
+
+    /**
+     * Convert a small BigDecimal to BigInteger
+     */
+    public void testToBigIntegerZero() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E-500";
+        BigInteger bNumber = new BigInteger("0");
+        BigDecimal aNumber = new BigDecimal(a);
+        BigInteger result = aNumber.toBigInteger();
+        assertTrue("incorrect value", result.equals(bNumber));
+    }
+
+    /**
+     * Convert a negative BigDecimal with a negative exponent 
+     * to a plain string representation;
+     * scale == 0.
+     */
+     public void testToPlainStringNegNegExp() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E-100";
+        BigDecimal aNumber = new BigDecimal(a);
+        String result = "-0.000000000000000000000000000000000000000000000000000000000000000000012380964839238475457356735674573563567890295784902768787678287";
+        assertTrue("incorrect value", aNumber.toPlainString().equals(result));
+    }
+
+    /**
+     * Convert a negative BigDecimal with a positive exponent
+     * to a plain string representation;
+     * scale == 0.
+     */
+     public void testToPlainStringNegPosExp() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E100";
+        BigDecimal aNumber = new BigDecimal(a);
+        String result = "-1238096483923847545735673567457356356789029578490276878767828700000000000000000000000000000000000000000000000000000000000000000000000";
+        assertTrue("incorrect value", aNumber.toPlainString().equals(result));
+    }
+
+    /**
+     * Convert a positive BigDecimal with a negative exponent
+     * to a plain string representation;
+     * scale == 0.
+     */
+     public void testToPlainStringPosNegExp() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E-100";
+        BigDecimal aNumber = new BigDecimal(a);
+        String result = "0.000000000000000000000000000000000000000000000000000000000000000000012380964839238475457356735674573563567890295784902768787678287";
+        assertTrue("incorrect value", aNumber.toPlainString().equals(result));
+    }
+
+    /**
+     * Convert a negative BigDecimal with a negative exponent
+     * to a plain string representation;
+     * scale == 0.
+     */
+     public void testToPlainStringPosPosExp() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+100";
+        BigDecimal aNumber = new BigDecimal(a);
+        String result = "1238096483923847545735673567457356356789029578490276878767828700000000000000000000000000000000000000000000000000000000000000000000000";
+        assertTrue("incorrect value", aNumber.toPlainString().equals(result));
+    }
+
+    /**
+     * Convert a BigDecimal to a string representation;
+     * scale == 0.
+     */
+     public void testToStringZeroScale() {
+        String a = "-123809648392384754573567356745735635678902957849027687876782870";
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a));
+        String result = "-123809648392384754573567356745735635678902957849027687876782870";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+
+    /**
+     * Convert a positive BigDecimal to a string representation
+     */
+    public void testToStringPos() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E-500";
+        BigDecimal aNumber = new BigDecimal(a);
+        String result = "1.2380964839238475457356735674573563567890295784902768787678287E-468";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+
+    /**
+     * Convert a negative BigDecimal to a string representation
+     */
+    public void testToStringNeg() {
+        String a = "-123.4564563673567380964839238475457356735674573563567890295784902768787678287E-5";
+        BigDecimal aNumber = new BigDecimal(a);
+        String result = "-0.001234564563673567380964839238475457356735674573563567890295784902768787678287";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+
+    /**
+     * Create a BigDecimal from a positive long value; scale == 0
+     */
+    public void testValueOfPosZeroScale() {
+        long a = 98374823947823578L;
+        BigDecimal aNumber = BigDecimal.valueOf(a);
+        String result = "98374823947823578";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+
+    /**
+     * Create a BigDecimal from a negative long value; scale is 0
+     */
+    public void testValueOfNegZeroScale() {
+        long a = -98374823947823578L;
+        BigDecimal aNumber = BigDecimal.valueOf(a);
+        String result = "-98374823947823578";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+
+    /**
+     * Create a BigDecimal from a negative long value; scale is positive
+     */
+    public void testValueOfNegScalePos() {
+        long a = -98374823947823578L;
+        int scale = 12;
+        BigDecimal aNumber = BigDecimal.valueOf(a, scale);
+        String result = "-98374.823947823578";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+
+    /**
+     * Create a BigDecimal from a negative long value; scale is negative
+     */
+    public void testValueOfNegScaleNeg() {
+        long a = -98374823947823578L;
+        int scale = -12;
+        BigDecimal aNumber = BigDecimal.valueOf(a, scale);
+        String result = "-9.8374823947823578E+28";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+
+    /**
+     * Create a BigDecimal from a negative long value; scale == 0
+     */
+    public void testValueOfPosScalePos() {
+        long a = 98374823947823578L;
+        int scale = 12;
+        BigDecimal aNumber = BigDecimal.valueOf(a, scale);
+        String result = "98374.823947823578";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+
+    /**
+     * Create a BigDecimal from a negative long value; scale == 0
+     */
+    public void testValueOfPosScaleNeg() {
+        long a = 98374823947823578L;
+        int scale = -12;
+        BigDecimal aNumber = BigDecimal.valueOf(a, scale);
+        String result = "9.8374823947823578E+28";
+        assertTrue("incorrect value", aNumber.toString().equals(result));
+    }
+}



Mime
View raw message