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 org.apache.harmony.math.tests.java.math;
     23 
     24 import dalvik.annotation.TestTargetClass;
     25 import dalvik.annotation.TestTargets;
     26 import dalvik.annotation.TestLevel;
     27 import dalvik.annotation.TestTargetNew;
     28 
     29 import java.math.BigDecimal;
     30 import java.math.BigInteger;
     31 import java.math.RoundingMode;
     32 import java.math.MathContext;
     33 
     34 import junit.framework.TestCase;
     35 @TestTargetClass(BigDecimal.class)
     36 /**
     37  * Class:  java.math.BigDecimal
     38  * Methods: doubleValue, floatValue, intValue, longValue,
     39  * valueOf, toString, toBigInteger
     40  */
     41 public class BigDecimalConvertTest extends TestCase {
     42     /**
     43      * Double value of a negative BigDecimal
     44      */
     45     @TestTargetNew(
     46         level = TestLevel.PARTIAL_COMPLETE,
     47         notes = "This is a complete subset of tests for doubleValue method.",
     48         method = "doubleValue",
     49         args = {}
     50     )
     51     public void testDoubleValueNeg() {
     52         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
     53         BigDecimal aNumber = new BigDecimal(a);
     54         double result = -1.2380964839238476E53;
     55         assertEquals("incorrect value", result, aNumber.doubleValue(), 0);
     56     }
     57 
     58     /**
     59      * Double value of a positive BigDecimal
     60      */
     61     @TestTargetNew(
     62         level = TestLevel.PARTIAL_COMPLETE,
     63         notes = "This is a complete subset of tests for doubleValue method.",
     64         method = "doubleValue",
     65         args = {}
     66     )
     67     public void testDoubleValuePos() {
     68         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
     69         BigDecimal aNumber = new BigDecimal(a);
     70         double result = 1.2380964839238476E53;
     71         assertEquals("incorrect value", result, aNumber.doubleValue(), 0);
     72     }
     73 
     74     /**
     75      * Double value of a large positive BigDecimal
     76      */
     77     @TestTargetNew(
     78         level = TestLevel.PARTIAL_COMPLETE,
     79         notes = "This is a complete subset of tests for doubleValue method.",
     80         method = "doubleValue",
     81         args = {}
     82     )
     83     public void testDoubleValuePosInfinity() {
     84         String a = "123809648392384754573567356745735.63567890295784902768787678287E+400";
     85         BigDecimal aNumber = new BigDecimal(a);
     86         double result = Double.POSITIVE_INFINITY;
     87         assertEquals("incorrect value", result, aNumber.doubleValue(), 0);
     88     }
     89 
     90     /**
     91      * Double value of a large negative BigDecimal
     92      */
     93     @TestTargetNew(
     94         level = TestLevel.PARTIAL_COMPLETE,
     95         notes = "This is a complete subset of tests for doubleValue method.",
     96         method = "doubleValue",
     97         args = {}
     98     )
     99     public void testDoubleValueNegInfinity() {
    100         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+400";
    101         BigDecimal aNumber = new BigDecimal(a);
    102         double result = Double.NEGATIVE_INFINITY;
    103         assertEquals("incorrect value", result, aNumber.doubleValue(), 0);
    104     }
    105 
    106     /**
    107      * Double value of a small negative BigDecimal
    108      */
    109     @TestTargetNew(
    110         level = TestLevel.PARTIAL_COMPLETE,
    111         notes = "This is a complete subset of tests for doubleValue method.",
    112         method = "doubleValue",
    113         args = {}
    114     )
    115     public void testDoubleValueMinusZero() {
    116         String a = "-123809648392384754573567356745735.63567890295784902768787678287E-400";
    117         BigDecimal aNumber = new BigDecimal(a);
    118         long minusZero = -9223372036854775808L;
    119         double result = aNumber.doubleValue();
    120         assertTrue("incorrect value", Double.doubleToLongBits(result) == minusZero);
    121     }
    122 
    123     /**
    124      * Double value of a small positive BigDecimal
    125      */
    126     @TestTargetNew(
    127         level = TestLevel.PARTIAL_COMPLETE,
    128         notes = "This is a complete subset of tests for doubleValue method.",
    129         method = "doubleValue",
    130         args = {}
    131     )
    132     public void testDoubleValuePlusZero() {
    133         String a = "123809648392384754573567356745735.63567890295784902768787678287E-400";
    134         BigDecimal aNumber = new BigDecimal(a);
    135         long zero = 0;
    136         double result = aNumber.doubleValue();
    137         assertTrue("incorrect value", Double.doubleToLongBits(result) == zero);
    138     }
    139 
    140     /**
    141      * Float value of a negative BigDecimal
    142      */
    143     @TestTargetNew(
    144         level = TestLevel.PARTIAL_COMPLETE,
    145         notes = "This is a complete subset of tests for floatValue method.",
    146         method = "floatValue",
    147         args = {}
    148     )
    149     public void testFloatValueNeg() {
    150         String a = "-1238096483923847.6356789029578E+21";
    151         BigDecimal aNumber = new BigDecimal(a);
    152         float result = -1.2380965E36F;
    153         assertTrue("incorrect value", aNumber.floatValue() == result);
    154     }
    155 
    156     /**
    157      * Float value of a positive BigDecimal
    158      */
    159     @TestTargetNew(
    160         level = TestLevel.PARTIAL_COMPLETE,
    161         notes = "This is a complete subset of tests for floatValue method.",
    162         method = "floatValue",
    163         args = {}
    164     )
    165     public void testFloatValuePos() {
    166         String a = "1238096483923847.6356789029578E+21";
    167         BigDecimal aNumber = new BigDecimal(a);
    168         float result = 1.2380965E36F;
    169         assertTrue("incorrect value", aNumber.floatValue() == result);
    170     }
    171 
    172     /**
    173      * Float value of a large positive BigDecimal
    174      */
    175     @TestTargetNew(
    176         level = TestLevel.PARTIAL_COMPLETE,
    177         notes = "This is a complete subset of tests for floatValue method.",
    178         method = "floatValue",
    179         args = {}
    180     )
    181     public void testFloatValuePosInfinity() {
    182         String a = "123809648373567356745735.6356789787678287E+200";
    183         BigDecimal aNumber = new BigDecimal(a);
    184         float result = Float.POSITIVE_INFINITY;
    185         assertTrue("incorrect value", aNumber.floatValue() == result);
    186     }
    187 
    188     /**
    189      * Float value of a large negative BigDecimal
    190      */
    191     @TestTargetNew(
    192         level = TestLevel.PARTIAL_COMPLETE,
    193         notes = "This is a complete subset of tests for floatValue method.",
    194         method = "floatValue",
    195         args = {}
    196     )
    197     public void testFloatValueNegInfinity() {
    198         String a = "-123809648392384755735.63567887678287E+200";
    199         BigDecimal aNumber = new BigDecimal(a);
    200         float result = Float.NEGATIVE_INFINITY;
    201         assertTrue("incorrect value", aNumber.floatValue() == result);
    202     }
    203 
    204     /**
    205      * Float value of a small negative BigDecimal
    206      */
    207     @TestTargetNew(
    208         level = TestLevel.PARTIAL_COMPLETE,
    209         notes = "This is a complete subset of tests for floatValue method.",
    210         method = "floatValue",
    211         args = {}
    212     )
    213     public void testFloatValueMinusZero() {
    214         String a = "-123809648392384754573567356745735.63567890295784902768787678287E-400";
    215         BigDecimal aNumber = new BigDecimal(a);
    216         int minusZero = -2147483648;
    217         float result = aNumber.floatValue();
    218         assertTrue("incorrect value", Float.floatToIntBits(result) == minusZero);
    219     }
    220 
    221     /**
    222      * Float value of a small positive BigDecimal
    223      */
    224     @TestTargetNew(
    225         level = TestLevel.PARTIAL_COMPLETE,
    226         notes = "This is a complete subset of tests for floatValue method.",
    227         method = "floatValue",
    228         args = {}
    229     )
    230     public void testFloatValuePlusZero() {
    231         String a = "123809648392384754573567356745735.63567890295784902768787678287E-400";
    232         BigDecimal aNumber = new BigDecimal(a);
    233         int zero = 0;
    234         float result = aNumber.floatValue();
    235         assertTrue("incorrect value", Float.floatToIntBits(result) == zero);
    236     }
    237 
    238     /**
    239      * Integer value of a negative BigDecimal
    240      */
    241     @TestTargetNew(
    242         level = TestLevel.PARTIAL_COMPLETE,
    243         notes = "This is a complete subset of tests for intValue method.",
    244         method = "intValue",
    245         args = {}
    246     )
    247     public void testIntValueNeg() {
    248         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
    249         BigDecimal aNumber = new BigDecimal(a);
    250         int result = 218520473;
    251         assertTrue("incorrect value", aNumber.intValue() == result);
    252     }
    253 
    254     /**
    255      * Integer value of a positive BigDecimal
    256      */
    257     @TestTargetNew(
    258         level = TestLevel.PARTIAL_COMPLETE,
    259         notes = "This is a complete subset of tests for intValue method.",
    260         method = "intValue",
    261         args = {}
    262     )
    263     public void testIntValuePos() {
    264         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
    265         BigDecimal aNumber = new BigDecimal(a);
    266         int result = -218520473;
    267         assertTrue("incorrect value", aNumber.intValue() == result);
    268     }
    269 
    270     /**
    271      * Long value of a negative BigDecimal
    272      */
    273     @TestTargetNew(
    274         level = TestLevel.PARTIAL_COMPLETE,
    275         notes = "This is a complete subset of tests for longValue method",
    276         method = "longValue",
    277         args = {}
    278     )
    279     public void testLongValueNeg() {
    280         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
    281         BigDecimal aNumber = new BigDecimal(a);
    282         long result = -1246043477766677607L;
    283         assertTrue("incorrect value", aNumber.longValue() == result);
    284     }
    285 
    286     /**
    287      * Long value of a positive BigDecimal
    288      */
    289     @TestTargetNew(
    290         level = TestLevel.PARTIAL_COMPLETE,
    291         notes = "This is a complete subset of tests for longValue method",
    292         method = "longValue",
    293         args = {}
    294     )
    295     public void testLongValuePos() {
    296         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
    297         BigDecimal aNumber = new BigDecimal(a);
    298         long result = 1246043477766677607L;
    299         assertTrue("incorrect value", aNumber.longValue() == result);
    300     }
    301 
    302     /**
    303      * scaleByPowerOfTen(int n)
    304      */
    305     @TestTargetNew(
    306         level = TestLevel.PARTIAL,
    307         notes = "ArithmeticException checking missed",
    308         method = "scaleByPowerOfTen",
    309         args = {int.class}
    310     )
    311     public void testScaleByPowerOfTen1() {
    312         String a = "1231212478987482988429808779810457634781384756794987";
    313         int aScale = 13;
    314         BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
    315         BigDecimal result = aNumber.scaleByPowerOfTen(10);
    316         String res = "1231212478987482988429808779810457634781384756794.987";
    317         int resScale = 3;
    318         assertEquals("incorrect value", res, result.toString());
    319         assertEquals("incorrect scale", resScale, result.scale());
    320     }
    321 
    322     /**
    323      * scaleByPowerOfTen(int n)
    324      */
    325     @TestTargetNew(
    326         level = TestLevel.PARTIAL,
    327         notes = "ArithmeticException checking missed",
    328         method = "scaleByPowerOfTen",
    329         args = {int.class}
    330     )
    331     public void testScaleByPowerOfTen2() {
    332         String a = "1231212478987482988429808779810457634781384756794987";
    333         int aScale = -13;
    334         BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
    335         BigDecimal result = aNumber.scaleByPowerOfTen(10);
    336         String res = "1.231212478987482988429808779810457634781384756794987E+74";
    337         int resScale = -23;
    338         assertEquals("incorrect value", res, result.toString());
    339         assertEquals("incorrect scale", resScale, result.scale());
    340     }
    341 
    342     /**
    343      * Convert a positive BigDecimal to BigInteger
    344      */
    345     @TestTargetNew(
    346         level = TestLevel.PARTIAL_COMPLETE,
    347         notes = "This is a complete subset of tests for toBigInteger method",
    348         method = "toBigInteger",
    349         args = {}
    350     )
    351     public void testToBigIntegerPos1() {
    352         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
    353         BigInteger bNumber = new BigInteger("123809648392384754573567356745735635678902957849027687");
    354         BigDecimal aNumber = new BigDecimal(a);
    355         BigInteger result = aNumber.toBigInteger();
    356         assertTrue("incorrect value", result.equals(bNumber));
    357     }
    358 
    359     /**
    360      * Convert a positive BigDecimal to BigInteger
    361      */
    362     @TestTargetNew(
    363         level = TestLevel.PARTIAL_COMPLETE,
    364         notes = "This is a complete subset of tests for toBigInteger method",
    365         method = "toBigInteger",
    366         args = {}
    367     )
    368     public void testToBigIntegerPos2() {
    369         String a = "123809648392384754573567356745735.63567890295784902768787678287E+15";
    370         BigInteger bNumber = new BigInteger("123809648392384754573567356745735635678902957849");
    371         BigDecimal aNumber = new BigDecimal(a);
    372         BigInteger result = aNumber.toBigInteger();
    373         assertTrue("incorrect value", result.equals(bNumber));
    374     }
    375 
    376     /**
    377      * Convert a positive BigDecimal to BigInteger
    378      */
    379     @TestTargetNew(
    380         level = TestLevel.PARTIAL_COMPLETE,
    381         notes = "This is a complete subset of tests for toBigInteger method",
    382         method = "toBigInteger",
    383         args = {}
    384     )
    385     public void testToBigIntegerPos3() {
    386         String a = "123809648392384754573567356745735.63567890295784902768787678287E+45";
    387         BigInteger bNumber = new BigInteger("123809648392384754573567356745735635678902957849027687876782870000000000000000");
    388         BigDecimal aNumber = new BigDecimal(a);
    389         BigInteger result = aNumber.toBigInteger();
    390         assertTrue("incorrect value", result.equals(bNumber));
    391     }
    392 
    393     /**
    394      * Convert a negative BigDecimal to BigInteger
    395      */
    396     @TestTargetNew(
    397         level = TestLevel.PARTIAL_COMPLETE,
    398         notes = "This is a complete subset of tests for toBigInteger method",
    399         method = "toBigInteger",
    400         args = {}
    401     )
    402     public void testToBigIntegerNeg1() {
    403         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
    404         BigInteger bNumber = new BigInteger("-123809648392384754573567356745735635678902957849027687");
    405         BigDecimal aNumber = new BigDecimal(a);
    406         BigInteger result = aNumber.toBigInteger();
    407         assertTrue("incorrect value", result.equals(bNumber));
    408     }
    409 
    410     /**
    411      * Convert a negative BigDecimal to BigInteger
    412      */
    413     @TestTargetNew(
    414         level = TestLevel.PARTIAL_COMPLETE,
    415         notes = "This is a complete subset of tests for toBigInteger method",
    416         method = "toBigInteger",
    417         args = {}
    418     )
    419     public void testToBigIntegerNeg2() {
    420         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+15";
    421         BigInteger bNumber = new BigInteger("-123809648392384754573567356745735635678902957849");
    422         BigDecimal aNumber = new BigDecimal(a);
    423         BigInteger result = aNumber.toBigInteger();
    424         assertTrue("incorrect value", result.equals(bNumber));
    425     }
    426 
    427     /**
    428      * Convert a negative BigDecimal to BigInteger
    429      */
    430     @TestTargetNew(
    431         level = TestLevel.PARTIAL_COMPLETE,
    432         notes = "This is a complete subset of tests for toBigInteger method",
    433         method = "toBigInteger",
    434         args = {}
    435     )
    436     public void testToBigIntegerNeg3() {
    437         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+45";
    438         BigInteger bNumber = new BigInteger("-123809648392384754573567356745735635678902957849027687876782870000000000000000");
    439         BigDecimal aNumber = new BigDecimal(a);
    440         BigInteger result = aNumber.toBigInteger();
    441         assertTrue("incorrect value", result.equals(bNumber));
    442     }
    443 
    444     /**
    445      * Convert a small BigDecimal to BigInteger
    446      */
    447     @TestTargetNew(
    448         level = TestLevel.PARTIAL_COMPLETE,
    449         notes = "This is a complete subset of tests for toBigInteger method",
    450         method = "toBigInteger",
    451         args = {}
    452     )
    453     public void testToBigIntegerZero() {
    454         String a = "-123809648392384754573567356745735.63567890295784902768787678287E-500";
    455         BigInteger bNumber = new BigInteger("0");
    456         BigDecimal aNumber = new BigDecimal(a);
    457         BigInteger result = aNumber.toBigInteger();
    458         assertTrue("incorrect value", result.equals(bNumber));
    459     }
    460 
    461     /**
    462      * toBigIntegerExact()
    463      */
    464     @TestTargetNew(
    465         level = TestLevel.PARTIAL_COMPLETE,
    466         notes = "This is a complete subset of tests for toBigIntegerExact method",
    467         method = "toBigIntegerExact",
    468         args = {}
    469     )
    470     public void testToBigIntegerExact1() {
    471         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+45";
    472         BigDecimal aNumber = new BigDecimal(a);
    473         String res = "-123809648392384754573567356745735635678902957849027687876782870000000000000000";
    474         BigInteger result = aNumber.toBigIntegerExact();
    475         assertEquals("incorrect value", res, result.toString());
    476     }
    477 
    478     /**
    479      * toBigIntegerExact()
    480      */
    481     @TestTargetNew(
    482         level = TestLevel.PARTIAL_COMPLETE,
    483         notes = "This is a complete subset of tests for toBigIntegerExact method",
    484         method = "toBigIntegerExact",
    485         args = {}
    486     )
    487     public void testToBigIntegerExactException() {
    488         String a = "-123809648392384754573567356745735.63567890295784902768787678287E-10";
    489         BigDecimal aNumber = new BigDecimal(a);
    490         try {
    491             aNumber.toBigIntegerExact();
    492             fail("java.lang.ArithmeticException has not been thrown");
    493         } catch (java.lang.ArithmeticException e) {
    494             return;
    495         }
    496     }
    497 
    498     /**
    499      * Convert a positive BigDecimal to an engineering string representation
    500      */
    501     @TestTargetNew(
    502         level = TestLevel.PARTIAL_COMPLETE,
    503         notes = "This is a complete subset of tests for toEngineeringString method",
    504         method = "toEngineeringString",
    505         args = {}
    506     )
    507     public void testToEngineeringStringPos() {
    508         String a = "123809648392384754573567356745735.63567890295784902768787678287E-501";
    509         BigDecimal aNumber = new BigDecimal(a);
    510         String result = "123.80964839238475457356735674573563567890295784902768787678287E-471";
    511         assertEquals("incorrect value", result, aNumber.toEngineeringString());
    512     }
    513 
    514     /**
    515      * Convert a negative BigDecimal to an engineering string representation
    516      */
    517     @TestTargetNew(
    518         level = TestLevel.PARTIAL_COMPLETE,
    519         notes = "This is a complete subset of tests for toEngineeringString method",
    520         method = "toEngineeringString",
    521         args = {}
    522     )
    523     public void testToEngineeringStringNeg() {
    524         String a = "-123809648392384754573567356745735.63567890295784902768787678287E-501";
    525         BigDecimal aNumber = new BigDecimal(a);
    526         String result = "-123.80964839238475457356735674573563567890295784902768787678287E-471";
    527         assertEquals("incorrect value", result, aNumber.toEngineeringString());
    528     }
    529 
    530     /**
    531      * Convert a negative BigDecimal to an engineering string representation
    532      */
    533     @TestTargetNew(
    534         level = TestLevel.PARTIAL_COMPLETE,
    535         notes = "This is a complete subset of tests for toEngineeringString method",
    536         method = "toEngineeringString",
    537         args = {}
    538     )
    539     public void testToEngineeringStringZeroPosExponent() {
    540         String a = "0.0E+16";
    541         BigDecimal aNumber = new BigDecimal(a);
    542         String result = "0E+15";
    543         assertEquals("incorrect value", result, aNumber.toEngineeringString());
    544     }
    545 
    546     /**
    547      * Convert a negative BigDecimal to an engineering string representation
    548      */
    549     @TestTargetNew(
    550         level = TestLevel.PARTIAL_COMPLETE,
    551         notes = "This is a complete subset of tests for toEngineeringString method",
    552         method = "toEngineeringString",
    553         args = {}
    554     )
    555     public void testToEngineeringStringZeroNegExponent() {
    556         String a = "0.0E-16";
    557         BigDecimal aNumber = new BigDecimal(a);
    558         String result = "0.00E-15";
    559         assertEquals("incorrect value", result, aNumber.toEngineeringString());
    560     }
    561 
    562     /**
    563      * Convert a negative BigDecimal with a negative exponent to a plain string
    564      * representation; scale == 0.
    565      */
    566     @TestTargetNew(
    567         level = TestLevel.PARTIAL_COMPLETE,
    568         notes = "This is a complete subset of tests for toPlainString method",
    569         method = "toPlainString",
    570         args = {}
    571     )
    572     public void testToPlainStringNegNegExp() {
    573         String a = "-123809648392384754573567356745735.63567890295784902768787678287E-100";
    574         BigDecimal aNumber = new BigDecimal(a);
    575         String result = "-0.000000000000000000000000000000000000000000000000000000000000000000012380964839238475457356735674573563567890295784902768787678287";
    576         assertTrue("incorrect value", aNumber.toPlainString().equals(result));
    577     }
    578 
    579     /**
    580      * Convert a negative BigDecimal with a positive exponent
    581      * to a plain string representation;
    582      * scale == 0.
    583      */
    584     @TestTargetNew(
    585         level = TestLevel.PARTIAL_COMPLETE,
    586         notes = "This is a complete subset of tests for toPlainString method",
    587         method = "toPlainString",
    588         args = {}
    589     )
    590     public void testToPlainStringNegPosExp() {
    591         String a = "-123809648392384754573567356745735.63567890295784902768787678287E100";
    592         BigDecimal aNumber = new BigDecimal(a);
    593         String result = "-1238096483923847545735673567457356356789029578490276878767828700000000000000000000000000000000000000000000000000000000000000000000000";
    594         assertTrue("incorrect value", aNumber.toPlainString().equals(result));
    595     }
    596 
    597     /**
    598      * Convert a positive BigDecimal with a negative exponent
    599      * to a plain string representation;
    600      * scale == 0.
    601      */
    602     @TestTargetNew(
    603         level = TestLevel.PARTIAL_COMPLETE,
    604         notes = "This is a complete subset of tests for toPlainString method",
    605         method = "toPlainString",
    606         args = {}
    607     )
    608     public void testToPlainStringPosNegExp() {
    609         String a = "123809648392384754573567356745735.63567890295784902768787678287E-100";
    610         BigDecimal aNumber = new BigDecimal(a);
    611         String result = "0.000000000000000000000000000000000000000000000000000000000000000000012380964839238475457356735674573563567890295784902768787678287";
    612         assertTrue("incorrect value", aNumber.toPlainString().equals(result));
    613     }
    614 
    615     /**
    616      * Convert a negative BigDecimal with a negative exponent
    617      * to a plain string representation;
    618      * scale == 0.
    619      */
    620     @TestTargetNew(
    621         level = TestLevel.PARTIAL_COMPLETE,
    622         notes = "This is a complete subset of tests for toPlainString method",
    623         method = "toPlainString",
    624         args = {}
    625     )
    626     public void testToPlainStringPosPosExp() {
    627         String a = "123809648392384754573567356745735.63567890295784902768787678287E+100";
    628         BigDecimal aNumber = new BigDecimal(a);
    629         String result = "1238096483923847545735673567457356356789029578490276878767828700000000000000000000000000000000000000000000000000000000000000000000000";
    630         assertTrue("incorrect value", aNumber.toPlainString().equals(result));
    631     }
    632 
    633     /**
    634      * Convert a BigDecimal to a string representation;
    635      * scale == 0.
    636      */
    637     @TestTargetNew(
    638         level = TestLevel.PARTIAL_COMPLETE,
    639         notes = "This is a complete subset of tests for toString method",
    640         method = "toString",
    641         args = {}
    642     )
    643     public void testToStringZeroScale() {
    644         String a = "-123809648392384754573567356745735635678902957849027687876782870";
    645         BigDecimal aNumber = new BigDecimal(new BigInteger(a));
    646         String result = "-123809648392384754573567356745735635678902957849027687876782870";
    647         assertTrue("incorrect value", aNumber.toString().equals(result));
    648     }
    649 
    650     /**
    651      * Convert a positive BigDecimal to a string representation
    652      */
    653     @TestTargetNew(
    654         level = TestLevel.PARTIAL_COMPLETE,
    655         notes = "This is a complete subset of tests for toString method",
    656         method = "toString",
    657         args = {}
    658     )
    659     public void testToStringPos() {
    660         String a = "123809648392384754573567356745735.63567890295784902768787678287E-500";
    661         BigDecimal aNumber = new BigDecimal(a);
    662         String result = "1.2380964839238475457356735674573563567890295784902768787678287E-468";
    663         assertTrue("incorrect value", aNumber.toString().equals(result));
    664     }
    665 
    666     /**
    667      * Convert a negative BigDecimal to a string representation
    668      */
    669     @TestTargetNew(
    670         level = TestLevel.PARTIAL_COMPLETE,
    671         notes = "This is a complete subset of tests for toString method",
    672         method = "toString",
    673         args = {}
    674     )
    675     public void testToStringNeg() {
    676         String a = "-123.4564563673567380964839238475457356735674573563567890295784902768787678287E-5";
    677         BigDecimal aNumber = new BigDecimal(a);
    678         String result = "-0.001234564563673567380964839238475457356735674573563567890295784902768787678287";
    679         assertTrue("incorrect value", aNumber.toString().equals(result));
    680     }
    681 
    682     /**
    683      * Create a BigDecimal from a positive long value; scale == 0
    684      */
    685     @TestTargetNew(
    686         level = TestLevel.PARTIAL_COMPLETE,
    687         notes = "This is a complete subset of tests for valueOf(long) method",
    688         method = "valueOf",
    689         args = {long.class}
    690     )
    691     public void testValueOfPosZeroScale() {
    692         long a = 98374823947823578L;
    693         BigDecimal aNumber = BigDecimal.valueOf(a);
    694         String result = "98374823947823578";
    695         assertTrue("incorrect value", aNumber.toString().equals(result));
    696     }
    697 
    698     /**
    699      * Create a BigDecimal from a negative long value; scale is 0
    700      */
    701     @TestTargetNew(
    702         level = TestLevel.PARTIAL_COMPLETE,
    703         notes = "This is a complete subset of tests for valueOf(long) method",
    704         method = "valueOf",
    705         args = {long.class}
    706     )
    707     public void testValueOfNegZeroScale() {
    708         long a = -98374823947823578L;
    709         BigDecimal aNumber = BigDecimal.valueOf(a);
    710         String result = "-98374823947823578";
    711         assertTrue("incorrect value", aNumber.toString().equals(result));
    712     }
    713 
    714     /**
    715      * Create a BigDecimal from a negative long value; scale is positive
    716      */
    717     @TestTargetNew(
    718         level = TestLevel.PARTIAL_COMPLETE,
    719         notes = "This is a complete subset of tests for valueOf(long) method",
    720         method = "valueOf",
    721         args = {long.class}
    722     )
    723     public void testValueOfNegScalePos() {
    724         long a = -98374823947823578L;
    725         int scale = 12;
    726         BigDecimal aNumber = BigDecimal.valueOf(a, scale);
    727         String result = "-98374.823947823578";
    728         assertTrue("incorrect value", aNumber.toString().equals(result));
    729     }
    730 
    731     /**
    732      * Create a BigDecimal from a negative long value; scale is negative
    733      */
    734     @TestTargetNew(
    735         level = TestLevel.PARTIAL_COMPLETE,
    736         notes = "This is a complete subset of tests for valueOf(long) method",
    737         method = "valueOf",
    738         args = {long.class}
    739     )
    740     public void testValueOfNegScaleNeg() {
    741         long a = -98374823947823578L;
    742         int scale = -12;
    743         BigDecimal aNumber = BigDecimal.valueOf(a, scale);
    744         String result = "-9.8374823947823578E+28";
    745         assertTrue("incorrect value", aNumber.toString().equals(result));
    746     }
    747 
    748     /**
    749      * Create a BigDecimal from a negative long value; scale is positive
    750      */
    751     @TestTargetNew(
    752         level = TestLevel.PARTIAL_COMPLETE,
    753         notes = "This is a complete subset of tests for valueOf(long) method",
    754         method = "valueOf",
    755         args = {long.class}
    756     )
    757     public void testValueOfPosScalePos() {
    758         long a = 98374823947823578L;
    759         int scale = 12;
    760         BigDecimal aNumber = BigDecimal.valueOf(a, scale);
    761         String result = "98374.823947823578";
    762         assertTrue("incorrect value", aNumber.toString().equals(result));
    763     }
    764 
    765     /**
    766      * Create a BigDecimal from a negative long value; scale is negative
    767      */
    768     @TestTargetNew(
    769         level = TestLevel.PARTIAL_COMPLETE,
    770         notes = "This is a complete subset of tests for valueOf(long) method",
    771         method = "valueOf",
    772         args = {long.class}
    773     )
    774     public void testValueOfPosScaleNeg() {
    775         long a = 98374823947823578L;
    776         int scale = -12;
    777         BigDecimal aNumber = BigDecimal.valueOf(a, scale);
    778         String result = "9.8374823947823578E+28";
    779         assertTrue("incorrect value", aNumber.toString().equals(result));
    780     }
    781 
    782     /**
    783      * Create a BigDecimal from a negative double value
    784      */
    785     @TestTargetNew(
    786         level = TestLevel.PARTIAL_COMPLETE,
    787         notes = "This is a complete subset of tests for valueOf(double) method",
    788         method = "valueOf",
    789         args = {double.class}
    790     )
    791     public void testValueOfDoubleNeg() {
    792         double a = -65678765876567576.98788767;
    793         BigDecimal result = BigDecimal.valueOf(a);
    794         String res = "-65678765876567576";
    795         int resScale = 0;
    796         assertEquals("incorrect value", res, result.toString());
    797         assertEquals("incorrect scale", resScale, result.scale());
    798     }
    799 
    800     /**
    801      * Create a BigDecimal from a positive double value
    802      */
    803     @TestTargetNew(
    804         level = TestLevel.PARTIAL_COMPLETE,
    805         notes = "This is a complete subset of tests for valueOf(double) method",
    806         method = "valueOf",
    807         args = {double.class}
    808     )
    809     public void testValueOfDoublePos1() {
    810         double a = 65678765876567576.98788767;
    811         BigDecimal result = BigDecimal.valueOf(a);
    812         String res = "65678765876567576";
    813         int resScale = 0;
    814         assertEquals("incorrect value", res, result.toString());
    815         assertEquals("incorrect scale", resScale, result.scale());
    816     }
    817 
    818     /**
    819      * Create a BigDecimal from a positive double value
    820      */
    821     @TestTargetNew(
    822         level = TestLevel.PARTIAL_COMPLETE,
    823         notes = "This is a complete subset of tests for valueOf(double) method",
    824         method = "valueOf",
    825         args = {double.class}
    826     )
    827     public void testValueOfDoublePos2() {
    828         double a = 12321237576.98788767;
    829         BigDecimal result = BigDecimal.valueOf(a);
    830         String res = "12321237576.987888";
    831         int resScale = 6;
    832         assertEquals("incorrect value", res, result.toString());
    833         assertEquals("incorrect scale", resScale, result.scale());
    834     }
    835 
    836     /**
    837      * Create a BigDecimal from a positive double value
    838      */
    839     @TestTargetNew(
    840         level = TestLevel.PARTIAL_COMPLETE,
    841         notes = "This is a complete subset of tests for valueOf(double) method",
    842         method = "valueOf",
    843         args = {double.class}
    844     )
    845     public void testValueOfDoublePos3() {
    846         double a = 12321237576.9878838;
    847         BigDecimal result = BigDecimal.valueOf(a);
    848         String res = "12321237576.987885";
    849         int resScale = 6;
    850         assertEquals("incorrect value", res, result.toString());
    851         assertEquals("incorrect scale", resScale, result.scale());
    852     }
    853 
    854     /**
    855      * valueOf(Double.NaN)
    856      */
    857     @TestTargetNew(
    858         level = TestLevel.PARTIAL_COMPLETE,
    859         notes = "This is a complete subset of tests for valueOf(double) method",
    860         method = "valueOf",
    861         args = {double.class}
    862     )
    863     public void testValueOfDoubleNaN() {
    864         double a = Double.NaN;
    865         try {
    866             BigDecimal.valueOf(a);
    867             fail("NumberFormatException has not been thrown for Double.NaN");
    868         } catch (NumberFormatException e) {
    869             return;
    870         }
    871     }
    872 
    873 // ANDROID ADDED
    874 
    875     /**
    876      * @tests java.math.BigDecimal#intValueExact() Integer value of a negative
    877      *        BigDecimal
    878      */
    879     @TestTargetNew(
    880         level = TestLevel.PARTIAL_COMPLETE,
    881         notes = "This is a complete subset of tests for intValueExact method",
    882         method = "intValueExact",
    883         args = {}
    884     )
    885     public void test_IntValueExactNeg() {
    886         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
    887         BigDecimal aNumber = new BigDecimal(a);
    888         try {
    889             aNumber.intValueExact();
    890             fail("java.lang.ArithmeticException isn't thrown after calling intValueExact");
    891         } catch (java.lang.ArithmeticException ae) {
    892             // expected;
    893         }
    894     }
    895 
    896     /**
    897      * @tests java.math.BigDecimal#intValueExact() Integer value of a positive
    898      *        BigDecimal
    899      */
    900     @TestTargetNew(
    901         level = TestLevel.PARTIAL_COMPLETE,
    902         notes = "This is a complete subset of tests for intValueExact method",
    903         method = "intValueExact",
    904         args = {}
    905     )
    906     public void test_IntValueExactPos() {
    907         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
    908         BigDecimal aNumber = new BigDecimal(a);
    909         try {
    910             aNumber.intValueExact();
    911             fail("java.lang.ArithmeticException isn't thrown after calling intValueExact");
    912         } catch (java.lang.ArithmeticException ae) {
    913             // expected;
    914         }
    915     }
    916 
    917     /**
    918      * @tests java.math.BigDecimal#intValueExact() Integer value of a negative
    919      *        BigDecimal
    920      */
    921     @TestTargetNew(
    922         level = TestLevel.PARTIAL_COMPLETE,
    923         notes = "This is a complete subset of tests for intValueExact method",
    924         method = "intValueExact",
    925         args = {}
    926     )
    927     public void test_IntValueExactFloatNeg() {
    928         BigDecimal aNumber = new BigDecimal("-2147483647.999");
    929         try {
    930             aNumber.intValueExact();
    931             fail("java.lang.ArithmeticException isn't thrown after calling intValueExact");
    932         } catch (java.lang.ArithmeticException ae) {
    933             // expected;
    934         }
    935     }
    936 
    937     /**
    938      * @tests java.math.BigDecimal#intValueExact() Integer value of a positive
    939      *        BigDecimal
    940      */
    941     @TestTargetNew(
    942         level = TestLevel.PARTIAL_COMPLETE,
    943         notes = "This is a complete subset of tests for intValueExact method",
    944         method = "intValueExact",
    945         args = {}
    946     )
    947     public void test_IntValueExactFloatPos() {
    948         float a = 2147483646.99999F;
    949         BigDecimal aNumber = new BigDecimal(a);
    950         try {
    951             aNumber.intValueExact();
    952             fail("java.lang.ArithmeticException isn't thrown after calling intValueExact");
    953         } catch (java.lang.ArithmeticException ae) {
    954             // expected;
    955         }
    956     }
    957 
    958     /**
    959      * @tests java.math.BigDecimal#intValueExact() Integer value of a positive
    960      *        BigDecimal
    961      */
    962     @TestTargetNew(
    963         level = TestLevel.PARTIAL_COMPLETE,
    964         notes = "This is a complete subset of tests for intValueExact method",
    965         method = "intValueExact",
    966         args = {}
    967     )
    968     public void test_IntValueExactLongPos() {
    969         long a = 2147483647L;
    970         BigDecimal aNumber = new BigDecimal(a);
    971         int iNumber = aNumber.intValueExact();
    972         assertTrue("incorrect value", iNumber == a);
    973     }
    974 
    975     /**
    976      * @tests java.math.BigDecimal#intValueExact() Integer value of a positive
    977      *        BigDecimal
    978      */
    979     @TestTargetNew(
    980         level = TestLevel.PARTIAL_COMPLETE,
    981         notes = "This is a complete subset of tests for intValueExact method",
    982         method = "intValueExact",
    983         args = {}
    984     )
    985     public void test_IntValueExactLongNeg() {
    986         long a = -2147483648L;
    987         BigDecimal aNumber = new BigDecimal(a);
    988         int iNumber = aNumber.intValueExact();
    989         assertTrue("incorrect value", iNumber == a);
    990     }
    991 
    992     /**
    993      * @tests java.math.BigDecimal#longValueExact() Long value of a negative
    994      *        BigDecimal
    995      */
    996     @TestTargetNew(
    997         level = TestLevel.PARTIAL,
    998         notes = "ArithmeticException checked",
    999         method = "longValueExact",
   1000         args = {}
   1001     )
   1002     public void test_LongValueExactNeg() {
   1003         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
   1004         BigDecimal aNumber = new BigDecimal(a);
   1005         try {
   1006             aNumber.longValueExact();
   1007             fail("java.lang.ArithmeticException isn't thrown after calling longValueExact");
   1008         } catch (java.lang.ArithmeticException ae) {
   1009             // expected;
   1010         }
   1011     }
   1012 
   1013     /**
   1014      * @tests java.math.BigDecimal#longValueExact() Long value of a positive
   1015      *        BigDecimal
   1016      */
   1017     @TestTargetNew(
   1018         level = TestLevel.PARTIAL_COMPLETE,
   1019         notes = "ArithmeticException checked",
   1020         method = "longValueExact",
   1021         args = {}
   1022     )
   1023     public void test_LongValueExactPos() {
   1024         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
   1025         BigDecimal aNumber = new BigDecimal(a);
   1026         try {
   1027             aNumber.longValueExact();
   1028             fail("java.lang.ArithmeticException isn't thrown after calling longValueExact");
   1029         } catch (java.lang.ArithmeticException ae) {
   1030             // expected;
   1031         }
   1032     }
   1033 
   1034     /**
   1035      * @tests java.math.BigDecimal#longValueExact() Long value of a negative
   1036      *        BigDecimal
   1037      */
   1038     @TestTargetNew(
   1039         level = TestLevel.PARTIAL_COMPLETE,
   1040         notes = "ArithmeticException checked",
   1041         method = "longValueExact",
   1042         args = {}
   1043     )
   1044     public void test_LongValueExactFloatNeg() {
   1045         BigDecimal aNumber = new BigDecimal("-9223372036854775807.99999");
   1046         try {
   1047             aNumber.longValueExact();
   1048             fail("java.lang.ArithmeticException isn't thrown after calling longValueExact");
   1049         } catch (java.lang.ArithmeticException ae) {
   1050             // expected;
   1051         }
   1052     }
   1053 
   1054     /**
   1055      * @tests java.math.BigDecimal#longValueExact() Long value of a positive
   1056      *        BigDecimal
   1057      */
   1058     @TestTargetNew(
   1059         level = TestLevel.PARTIAL_COMPLETE,
   1060         notes = "ArithmeticException checked",
   1061         method = "longValueExact",
   1062         args = {}
   1063     )
   1064     public void test_LongValueExactFloatPos() {
   1065         float a = 9223372036854775806.99999F;
   1066         BigDecimal aNumber = new BigDecimal(a);
   1067         try {
   1068             aNumber.longValueExact();
   1069             fail("java.lang.ArithmeticException isn't thrown after calling longValueExact");
   1070         } catch (java.lang.ArithmeticException ae) {
   1071             // expected;
   1072         }
   1073     }
   1074 
   1075     /**
   1076      * @test java.math.BigDecimal#byteValueExact() Convert pisitive BigDesimal
   1077      *       to byte type
   1078      */
   1079     @TestTargetNew(
   1080         level = TestLevel.PARTIAL_COMPLETE,
   1081         notes = "This is a complete subset of tests for byteValueExact method",
   1082         method = "byteValueExact",
   1083         args = {}
   1084     )
   1085     public void test_ByteValueExactPos() {
   1086         int i = 127;
   1087         BigDecimal bdNumber = new BigDecimal(i);
   1088         byte bNumber = bdNumber.byteValueExact();
   1089         assertTrue("incorrect byteValueExact", i == bNumber);
   1090     }
   1091 
   1092     /**
   1093      * @test java.math.BigDecimal#byteValueExact() Convert negative BigDesimal
   1094      *       to byte type
   1095      */
   1096     @TestTargetNew(
   1097         level = TestLevel.PARTIAL_COMPLETE,
   1098         notes = "This is a complete subset of tests for byteValueExact method",
   1099         method = "byteValueExact",
   1100         args = {}
   1101     )
   1102     public void test_ByteValueExactNeg() {
   1103         String sNumber = "-127.56789";
   1104         int iNumber = -128;
   1105         int iPresition = 3;
   1106         MathContext mc = new MathContext(iPresition, RoundingMode.UP);
   1107         BigDecimal bdNumber = new BigDecimal(sNumber, mc);
   1108         byte bNumber = bdNumber.byteValueExact();
   1109         assertTrue("incorrect byteValueExact", iNumber == bNumber);
   1110     }
   1111 
   1112     /**
   1113      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1114      *       from char array to byte type
   1115      */
   1116 
   1117     @TestTargetNew(
   1118         level = TestLevel.PARTIAL_COMPLETE,
   1119         notes = "This is a complete subset of tests for byteValueExact method",
   1120         method = "byteValueExact",
   1121         args = {}
   1122     )
   1123     public void test_ByteValueExactCharZero() {
   1124         char[] cNumber = {
   1125                 '-', '0', '.', '0'
   1126         };
   1127         int iNumber = 0;
   1128         int iPresition = 5;
   1129         MathContext mc = new MathContext(iPresition, RoundingMode.HALF_DOWN);
   1130         BigDecimal bdNumber = new BigDecimal(cNumber, mc);
   1131         byte bNumber = bdNumber.byteValueExact();
   1132         assertTrue("incorrect byteValueExact", iNumber == bNumber);
   1133     }
   1134 
   1135     /**
   1136      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1137      *       from String to byte type
   1138      */
   1139 
   1140     @TestTargetNew(
   1141         level = TestLevel.PARTIAL_COMPLETE,
   1142         notes = "This is a complete subset of tests for byteValueExact method",
   1143         method = "byteValueExact",
   1144         args = {}
   1145     )
   1146     public void test_ByteValueExactStringZero() {
   1147         String sNumber = "00000000000000";
   1148         int iNumber = 0;
   1149         int iPresition = 0;
   1150         MathContext mc = new MathContext(iPresition, RoundingMode.HALF_UP);
   1151         BigDecimal bdNumber = new BigDecimal(sNumber, mc);
   1152         byte bNumber = bdNumber.byteValueExact();
   1153         assertTrue("incorrect byteValueExact", iNumber == bNumber);
   1154     }
   1155 
   1156     /**
   1157      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1158      *       from double to byte type
   1159      */
   1160 
   1161     @TestTargetNew(
   1162         level = TestLevel.PARTIAL_COMPLETE,
   1163         notes = "This is a complete subset of tests for byteValueExact method",
   1164         method = "byteValueExact",
   1165         args = {}
   1166     )
   1167     public void test_ByteValueExactDoubleMax() {
   1168         double dNumber = Double.MAX_VALUE;
   1169         BigDecimal bdNumber = new BigDecimal(dNumber);
   1170         try {
   1171             bdNumber.byteValueExact();
   1172             fail("java.lang.ArithmeticException isn't thrown after calling byteValueExact");
   1173         } catch (java.lang.ArithmeticException ae) {
   1174             // expected
   1175         }
   1176     }
   1177 
   1178     /**
   1179      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1180      *       from double to byte type
   1181      */
   1182 
   1183     @TestTargetNew(
   1184         level = TestLevel.PARTIAL_COMPLETE,
   1185         notes = "This is a complete subset of tests for byteValueExact method",
   1186         method = "byteValueExact",
   1187         args = {}
   1188     )
   1189     public void test_ByteValueExactDoubleMin() {
   1190         double dNumber = Double.MIN_VALUE;
   1191         BigDecimal bdNumber = new BigDecimal(dNumber);
   1192         try {
   1193             bdNumber.byteValueExact();
   1194             fail("java.lang.ArithmeticException isn't thrown after calling byteValueExact");
   1195         } catch (java.lang.ArithmeticException ae) {
   1196             // expected
   1197         }
   1198     }
   1199 
   1200     /**
   1201      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1202      *       from float to byte type
   1203      */
   1204 
   1205     @TestTargetNew(
   1206         level = TestLevel.PARTIAL_COMPLETE,
   1207         notes = "This is a complete subset of tests for byteValueExact method",
   1208         method = "byteValueExact",
   1209         args = {}
   1210     )
   1211     public void test_ByteValueExactFloatPos() {
   1212         float fNumber = 123.5445F;
   1213         BigDecimal bdNumber = new BigDecimal(fNumber);
   1214         try {
   1215             bdNumber.byteValueExact();
   1216             fail("java.lang.ArithmeticException isn't thrown after calling byteValueExact");
   1217         } catch (java.lang.ArithmeticException ae) {
   1218             // expected
   1219         }
   1220     }
   1221 
   1222     /**
   1223      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1224      *       from float to byte type
   1225      */
   1226 
   1227     @TestTargetNew(
   1228         level = TestLevel.PARTIAL_COMPLETE,
   1229         notes = "This is a complete subset of tests for byteValueExact method",
   1230         method = "byteValueExact",
   1231         args = {}
   1232     )
   1233     public void test_ByteValueExactFloatNeg() {
   1234         float fNumber = -12.987654321F;
   1235         BigDecimal bdNumber = new BigDecimal(fNumber);
   1236         try {
   1237             bdNumber.byteValueExact();
   1238             fail("java.lang.ArithmeticException isn't thrown after calling byteValueExact");
   1239         } catch (java.lang.ArithmeticException ae) {
   1240             // expected
   1241         }
   1242     }
   1243 
   1244     /**
   1245      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1246      *       from double to byte type
   1247      */
   1248 
   1249     @TestTargetNew(
   1250         level = TestLevel.PARTIAL_COMPLETE,
   1251         notes = "This is a complete subset of tests for byteValueExact method",
   1252         method = "byteValueExact",
   1253         args = {}
   1254     )
   1255     public void test_ByteValueExactDouble() {
   1256         double dNumber = 123.0000D;
   1257         BigDecimal bdNumber = new BigDecimal(dNumber);
   1258         byte bNumber = bdNumber.byteValueExact();
   1259         assertTrue("incorrect byteValueExact", dNumber == bNumber);
   1260     }
   1261 
   1262     /**
   1263      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1264      *       from long to byte type
   1265      */
   1266 
   1267     @TestTargetNew(
   1268         level = TestLevel.PARTIAL_COMPLETE,
   1269         notes = "This is a complete subset of tests for byteValueExact method",
   1270         method = "byteValueExact",
   1271         args = {}
   1272     )
   1273     public void test_ByteValueExactLongMin() {
   1274         long lNumber = Long.MIN_VALUE;
   1275         BigDecimal bdNumber = new BigDecimal(lNumber);
   1276         try {
   1277             bdNumber.byteValueExact();
   1278             fail("java.lang.ArithmeticException isn't thrown after calling byteValueExact");
   1279         } catch (java.lang.ArithmeticException ae) {
   1280             // expected
   1281         }
   1282     }
   1283 
   1284     /**
   1285      * @test java.math.BigDecimal#byteValueExact() Convert BigDesimal created
   1286      *       from int to byte type
   1287      */
   1288 
   1289     @TestTargetNew(
   1290         level = TestLevel.PARTIAL_COMPLETE,
   1291         notes = "This is a complete subset of tests for byteValueExact method",
   1292         method = "byteValueExact",
   1293         args = {}
   1294     )
   1295     public void test_ByteValueExactIntMax() {
   1296         int iNumber = Integer.MAX_VALUE;
   1297         BigDecimal bdNumber = new BigDecimal(iNumber);
   1298         try {
   1299             bdNumber.byteValueExact();
   1300             fail("java.lang.ArithmeticException isn't thrown after calling byteValueExact");
   1301         } catch (java.lang.ArithmeticException ae) {
   1302             // expected
   1303         }
   1304     }
   1305 
   1306     /**
   1307      * @test java.math.BigDecimal#byteValue() Convert pisitive BigDesimal to
   1308      *       byte type
   1309      */
   1310     @TestTargetNew(
   1311         level = TestLevel.PARTIAL_COMPLETE,
   1312         method = "byteValue",
   1313         args = {}
   1314     )
   1315     public void test_ByteValuePos() {
   1316         int i = 127;
   1317         BigDecimal bdNumber = new BigDecimal(i);
   1318         byte bNumber = bdNumber.byteValue();
   1319         assertTrue("incorrect byteValue", i == bNumber);
   1320     }
   1321 
   1322     /**
   1323      * @test java.math.BigDecimal#byteValue() Convert negative BigDesimal to
   1324      *       byte type
   1325      */
   1326     @TestTargetNew(
   1327         level = TestLevel.PARTIAL_COMPLETE,
   1328         method = "byteValue",
   1329         args = {}
   1330     )
   1331     public void test_ByteValueNeg() {
   1332         String sNumber = "-127.56789";
   1333         int iNumber = -128;
   1334         int iPresition = 3;
   1335         MathContext mc = new MathContext(iPresition, RoundingMode.UP);
   1336         BigDecimal bdNumber = new BigDecimal(sNumber, mc);
   1337         byte bNumber = bdNumber.byteValue();
   1338         assertTrue("incorrect byteValueExact", iNumber == bNumber);
   1339     }
   1340 
   1341     /**
   1342      * @test java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1343      *       char array to byte type
   1344      */
   1345     @TestTargetNew(
   1346         level = TestLevel.PARTIAL_COMPLETE,
   1347         method = "byteValue",
   1348         args = {}
   1349     )
   1350     public void test_ByteValueCharZero() {
   1351         char[] cNumber = {
   1352                 '-', '0', '.', '0'
   1353         };
   1354         int iNumber = 0;
   1355         int iPresition = 0;
   1356         MathContext mc = new MathContext(iPresition, RoundingMode.HALF_UP);
   1357         BigDecimal bdNumber = new BigDecimal(cNumber, mc);
   1358         byte bNumber = bdNumber.byteValue();
   1359         assertTrue("incorrect byteValue", iNumber == bNumber);
   1360     }
   1361 
   1362     /**
   1363      * @test java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1364      *       String to byte type
   1365      */
   1366     @TestTargetNew(
   1367         level = TestLevel.PARTIAL_COMPLETE,
   1368         method = "byteValue",
   1369         args = {}
   1370     )
   1371     public void test_ByteValueStringZero() {
   1372         String sNumber = "00000";
   1373         int iNumber = 0;
   1374         int iPresition = 0;
   1375         MathContext mc = new MathContext(iPresition, RoundingMode.HALF_UP);
   1376         BigDecimal bdNumber = new BigDecimal(sNumber, mc);
   1377         byte bNumber = bdNumber.byteValue();
   1378         assertTrue("incorrect byteValue", iNumber == bNumber);
   1379     }
   1380 
   1381     /**
   1382      * @test java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1383      *       double to byte type
   1384      */
   1385     @TestTargetNew(
   1386         level = TestLevel.PARTIAL_COMPLETE,
   1387         method = "byteValue",
   1388         args = {}
   1389     )
   1390     public void test_ByteValueDoubleMax() {
   1391         double dNumber = Double.MAX_VALUE;
   1392         BigDecimal bdNumber = new BigDecimal(dNumber);
   1393         int result = 0;
   1394         byte bNumber = bdNumber.byteValue();
   1395         assertTrue("incorrect byteValue", bNumber == result);
   1396     }
   1397 
   1398     /**
   1399      * @test java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1400      *       double to byte type
   1401      */
   1402     @TestTargetNew(
   1403         level = TestLevel.PARTIAL_COMPLETE,
   1404         method = "byteValue",
   1405         args = {}
   1406     )
   1407     public void test_ByteValueDoubleMin() {
   1408         double dNumber = Double.MIN_VALUE;
   1409         BigDecimal bdNumber = new BigDecimal(dNumber);
   1410         int result = 0;
   1411         byte bNumber = bdNumber.byteValue();
   1412         assertTrue("incorrect byteValue", bNumber == result);
   1413     }
   1414 
   1415     /**
   1416      * @test_ java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1417      *        float to byte type
   1418      */
   1419     @TestTargetNew(
   1420         level = TestLevel.PARTIAL_COMPLETE,
   1421         method = "byteValue",
   1422         args = {}
   1423     )
   1424     public void test_ByteValueFloatNeg() {
   1425         float fNumber = -12.987654321F;
   1426         byte bValue = -12;
   1427         BigDecimal bdNumber = new BigDecimal(fNumber);
   1428         byte bNumber = bdNumber.byteValue();
   1429         assertTrue("incorrect byteValue", bNumber == bValue);
   1430     }
   1431 
   1432     /**
   1433      * @test java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1434      *       double to byte type
   1435      */
   1436     @TestTargetNew(
   1437         level = TestLevel.PARTIAL_COMPLETE,
   1438         method = "byteValue",
   1439         args = {}
   1440     )
   1441     public void test_ByteValueDouble() {
   1442         double dNumber = 123.0000D;
   1443         BigDecimal bdNumber = new BigDecimal(dNumber);
   1444         byte bNumber = bdNumber.byteValue();
   1445         assertTrue("incorrect byteValue", dNumber == bNumber);
   1446     }
   1447 
   1448     /**
   1449      * @test java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1450      *       long to byte type
   1451      */
   1452     @TestTargetNew(
   1453         level = TestLevel.PARTIAL_COMPLETE,
   1454         method = "byteValue",
   1455         args = {}
   1456     )
   1457     public void test_ByteValueLongMin() {
   1458         long lNumber = Long.MIN_VALUE;
   1459         int result = 0;
   1460         BigDecimal bdNumber = new BigDecimal(lNumber);
   1461         byte bNumber = bdNumber.byteValue();
   1462         assertTrue("incorrect byteValue", bNumber == result);
   1463     }
   1464 
   1465     /**
   1466      * @test java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1467      *       int to byte type
   1468      */
   1469     @TestTargetNew(
   1470         level = TestLevel.PARTIAL_COMPLETE,
   1471         method = "byteValue",
   1472         args = {}
   1473     )
   1474     public void test_ByteValueIntMin() {
   1475         int iNumber = Integer.MIN_VALUE;
   1476         int result = 0;
   1477         BigDecimal bdNumber = new BigDecimal(iNumber);
   1478         byte bNumber = bdNumber.byteValue();
   1479         assertTrue("incorrect byteValue", bNumber == result);
   1480     }
   1481 
   1482     /**
   1483      * @test java.math.BigDecimal#byteValue() Convert BigDesimal created from
   1484      *       int to byte type
   1485      */
   1486     @TestTargetNew(
   1487         level = TestLevel.PARTIAL_COMPLETE,
   1488         method = "byteValue",
   1489         args = {}
   1490     )
   1491     public void test_ByteValueIntMax() {
   1492         int iNumber = Integer.MAX_VALUE;
   1493         int result = -1;
   1494         BigDecimal bdNumber = new BigDecimal(iNumber);
   1495         byte bNumber = bdNumber.byteValue();
   1496         assertTrue("incorrect byteValue", bNumber == result);
   1497     }
   1498 
   1499     /**
   1500      * @test java.math.BigDecimal#shortValue() Short value of a negative
   1501      *       BigDecimal
   1502      */
   1503     @TestTargetNew(
   1504         level = TestLevel.PARTIAL_COMPLETE,
   1505         method = "shortValue",
   1506         args = {}
   1507     )
   1508     public void test_ShortValueNeg() {
   1509         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
   1510         BigDecimal aNumber = new BigDecimal(a);
   1511         int result = 23449;
   1512         assertTrue("incorrect value", aNumber.shortValue() == result);
   1513     }
   1514 
   1515     /**
   1516      * @test java.math.BigDecimal#shortValue() Short value of a positive
   1517      *       BigDecimal
   1518      */
   1519     @TestTargetNew(
   1520         level = TestLevel.PARTIAL_COMPLETE,
   1521         method = "shortValue",
   1522         args = {}
   1523     )
   1524     public void test_ShortValuePos() {
   1525         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
   1526         BigDecimal aNumber = new BigDecimal(a);
   1527         int result = -23449;
   1528         assertTrue("incorrect value", aNumber.shortValue() == result);
   1529     }
   1530 
   1531     /**
   1532      * @test java.math.BigDecimal#shortValueExact() Short value of a negative
   1533      *       BigDecimal
   1534      */
   1535     @TestTargetNew(
   1536         level = TestLevel.PARTIAL_COMPLETE,
   1537         notes = "This is a complete subset of tests for shortValueExact method",
   1538         method = "shortValueExact",
   1539         args = {}
   1540     )
   1541     public void test_ShortValueExactNeg() {
   1542         String a = "-123809648392384754573567356745735.63567890295784902768787678287E+21";
   1543         BigDecimal aNumber = new BigDecimal(a);
   1544         try {
   1545             aNumber.shortValueExact();
   1546             fail("java.lang.ArithmeticException isn't thrown after calling intValueExact");
   1547         } catch (java.lang.ArithmeticException ae) {
   1548             // expected;
   1549         }
   1550     }
   1551 
   1552     /**
   1553      * @test java.math.BigDecimal#shortValueExact() Short value of a positive
   1554      *       BigDecimal
   1555      */
   1556     @TestTargetNew(
   1557         level = TestLevel.PARTIAL_COMPLETE,
   1558         notes = "This is a complete subset of tests for shortValueExact method",
   1559         method = "shortValueExact",
   1560         args = {}
   1561     )
   1562     public void test_ShortValueExactPos() {
   1563         String a = "123809648392384754573567356745735.63567890295784902768787678287E+21";
   1564         BigDecimal aNumber = new BigDecimal(a);
   1565         try {
   1566             aNumber.shortValueExact();
   1567             fail("java.lang.ArithmeticException isn't thrown after calling intValueExact");
   1568         } catch (java.lang.ArithmeticException ae) {
   1569             // expected;
   1570         }
   1571     }
   1572 
   1573     /**
   1574      * @test java.math.BigDecimal#shortValueExact() Short value of a negative
   1575      *       BigDecimal
   1576      */
   1577     @TestTargetNew(
   1578         level = TestLevel.PARTIAL_COMPLETE,
   1579         notes = "This is a complete subset of tests for shortValueExact method",
   1580         method = "shortValueExact",
   1581         args = {}
   1582     )
   1583     public void test_ShortValueExactFloatNeg() {
   1584         BigDecimal aNumber = new BigDecimal("-32766.99999");
   1585         try {
   1586             aNumber.shortValueExact();
   1587             fail("java.lang.ArithmeticException isn't thrown after calling intValueExact");
   1588         } catch (java.lang.ArithmeticException ae) {
   1589             // expected;
   1590         }
   1591     }
   1592 
   1593     /**
   1594      * @test java.math.BigDecimal#shortValueExact() Short value of a positive
   1595      *       BigDecimal
   1596      */
   1597     @TestTargetNew(
   1598         level = TestLevel.PARTIAL_COMPLETE,
   1599         notes = "This is a complete subset of tests for shortValueExact method",
   1600         method = "shortValueExact",
   1601         args = {}
   1602     )
   1603     public void test_ShortValueExactFloatPos() {
   1604         float a = 32767.99999F;
   1605         BigDecimal aNumber = new BigDecimal(a);
   1606         try {
   1607             aNumber.shortValueExact();
   1608             fail("java.lang.ArithmeticException isn't thrown after calling intValueExact");
   1609         } catch (java.lang.ArithmeticException ae) {
   1610             // expected;
   1611         }
   1612     }
   1613 
   1614     /**
   1615      * @test java.math.BigDecimal#shortValueExact() Short value of a positive
   1616      *       BigDecimal
   1617      */
   1618     @TestTargetNew(
   1619         level = TestLevel.PARTIAL_COMPLETE,
   1620         notes = "This is a complete subset of tests for shortValueExact method",
   1621         method = "shortValueExact",
   1622         args = {}
   1623     )
   1624     public void test_ShortValueExactLongPos() {
   1625         long a = 12345L;
   1626         BigDecimal aNumber = new BigDecimal(a);
   1627         short shNumber = aNumber.shortValueExact();
   1628         assertTrue("incorrect value", shNumber == a);
   1629     }
   1630 
   1631     /**
   1632      * @test java.math.BigDecimal#shortValueExact() Short value of a positive
   1633      *       BigDecimal
   1634      */
   1635     @TestTargetNew(
   1636         level = TestLevel.PARTIAL_COMPLETE,
   1637         notes = "This is a complete subset of tests for shortValueExact method",
   1638         method = "shortValueExact",
   1639         args = {}
   1640     )
   1641     public void test_ShortValueExactLongNeg() {
   1642         long a = -12345L;
   1643         BigDecimal aNumber = new BigDecimal(a);
   1644         int iNumber = aNumber.shortValueExact();
   1645         assertTrue("incorrect value", iNumber == a);
   1646     }
   1647 
   1648     /**
   1649      * @tests java.math.BigDecimal#stripTrailingZeros() stripTrailingZeros() for
   1650      *        BigDecimal with zero
   1651      */
   1652     @TestTargetNew(
   1653         level = TestLevel.PARTIAL_COMPLETE,
   1654         notes = "This is a complete subset of tests for stripTrailingZeros method",
   1655         method = "stripTrailingZeros",
   1656         args = {}
   1657     )
   1658     public void test_stripTrailingZerosZeros() {
   1659 
   1660         BigDecimal bdNumber = new BigDecimal("0000000");
   1661         BigDecimal result = bdNumber.stripTrailingZeros();
   1662         assertEquals("incorrect value", result.unscaledValue(), bdNumber.unscaledValue());
   1663         assertTrue("incorrect value", result.scale() == 0);
   1664 
   1665         bdNumber = new BigDecimal(0);
   1666         result = bdNumber.stripTrailingZeros();
   1667         assertEquals("incorrect value", result.unscaledValue(), bdNumber.unscaledValue());
   1668         assertTrue("incorrect value", result.scale() == 0);
   1669 
   1670         bdNumber = new BigDecimal(0.000000);
   1671         result = bdNumber.stripTrailingZeros();
   1672         assertEquals("incorrect value", result.unscaledValue(), bdNumber.unscaledValue());
   1673         assertTrue("incorrect value", result.scale() == 0);
   1674     }
   1675 
   1676     /**
   1677      * @tests java.math.BigDecimal#stripTrailingZeros() stripTrailingZeros() for
   1678      *        positive BigDecimal
   1679      */
   1680     @TestTargetNew(
   1681         level = TestLevel.PARTIAL_COMPLETE,
   1682         notes = "This is a complete subset of tests for stripTrailingZeros method",
   1683         method = "stripTrailingZeros",
   1684         args = {}
   1685     )
   1686     public void test_stripTrailingZeros() {
   1687 
   1688         String s = "00000000100000000100000000.000000000100000000";
   1689         int iScale = 10;
   1690         BigDecimal bdValue = new BigDecimal("1000000001000000000000000001");
   1691         BigDecimal bdNumber = new BigDecimal(s);
   1692         BigDecimal bdResult = bdNumber.stripTrailingZeros();
   1693         assertEquals("incorrect value", bdResult.unscaledValue(), bdValue.unscaledValue());
   1694         assertTrue("incorrect value", bdResult.scale() == iScale);
   1695 
   1696         s = "1000.0";
   1697         iScale = -3;
   1698         BigDecimal bd = new BigDecimal("1");
   1699         bdNumber = new BigDecimal(s);
   1700         bdResult = bdNumber.stripTrailingZeros();
   1701         assertEquals("incorrect value", bdResult.unscaledValue(), bd.unscaledValue());
   1702         assertTrue("incorrect value", bdResult.scale() == iScale);
   1703     }
   1704 }
   1705