harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r395476 [2/3] - in /incubator/harmony/enhanced/classlib/trunk/modules/math/src: main/java/java/math/ test/java/org/apache/harmony/tests/java/math/ test/java/tests/api/java/math/
Date Thu, 20 Apr 2006 04:13:47 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalArithmeticTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalArithmeticTest.java?rev=395476&r1=395475&r2=395476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalArithmeticTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalArithmeticTest.java Wed Apr 19 21:13:44 2006
@@ -15,14 +15,17 @@
  */
 /**
  * @author Elena Semukhina
- * @version $Revision: 1.3.6.3 $
+ * @version $Revision$
  */
 
 package org.apache.harmony.tests.java.math;
 
-import junit.framework.TestCase;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.math.MathContext;
+import java.math.RoundingMode;
+
+import junit.framework.TestCase;
 
 /**
  * Class:  java.math.BigDecimal
@@ -42,8 +45,26 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Add two numbers of equal positive scales using MathContext
+     */
+    public void testAddMathContextEqualScalePosPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 10;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "1.2313E+41";
+        int cScale = -37;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(5, RoundingMode.UP);
+        BigDecimal result = aNumber.add(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -59,8 +80,26 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Add two numbers of equal negative scales using MathContext
+     */
+    public void testAddMathContextEqualScaleNegNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = -10;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "1.2312E+61";
+        int cScale = -57;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(5, RoundingMode.FLOOR);
+        BigDecimal result = aNumber.add(bNumber, mc);
+        assertEquals("incorrect value ", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -76,8 +115,26 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Add two numbers of different scales using MathContext; the first is positive
+     */
+    public void testAddMathContextDiffScalePosNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "7.47233429416141E+45";
+        int cScale = -31;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(15, RoundingMode.CEILING);
+        BigDecimal result = aNumber.add(bNumber, mc);
+        assertEquals("incorrect value", c, c.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -93,8 +150,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -110,8 +167,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -127,8 +184,26 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Subtract two numbers of equal positive scales using MathContext
+     */
+    public void testSubtractMathContextEqualScalePosPos() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 10;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 10;
+        String c = "1.23121247898749E+41";
+        int cScale = -27;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(15, RoundingMode.CEILING);
+        BigDecimal result = aNumber.subtract(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -144,8 +219,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -161,8 +236,27 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Subtract two numbers of different scales using MathContext;
+     *  the first is positive
+     */
+    public void testSubtractMathContextDiffScalePosNeg() {
+        String a = "1231212478987482988429808779810457634781384756794987";
+        int aScale = 15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -10;
+        String c = "-7.4723342916989754E+45";
+        int cScale = -29;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(17, RoundingMode.DOWN);
+        BigDecimal result = aNumber.subtract(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -178,8 +272,27 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Subtract two numbers of different scales using MathContext;
+     *  the first is negative
+     */
+    public void testSubtractMathContextDiffScaleNegPos() {
+        String a = "986798656676789766678767876078779810457634781384756794987";
+        int aScale = -15;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 40;
+        String c = "9.867986566767897666787678760787798104576347813847567949870000000000000E+71";
+        int cScale = -2;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(70, RoundingMode.HALF_DOWN);
+        BigDecimal result = aNumber.subtract(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -195,8 +308,26 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Multiply two numbers of positive scales using MathContext
+     */
+    public void testMultiplyMathContextScalePosPos() {
+        String a = "97665696756578755423325476545428779810457634781384756794987";
+        int aScale = -25;
+        String b = "87656965586786097685674786576598865";
+        int bScale = 10;
+        String c = "8.561078619600910561431314228543672720908E+108";
+        int cScale = -69;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(40, RoundingMode.HALF_DOWN);
+        BigDecimal result = aNumber.multiply(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -212,8 +343,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -229,8 +360,26 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Multiply two numbers of different scales using MathContext
+     */
+    public void testMultiplyMathContextDiffScalePosNeg() {
+        String a = "987667796597975765768768767866756808779810457634781384756794987";
+        int aScale = 100;
+        String b = "747233429293018787918347987234564568";
+        int bScale = -70;
+        String c = "7.3801839465418518653942222612429081498248509257207477E+68";
+        int cScale = -16;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(53, RoundingMode.HALF_UP);
+        BigDecimal result = aNumber.multiply(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -246,8 +395,86 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * Multiply two numbers of different scales using MathContext
+     */
+    public void testMultiplyMathContextDiffScaleNegPos() {
+        String a = "488757458676796558668876576576579097029810457634781384756794987";
+        int aScale = -63;
+        String b = "747233429293018787918347987234564568";
+        int bScale = 63;
+        String c = "3.6521591193960361339707130098174381429788164316E+98";
+        int cScale = -52;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        MathContext mc = new MathContext(47, RoundingMode.HALF_UP);
+        BigDecimal result = aNumber.multiply(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * pow(int)
+     */
+    public void testPow() {
+        String a = "123121247898748298842980";
+        int aScale = 10;
+        int exp = 10;
+        String c = "8004424019039195734129783677098845174704975003788210729597" +
+                   "4875206425711159855030832837132149513512555214958035390490" +
+                   "798520842025826.594316163502809818340013610490541783276343" +
+                   "6514490899700151256484355936102754469438371850240000000000";
+        int cScale = 100;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.pow(exp);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * pow(0)
+     */
+    public void testPow0() {
+        String a = "123121247898748298842980";
+        int aScale = 10;
+        int exp = 0;
+        String c = "1";
+        int cScale = 0;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.pow(exp);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * ZERO.pow(0)
+     */
+    public void testZeroPow0() {
+        String c = "1";
+        int cScale = 0;
+        BigDecimal result = BigDecimal.ZERO.pow(0);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
+    }
+
+    /**
+     * pow(int, MathContext)
+     */
+    public void testPowMathContext() {
+        String a = "123121247898748298842980";
+        int aScale = 10;
+        int exp = 10;
+        String c = "8.0044E+130";
+        int cScale = -126;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        MathContext mc = new MathContext(5, RoundingMode.HALF_UP);
+        BigDecimal result = aNumber.pow(exp, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", cScale, result.scale());
     }
 
     /**
@@ -259,7 +486,7 @@
         BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
         BigDecimal bNumber = BigDecimal.valueOf(0L);
         try {
-            BigDecimal result = aNumber.divide(bNumber, BigDecimal.ROUND_UNNECESSARY);
+            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"));
@@ -277,7 +504,7 @@
         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);
+            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"));
@@ -295,7 +522,7 @@
         BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
         BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
         try {
-            BigDecimal result = aNumber.divide(bNumber, 100);
+            aNumber.divide(bNumber, 100);
             fail("IllegalArgumentException has not been caught");
         } catch (IllegalArgumentException e) {
             assertTrue("Improper exception message", e.getMessage().equals("invalid rounding mode"));
@@ -315,8 +542,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -332,8 +559,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -349,8 +576,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -366,8 +593,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -383,8 +610,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -400,8 +627,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -417,8 +644,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -434,8 +661,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -451,8 +678,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -468,8 +695,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -485,8 +712,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -502,8 +729,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -519,8 +746,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -536,8 +763,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -553,8 +780,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -570,8 +797,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -587,8 +814,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -604,8 +831,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -621,8 +848,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -638,8 +865,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -655,8 +882,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -672,8 +899,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -689,8 +916,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -706,8 +933,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
     
     /**
@@ -723,8 +950,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -740,8 +967,8 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 
     /**
@@ -757,7 +984,626 @@
         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);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * Divide to BigDecimal
+     */
+    public void testDivideBigDecimal1() {
+        String a = "-37361671119238118911893939591735";
+        int aScale = 10;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        String c = "-5E+4";
+        int resScale = -4;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * Divide to BigDecimal
+     */
+    public void testDivideBigDecimal2() {
+        String a = "-37361671119238118911893939591735";
+        int aScale = 10;
+        String b = "74723342238476237823787879183470";
+        int bScale = -15;
+        String c = "-5E-26";
+        int resScale = 26;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, scale, RoundingMode)
+     */
+    public void testDivideBigDecimalScaleRoundingModeUP() {
+        String a = "-37361671119238118911893939591735";
+        int aScale = 10;
+        String b = "74723342238476237823787879183470";
+        int bScale = -15;
+        int newScale = 31;
+        RoundingMode rm = RoundingMode.UP;
+        String c = "-5.00000E-26";
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, newScale, rm);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", newScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, scale, RoundingMode)
+     */
+    public void testDivideBigDecimalScaleRoundingModeDOWN() {
+        String a = "-37361671119238118911893939591735";
+        int aScale = 10;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        int newScale = 31;
+        RoundingMode rm = RoundingMode.DOWN;
+        String c = "-50000.0000000000000000000000000000000";
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, newScale, rm);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", newScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, scale, RoundingMode)
+     */
+    public void testDivideBigDecimalScaleRoundingModeCEILING() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 100;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        int newScale = 45;
+        RoundingMode rm = RoundingMode.CEILING;
+        String c = "1E-45";
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, newScale, rm);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", newScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, scale, RoundingMode)
+     */
+    public void testDivideBigDecimalScaleRoundingModeFLOOR() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 100;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        int newScale = 45;
+        RoundingMode rm = RoundingMode.FLOOR;
+        String c = "0E-45";
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, newScale, rm);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", newScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, scale, RoundingMode)
+     */
+    public void testDivideBigDecimalScaleRoundingModeHALF_UP() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = -51;
+        String b = "74723342238476237823787879183470";
+        int bScale = 45;
+        int newScale = 3;
+        RoundingMode rm = RoundingMode.HALF_UP;
+        String c = "50000260373164286401361913262100972218038099522752460421" +
+                   "05959924024355721031761947728703598332749334086415670525" +
+                   "3761096961.670";
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, newScale, rm);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", newScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, scale, RoundingMode)
+     */
+    public void testDivideBigDecimalScaleRoundingModeHALF_DOWN() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 5;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        int newScale = 7;
+        RoundingMode rm = RoundingMode.HALF_DOWN;
+        String c = "500002603731642864013619132621009722.1803810";
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, newScale, rm);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", newScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, scale, RoundingMode)
+     */
+    public void testDivideBigDecimalScaleRoundingModeHALF_EVEN() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 5;
+        String b = "74723342238476237823787879183470";
+        int bScale = 15;
+        int newScale = 7;
+        RoundingMode rm = RoundingMode.HALF_EVEN;
+        String c = "500002603731642864013619132621009722.1803810";
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, newScale, rm);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", newScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, MathContext)
+     */
+    public void testDivideBigDecimalScaleMathContextUP() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 15;
+        String b = "748766876876723342238476237823787879183470";
+        int bScale = 10;
+        int precision = 21;
+        RoundingMode rm = RoundingMode.UP;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "49897861180.2562512996";
+        int resScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, MathContext)
+     */
+    public void testDivideBigDecimalScaleMathContextDOWN() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 15;
+        String b = "748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 21;
+        RoundingMode rm = RoundingMode.DOWN;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "4.98978611802562512995E+70";
+        int resScale = -50;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, MathContext)
+     */
+    public void testDivideBigDecimalScaleMathContextCEILING() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 15;
+        String b = "748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 21;
+        RoundingMode rm = RoundingMode.CEILING;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "4.98978611802562512996E+70";
+        int resScale = -50;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, MathContext)
+     */
+    public void testDivideBigDecimalScaleMathContextFLOOR() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 15;
+        String b = "748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 21;
+        RoundingMode rm = RoundingMode.FLOOR;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "4.98978611802562512995E+70";
+        int resScale = -50;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, MathContext)
+     */
+    public void testDivideBigDecimalScaleMathContextHALF_UP() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 21;
+        RoundingMode rm = RoundingMode.HALF_UP;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "2.77923185514690367475E+26";
+        int resScale = -6;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, MathContext)
+     */
+    public void testDivideBigDecimalScaleMathContextHALF_DOWN() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 21;
+        RoundingMode rm = RoundingMode.HALF_DOWN;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "2.77923185514690367475E+26";
+        int resScale = -6;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divide(BigDecimal, MathContext)
+     */
+    public void testDivideBigDecimalScaleMathContextHALF_EVEN() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 21;
+        RoundingMode rm = RoundingMode.HALF_EVEN;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "2.77923185514690367475E+26";
+        int resScale = -6;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divide(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divideToIntegralValue(BigDecimal)
+     */
+    public void testDivideToIntegralValue() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        String c = "277923185514690367474770683";
+        int resScale = 0;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divideToIntegralValue(bNumber);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divideToIntegralValue(BigDecimal, MathContext)
+     */
+    public void testDivideToIntegralValueMathContextUP() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 32;
+        RoundingMode rm = RoundingMode.UP;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "277923185514690367474770683";
+        int resScale = 0;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divideToIntegralValue(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * divideToIntegralValue(BigDecimal, MathContext)
+     */
+    public void testDivideToIntegralValueMathContextDOWN() {
+        String a = "3736186567876876578956958769675785435673453453653543654354365435675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 75;
+        RoundingMode rm = RoundingMode.DOWN;
+        MathContext mc = new MathContext(precision, rm);
+        String c = "2.7792318551469036747477068339450205874992634417590178670822889E+62";
+        int resScale = -1;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.divideToIntegralValue(bNumber, mc);
+        assertEquals("incorrect value", c, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+    
+    /**
+     * divideAndRemainder(BigDecimal)
+     */
+    public void testDivideAndRemainder1() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        String res = "277923185514690367474770683";
+        int resScale = 0;
+        String rem = "1.3032693871288309587558885943391070087960319452465789990E-15";
+        int remScale = 70;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result[] = aNumber.divideAndRemainder(bNumber);
+        assertEquals("incorrect quotient value", res, result[0].toString());
+        assertEquals("incorrect quotient scale", resScale, result[0].scale());
+        assertEquals("incorrect remainder value", rem, result[1].toString());
+        assertEquals("incorrect remainder scale", remScale, result[1].scale());
+    }
+
+    /**
+     * divideAndRemainder(BigDecimal)
+     */
+    public void testDivideAndRemainder2() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = -45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        String res = "2779231855146903674747706830969461168692256919247547952" +
+                     "2608549363170374005512836303475980101168105698072946555" +
+                     "6862849";
+        int resScale = 0;
+        String rem = "3.4935796954060524114470681810486417234751682675102093970E-15";
+        int remScale = 70;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result[] = aNumber.divideAndRemainder(bNumber);
+        assertEquals("incorrect quotient value", res, result[0].toString());
+        assertEquals("incorrect quotient scale", resScale, result[0].scale());
+        assertEquals("incorrect remainder value", rem, result[1].toString());
+        assertEquals("incorrect remainder scale", remScale, result[1].scale());
+    }
+    
+    /**
+     * divideAndRemainder(BigDecimal, MathContext)
+     */
+    public void testDivideAndRemainderMathContextUP() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 70;
+        int precision = 75;
+        RoundingMode rm = RoundingMode.UP;
+        MathContext mc = new MathContext(precision, rm);
+        String res = "277923185514690367474770683";
+        int resScale = 0;
+        String rem = "1.3032693871288309587558885943391070087960319452465789990E-15";
+        int remScale = 70;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result[] = aNumber.divideAndRemainder(bNumber, mc);
+        assertEquals("incorrect quotient value", res, result[0].toString());
+        assertEquals("incorrect quotient scale", resScale, result[0].scale());
+        assertEquals("incorrect remainder value", rem, result[1].toString());
+        assertEquals("incorrect remainder scale", remScale, result[1].scale());
+    }
+
+    /**
+     * divideAndRemainder(BigDecimal, MathContext)
+     */
+    public void testDivideAndRemainderMathContextDOWN() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 20;
+        int precision = 15;
+        RoundingMode rm = RoundingMode.DOWN;
+        MathContext mc = new MathContext(precision, rm);
+        String res = "0E-25";
+        int resScale = 25;
+        String rem = "3736186567876.876578956958765675671119238118911893939591735";
+        int remScale = 45;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result[] = aNumber.divideAndRemainder(bNumber, mc);
+        assertEquals("incorrect quotient value", res, result[0].toString());
+        assertEquals("incorrect quotient scale", resScale, result[0].scale());
+        assertEquals("incorrect remainder value", rem, result[1].toString());
+        assertEquals("incorrect remainder scale", remScale, result[1].scale());
+    }
+    
+    /**
+     * remainder(BigDecimal)
+     */
+    public void testRemainder1() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 10;
+        String res = "3736186567876.876578956958765675671119238118911893939591735";
+        int resScale = 45;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.remainder(bNumber);
+        assertEquals("incorrect quotient value", res, result.toString());
+        assertEquals("incorrect quotient scale", resScale, result.scale());
+    }
+
+    /**
+     * remainder(BigDecimal)
+     */
+    public void testRemainder2() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = -45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 10;
+        String res = "1149310942946292909508821656680979993738625937.2065885780";
+        int resScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.remainder(bNumber);
+        assertEquals("incorrect quotient value", res, result.toString());
+        assertEquals("incorrect quotient scale", resScale, result.scale());
+    }
+
+    /**
+     * remainder(BigDecimal, MathContext)
+     */
+    public void testRemainderMathContextHALF_UP() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 10;
+        int precision = 15;
+        RoundingMode rm = RoundingMode.HALF_UP;
+        MathContext mc = new MathContext(precision, rm);
+        String res = "3736186567876.876578956958765675671119238118911893939591735";
+        int resScale = 45;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.remainder(bNumber, mc);
+        assertEquals("incorrect quotient value", res, result.toString());
+        assertEquals("incorrect quotient scale", resScale, result.scale());
+    }
+
+    /**
+     * remainder(BigDecimal, MathContext)
+     */
+    public void testRemainderMathContextHALF_DOWN() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = -45;
+        String b = "134432345432345748766876876723342238476237823787879183470";
+        int bScale = 10;
+        int precision = 75;
+        RoundingMode rm = RoundingMode.HALF_DOWN;
+        MathContext mc = new MathContext(precision, rm);
+        String res = "1149310942946292909508821656680979993738625937.2065885780";
+        int resScale = 10;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
+        BigDecimal result = aNumber.remainder(bNumber, mc);
+        assertEquals("incorrect quotient value", res, result.toString());
+        assertEquals("incorrect quotient scale", resScale, result.scale());
+    }
+
+    /**
+     * round(BigDecimal, MathContext)
+     */
+    public void testRoundMathContextHALF_DOWN() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = -45;
+        int precision = 75;
+        RoundingMode rm = RoundingMode.HALF_DOWN;
+        MathContext mc = new MathContext(precision, rm);
+        String res = "3.736186567876876578956958765675671119238118911893939591735E+102";
+        int resScale = -45;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.round(mc);
+        assertEquals("incorrect quotient value", res, result.toString());
+        assertEquals("incorrect quotient scale", resScale, result.scale());
+    }
+
+    /**
+     * round(BigDecimal, MathContext)
+     */
+    public void testRoundMathContextHALF_UP() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        int precision = 15;
+        RoundingMode rm = RoundingMode.HALF_UP;
+        MathContext mc = new MathContext(precision, rm);
+        String res = "3736186567876.88";
+        int resScale = 2;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.round(mc);
+        assertEquals("incorrect quotient value", res, result.toString());
+        assertEquals("incorrect quotient scale", resScale, result.scale());
+    }
+
+    /**
+     * round(BigDecimal, MathContext) when precision = 0
+     */
+    public void testRoundMathContextPrecision0() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        int precision = 0;
+        RoundingMode rm = RoundingMode.HALF_UP;
+        MathContext mc = new MathContext(precision, rm);
+        String res = "3736186567876.876578956958765675671119238118911893939591735";
+        int resScale = 2;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.round(mc);
+        assertEquals("incorrect quotient value", res, result.toString());
+        assertEquals("incorrect quotient scale", aScale, result.scale());
+    }
+
+
+    /**
+     * ulp() of a positive BigDecimal
+     */
+    public void testUlpPos() {
+        String a = "3736186567876876578956958765675671119238118911893939591735";
+        int aScale = -45;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.ulp();
+        String res = "1E+45";
+        int resScale = -45;
+        assertEquals("incorrect value", res, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * ulp() of a negative BigDecimal
+     */
+    public void testUlpNeg() {
+        String a = "-3736186567876876578956958765675671119238118911893939591735";
+        int aScale = 45;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.ulp();
+        String res = "1E-45";
+        int resScale = 45;
+        assertEquals("incorrect value", res, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
+    }
+
+    /**
+     * ulp() of a negative BigDecimal
+     */
+    public void testUlpZero() {
+        String a = "0";
+        int aScale = 2;
+        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+        BigDecimal result = aNumber.ulp();
+        String res = "0.01";
+        int resScale = 2;
+        assertEquals("incorrect value", res, result.toString());
+        assertEquals("incorrect scale", resScale, result.scale());
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalCompareTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalCompareTest.java?rev=395476&r1=395475&r2=395476&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalCompareTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/org/apache/harmony/tests/java/math/BigDecimalCompareTest.java Wed Apr 19 21:13:44 2006
@@ -15,14 +15,17 @@
  */
 /**
  * @author Elena Semukhina
- * @version $Revision: 1.4.6.2 $
+ * @version $Revision$
  */
 
 package org.apache.harmony.tests.java.math;
 
-import junit.framework.TestCase;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.math.MathContext;
+import java.math.RoundingMode;
+
+import junit.framework.TestCase;
 
 /**
  * Class:  java.math.BigDecimal
@@ -37,7 +40,7 @@
         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
         BigDecimal aNumber = new BigDecimal(a);
         String result = "123809648392384754573567356745735635678902957849027687.87678287";
-        assertTrue("incorrect value", aNumber.abs().toString().equals(result));
+        assertEquals("incorrect value", result, aNumber.abs().toString());
     }
 
     /**
@@ -47,7 +50,39 @@
         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
         BigDecimal aNumber = new BigDecimal(a);
         String result = "123809648392384754573567356745735635678902957849027687.87678287";
-        assertTrue("incorrect value", aNumber.abs().toString().equals(result));
+        assertEquals("incorrect value", result, aNumber.abs().toString());
+    }
+
+    /**
+     * Abs(MathContext) of a negative BigDecimal
+     */
+    public void testAbsMathContextNeg() {
+        String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        int precision = 15;
+        RoundingMode rm = RoundingMode.HALF_DOWN;
+        MathContext mc = new MathContext(precision, rm);
+        String result = "1.23809648392385E+53";
+        int resScale = -39;
+        BigDecimal res = aNumber.abs(mc);
+        assertEquals("incorrect value", result, res.toString());
+        assertEquals("incorrect scale", resScale, res.scale());
+    }
+
+    /**
+     * Abs(MathContext) of a positive BigDecimal
+     */
+    public void testAbsMathContextPos() {
+        String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
+        BigDecimal aNumber = new BigDecimal(a);
+        int precision = 41;
+        RoundingMode rm = RoundingMode.HALF_EVEN;
+        MathContext mc = new MathContext(precision, rm);
+        String result = "1.2380964839238475457356735674573563567890E+53";
+        int resScale = -13;
+        BigDecimal res = aNumber.abs(mc);
+        assertEquals("incorrect value", result, res.toString());
+        assertEquals("incorrect scale", resScale, res.scale());
     }
 
     /**
@@ -61,7 +96,7 @@
         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);
+        assertEquals("incorrect result", result, aNumber.compareTo(bNumber));
     }
 
     /**
@@ -75,7 +110,7 @@
         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);
+        assertEquals("incorrect result", result, aNumber.compareTo(bNumber));
     }
 
     /**
@@ -89,7 +124,7 @@
         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);
+        assertEquals("incorrect result", result, aNumber.compareTo(bNumber));
     }
 
     /**
@@ -103,7 +138,7 @@
         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);
+        assertEquals("incorrect result", result, aNumber.compareTo(bNumber));
     }
 
     /**
@@ -117,7 +152,7 @@
         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);
+        assertEquals("incorrect result", result, aNumber.compareTo(bNumber));
     }
 
     /**
@@ -131,7 +166,7 @@
         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);
+        assertEquals("incorrect result", result, aNumber.compareTo(bNumber));
     }
 
     /**
@@ -144,7 +179,7 @@
        int bScale = 13;
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
-       assertTrue(!aNumber.equals(bNumber));
+       assertFalse(aNumber.equals(bNumber));
     }
 
     /**
@@ -157,7 +192,7 @@
        int bScale = 13;
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
-       assertTrue(!aNumber.equals(bNumber));
+       assertFalse(aNumber.equals(bNumber));
     }
 
     /**
@@ -168,7 +203,7 @@
        int aScale = -24;
        String b = "92948782094488478231212478987482988429808779810457634781384756794987";
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
-       assertTrue(!aNumber.equals(b));
+       assertFalse(aNumber.equals(b));
     }
 
     /**
@@ -181,7 +216,7 @@
        int bScale = -24;
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
-       assertTrue(aNumber.equals(bNumber));
+       assertEquals(aNumber, bNumber);
     }
 
     /**
@@ -204,7 +239,7 @@
        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());
+       assertEquals("incorrect value", aNumber.hashCode(), bNumber.hashCode());
     }
 
     /**
@@ -233,7 +268,7 @@
        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));
+       assertEquals("incorrect value", cNumber, aNumber.max(bNumber));
     }
 
     /**
@@ -249,7 +284,7 @@
        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));
+       assertEquals("incorrect value", cNumber, aNumber.max(bNumber));
     }
 
     /**
@@ -265,7 +300,7 @@
        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));
+       assertEquals("incorrect value", cNumber, aNumber.max(bNumber));
     }
 
     /**
@@ -281,7 +316,7 @@
        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));
+       assertEquals("incorrect value", cNumber, aNumber.min(bNumber));
     }
 
     /**
@@ -297,7 +332,7 @@
        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));
+       assertEquals("incorrect value", cNumber, aNumber.min(bNumber));
     }
 
     /**
@@ -313,7 +348,67 @@
        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));
+       assertEquals("incorrect value", cNumber, aNumber.min(bNumber));
+    }
+
+    /**
+     * plus() for a positive BigDecimal
+     */
+    public void testPlusPositive() {
+       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);
+       assertEquals("incorrect value", cNumber, aNumber.plus());
+    }
+
+    /**
+     * plus(MathContext) for a positive BigDecimal
+     */
+    public void testPlusMathContextPositive() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       int precision = 37;
+       RoundingMode rm = RoundingMode.FLOOR;
+       MathContext mc = new MathContext(precision, rm);
+       String c = "929487820944884782312124789.8748298842";
+       int cScale = 10;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal res = aNumber.plus(mc);
+       assertEquals("incorrect value", c, res.toString());
+       assertEquals("incorrect scale", cScale, res.scale());
+    }
+
+    /**
+     * plus() for a negative BigDecimal
+     */
+    public void testPlusNegative() {
+       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);
+       assertEquals("incorrect value", cNumber, aNumber.plus());
+    }
+
+    /**
+     * plus(MathContext) for a negative BigDecimal
+     */
+    public void testPlusMathContextNegative() {
+       String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 49;
+       int precision = 46;
+       RoundingMode rm = RoundingMode.CEILING;
+       MathContext mc = new MathContext(precision, rm);
+       String c = "-9294878209448847823.121247898748298842980877981";
+       int cScale = 27;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal res = aNumber.plus(mc);
+       assertEquals("incorrect value", c, res.toString());
+       assertEquals("incorrect scale", cScale, res.scale());
     }
 
     /**
@@ -326,7 +421,24 @@
        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));
+       assertEquals("incorrect value", cNumber, aNumber.negate());
+    }
+
+    /**
+     * negate(MathContext) for a positive BigDecimal
+     */
+    public void testNegateMathContextPositive() {
+       String a = "92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 41;
+       int precision = 37;
+       RoundingMode rm = RoundingMode.FLOOR;
+       MathContext mc = new MathContext(precision, rm);
+       String c = "-929487820944884782312124789.8748298842";
+       int cScale = 10;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal res = aNumber.negate(mc);
+       assertEquals("incorrect value", c, res.toString());
+       assertEquals("incorrect scale", cScale, res.scale());
     }
 
     /**
@@ -339,7 +451,24 @@
        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));
+       assertEquals("incorrect value", cNumber, aNumber.negate());
+    }
+
+    /**
+     * negate(MathContext) for a negative BigDecimal
+     */
+    public void testNegateMathContextNegative() {
+       String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
+       int aScale = 49;
+       int precision = 46;
+       RoundingMode rm = RoundingMode.CEILING;
+       MathContext mc = new MathContext(precision, rm);
+       String c = "9294878209448847823.121247898748298842980877981";
+       int cScale = 27;
+       BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
+       BigDecimal res = aNumber.negate(mc);
+       assertEquals("incorrect value", c, res.toString());
+       assertEquals("incorrect scale", cScale, res.scale());
     }
 
     /**
@@ -349,7 +478,7 @@
        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
        int aScale = 41;
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
-       assertTrue("incorrect value", aNumber.signum() == 1);
+       assertEquals("incorrect value", 1, aNumber.signum());
     }
 
     /**
@@ -359,7 +488,7 @@
        String a = "-92948782094488478231212478987482988429808779810457634781384756794987";
        int aScale = 41;
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
-       assertTrue("incorrect value", aNumber.signum() == -1);
+       assertEquals("incorrect value", -1, aNumber.signum());
     }
 
     /**
@@ -369,6 +498,6 @@
        String a = "0";
        int aScale = 41;
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
-       assertTrue("incorrect value", aNumber.signum() == 0);
+       assertEquals("incorrect value", 0, aNumber.signum());
     }
 }



Mime
View raw message