Home | History | Annotate | Download | only in math
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Elena Semukhina
     19  * @version $Revision$
     20  */
     21 
     22 package libcore.java.math;
     23 
     24 import java.math.BigDecimal;
     25 import java.math.BigInteger;
     26 import java.math.MathContext;
     27 import java.math.RoundingMode;
     28 import junit.framework.TestCase;
     29 
     30 public class OldBigDecimalCompareTest extends TestCase {
     31 
     32     public void testAbsMathContextNeg() {
     33         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
     34         BigDecimal aNumber = new BigDecimal(a);
     35         MathContext mc = new MathContext(34, RoundingMode.UP);
     36         assertEquals("incorrect value", "1.238096483923847545735673567457357E+53", aNumber.abs(mc).toString());
     37 
     38         mc = new MathContext(34, RoundingMode.DOWN);
     39         assertEquals("incorrect value", "1.238096483923847545735673567457356E+53", aNumber.abs(mc).toString());
     40 
     41         mc = new MathContext(34, RoundingMode.FLOOR);
     42         assertEquals("incorrect value", "1.238096483923847545735673567457356E+53", aNumber.abs(mc).toString());
     43 
     44         mc = new MathContext(34, RoundingMode.CEILING);
     45         assertEquals("incorrect value", "1.238096483923847545735673567457357E+53", aNumber.abs(mc).toString());
     46 
     47         mc = new MathContext(34, RoundingMode.UNNECESSARY);
     48         try {
     49             aNumber.abs(mc);
     50             fail("No ArithmeticException for RoundingMode.UNNECESSARY");
     51         } catch (ArithmeticException expected) {
     52         }
     53     }
     54 
     55     public void testNegateMathContextPositive() {
     56        String a = "92948782094488478231212478987482988429808779810457634781384756794987";
     57        MathContext mc = new MathContext(37, RoundingMode.FLOOR);
     58        BigDecimal aNumber = new BigDecimal(new BigInteger(a), 41);
     59        BigDecimal res = aNumber.negate(mc);
     60        assertEquals("incorrect value", "-929487820944884782312124789.8748298843", res.toString());
     61        assertEquals("incorrect scale", 10, res.scale());
     62     }
     63 }
     64