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 */
20
21package org.apache.harmony.tests.java.math;
22
23import java.math.BigDecimal;
24import java.math.BigInteger;
25import java.math.MathContext;
26import java.math.RoundingMode;
27
28import junit.framework.TestCase;
29
30/**
31 * Class:  java.math.BigDecimal
32 * Methods: constructors and fields
33 */
34public class BigDecimalConstructorsTest extends TestCase {
35    /**
36     * check ONE
37     */
38    public void testFieldONE() {
39        String oneS = "1";
40        double oneD = 1.0;
41        assertEquals("incorrect string value", oneS, BigDecimal.ONE.toString());
42        assertEquals("incorrect double value", oneD, BigDecimal.ONE.doubleValue(), 0);
43    }
44
45    /**
46     * check TEN
47     */
48    public void testFieldTEN() {
49        String oneS = "10";
50        double oneD = 10.0;
51        assertEquals("incorrect string value", oneS, BigDecimal.TEN.toString());
52        assertEquals("incorrect double value", oneD, BigDecimal.TEN.doubleValue(), 0);
53    }
54
55    /**
56     * check ZERO
57     */
58    public void testFieldZERO() {
59        String oneS = "0";
60        double oneD = 0.0;
61        assertEquals("incorrect string value", oneS, BigDecimal.ZERO.toString());
62        assertEquals("incorrect double value", oneD, BigDecimal.ZERO.doubleValue(), 0);
63    }
64
65    /**
66     * new BigDecimal(BigInteger value)
67     */
68    public void testConstrBI() {
69        String a = "1231212478987482988429808779810457634781384756794987";
70        BigInteger bA = new BigInteger(a);
71        BigDecimal aNumber = new BigDecimal(bA);
72        assertEquals("incorrect value", bA, aNumber.unscaledValue());
73        assertEquals("incorrect scale", 0, aNumber.scale());
74
75        try {
76            new BigDecimal((BigInteger) null);
77        	fail("No NullPointerException");
78        } catch (NullPointerException e) {
79        	//expected
80        }
81    }
82
83    /**
84     * new BigDecimal(BigInteger value, int scale)
85     */
86    public void testConstrBIScale() {
87        String a = "1231212478987482988429808779810457634781384756794987";
88        BigInteger bA = new BigInteger(a);
89        int aScale = 10;
90        BigDecimal aNumber = new BigDecimal(bA, aScale);
91        assertEquals("incorrect value", bA, aNumber.unscaledValue());
92        assertEquals("incorrect scale", aScale, aNumber.scale());
93    }
94
95    /**
96     * new BigDecimal(BigInteger value, MathContext)
97     */
98    public void testConstrBigIntegerMathContext() {
99        String a = "1231212478987482988429808779810457634781384756794987";
100        BigInteger bA = new BigInteger(a);
101        int precision = 46;
102        RoundingMode rm = RoundingMode.CEILING;
103        MathContext mc = new MathContext(precision, rm);
104        String res = "1231212478987482988429808779810457634781384757";
105        int resScale = -6;
106        BigDecimal result = new BigDecimal(bA, mc);
107        assertEquals("incorrect value", res, result.unscaledValue().toString());
108        assertEquals("incorrect scale", resScale, result.scale());
109    }
110
111    /**
112     * new BigDecimal(BigInteger value, int scale, MathContext)
113     */
114    public void testConstrBigIntegerScaleMathContext() {
115        String a = "1231212478987482988429808779810457634781384756794987";
116        BigInteger bA = new BigInteger(a);
117        int aScale = 10;
118        int precision = 46;
119        RoundingMode rm = RoundingMode.CEILING;
120        MathContext mc = new MathContext(precision, rm);
121        String res = "1231212478987482988429808779810457634781384757";
122        int resScale = 4;
123        BigDecimal result = new BigDecimal(bA, aScale, mc);
124        assertEquals("incorrect value", res, result.unscaledValue().toString());
125        assertEquals("incorrect scale", resScale, result.scale());
126    }
127
128    /**
129     * new BigDecimal(char[] value);
130     */
131    public void testConstrChar() {
132        char value[] = {'-', '1', '2', '3', '8', '0', '.', '4', '7', '3', '8', 'E', '-', '4', '2', '3'};
133        BigDecimal result = new BigDecimal(value);
134        String res = "-1.23804738E-419";
135        int resScale = 427;
136        assertEquals("incorrect value", res, result.toString());
137        assertEquals("incorrect scale", resScale, result.scale());
138
139        try {
140            // Regression for HARMONY-783
141            new BigDecimal(new char[] {});
142            fail("NumberFormatException has not been thrown");
143        } catch (NumberFormatException e) {
144        }
145     }
146
147    /**
148     * new BigDecimal(char[] value, int offset, int len);
149     */
150    public void testConstrCharIntInt() {
151        char value[] = {'-', '1', '2', '3', '8', '0', '.', '4', '7', '3', '8', 'E', '-', '4', '2', '3'};
152        int offset = 3;
153        int len = 12;
154        BigDecimal result = new BigDecimal(value, offset, len);
155        String res = "3.804738E-40";
156        int resScale = 46;
157        assertEquals("incorrect value", res, result.toString());
158        assertEquals("incorrect scale", resScale, result.scale());
159
160        try {
161            // Regression for HARMONY-783
162            new BigDecimal(new char[] {}, 0, 0);
163            fail("NumberFormatException has not been thrown");
164        } catch (NumberFormatException e) {
165        }
166     }
167
168    /**
169     * new BigDecimal(char[] value, int offset, int len, MathContext mc);
170     */
171    public void testConstrCharIntIntMathContext() {
172        char value[] = {'-', '1', '2', '3', '8', '0', '.', '4', '7', '3', '8', 'E', '-', '4', '2', '3'};
173        int offset = 3;
174        int len = 12;
175        int precision = 4;
176        RoundingMode rm = RoundingMode.CEILING;
177        MathContext mc = new MathContext(precision, rm);
178        BigDecimal result = new BigDecimal(value, offset, len, mc);
179        String res = "3.805E-40";
180        int resScale = 43;
181        assertEquals("incorrect value", res, result.toString());
182        assertEquals("incorrect scale", resScale, result.scale());
183
184        try {
185            // Regression for HARMONY-783
186            new BigDecimal(new char[] {}, 0, 0, MathContext.DECIMAL32);
187            fail("NumberFormatException has not been thrown");
188        } catch (NumberFormatException e) {
189        }
190     }
191
192    /**
193     * new BigDecimal(char[] value, int offset, int len, MathContext mc);
194     */
195    public void testConstrCharIntIntMathContextException1() {
196        char value[] = {'-', '1', '2', '3', '8', '0', '.', '4', '7', '3', '8', 'E', '-', '4', '2', '3'};
197        int offset = 3;
198        int len = 120;
199        int precision = 4;
200        RoundingMode rm = RoundingMode.CEILING;
201        MathContext mc = new MathContext(precision, rm);
202        try {
203            new BigDecimal(value, offset, len, mc);
204            fail("NumberFormatException has not been thrown");
205        } catch (NumberFormatException e) {
206        }
207     }
208
209    /**
210     * new BigDecimal(char[] value, int offset, int len, MathContext mc);
211     */
212    public void testConstrCharIntIntMathContextException2() {
213        char value[] = {'-', '1', '2', '3', '8', '0', ',', '4', '7', '3', '8', 'E', '-', '4', '2', '3'};
214        int offset = 3;
215        int len = 120;
216        int precision = 4;
217        RoundingMode rm = RoundingMode.CEILING;
218        MathContext mc = new MathContext(precision, rm);
219        try {
220            new BigDecimal(value, offset, len, mc);
221            fail("NumberFormatException has not been thrown");
222        } catch (NumberFormatException e) {
223        }
224     }
225
226    /**
227     * new BigDecimal(char[] value, MathContext mc);
228     */
229    public void testConstrCharMathContext() {
230        try {
231            // Regression for HARMONY-783
232            new BigDecimal(new char[] {}, MathContext.DECIMAL32);
233            fail("NumberFormatException has not been thrown");
234        } catch (NumberFormatException e) {
235        }
236    }
237
238    /**
239     * new BigDecimal(double value) when value is NaN
240     */
241    public void testConstrDoubleNaN() {
242        double a = Double.NaN;
243        try {
244            new BigDecimal(a);
245            fail("NumberFormatException has not been caught");
246        } catch (NumberFormatException e) {
247        }
248    }
249
250    /**
251     * new BigDecimal(double value) when value is positive infinity
252     */
253    public void testConstrDoublePosInfinity() {
254        double a = Double.POSITIVE_INFINITY;
255        try {
256            new BigDecimal(a);
257            fail("NumberFormatException has not been caught");
258        } catch (NumberFormatException e) {
259        }
260    }
261
262    /**
263     * new BigDecimal(double value) when value is positive infinity
264     */
265    public void testConstrDoubleNegInfinity() {
266        double a = Double.NEGATIVE_INFINITY;
267        try {
268            new BigDecimal(a);
269            fail("NumberFormatException has not been caught");
270        } catch (NumberFormatException e) {
271        }
272    }
273
274    /**
275     * new BigDecimal(double value)
276     */
277    public void testConstrDouble() {
278        double a = 732546982374982347892379283571094797.287346782359284756;
279        int aScale = 0;
280        BigInteger bA = new BigInteger("732546982374982285073458350476230656");
281        BigDecimal aNumber = new BigDecimal(a);
282        assertEquals("incorrect value", bA, aNumber.unscaledValue());
283        assertEquals("incorrect scale", aScale, aNumber.scale());
284    }
285
286    /**
287     * new BigDecimal(double, MathContext)
288     */
289    public void testConstrDoubleMathContext() {
290        double a = 732546982374982347892379283571094797.287346782359284756;
291        int precision = 21;
292        RoundingMode rm = RoundingMode.CEILING;
293        MathContext mc = new MathContext(precision, rm);
294        String res = "732546982374982285074";
295        int resScale = -15;
296        BigDecimal result = new BigDecimal(a, mc);
297        assertEquals("incorrect value", res, result.unscaledValue().toString());
298        assertEquals("incorrect scale", resScale, result.scale());
299    }
300
301    /**
302     * new BigDecimal(0.1)
303     */
304    public void testConstrDouble01() {
305        double a = 1.E-1;
306        int aScale = 55;
307        BigInteger bA = new BigInteger("1000000000000000055511151231257827021181583404541015625");
308        BigDecimal aNumber = new BigDecimal(a);
309        assertEquals("incorrect value", bA, aNumber.unscaledValue());
310        assertEquals("incorrect scale", aScale, aNumber.scale());
311    }
312
313    /**
314     * new BigDecimal(0.555)
315     */
316    public void testConstrDouble02() {
317        double a = 0.555;
318        int aScale = 53;
319        BigInteger bA = new BigInteger("55500000000000004884981308350688777863979339599609375");
320        BigDecimal aNumber = new BigDecimal(a);
321        assertEquals("incorrect value", bA, aNumber.unscaledValue());
322        assertEquals("incorrect scale", aScale, aNumber.scale());
323    }
324
325    /**
326     * new BigDecimal(-0.1)
327     */
328    public void testConstrDoubleMinus01() {
329        double a = -1.E-1;
330        int aScale = 55;
331        BigInteger bA = new BigInteger("-1000000000000000055511151231257827021181583404541015625");
332        BigDecimal aNumber = new BigDecimal(a);
333        assertEquals("incorrect value", bA, aNumber.unscaledValue());
334        assertEquals("incorrect scale", aScale, aNumber.scale());
335    }
336
337    /**
338     * new BigDecimal(int value)
339     */
340    public void testConstrInt() {
341        int a = 732546982;
342        String res = "732546982";
343        int resScale = 0;
344        BigDecimal result = new BigDecimal(a);
345        assertEquals("incorrect value", res, result.unscaledValue().toString());
346        assertEquals("incorrect scale", resScale, result.scale());
347    }
348
349    /**
350     * new BigDecimal(int, MathContext)
351     */
352    public void testConstrIntMathContext() {
353        int a = 732546982;
354        int precision = 21;
355        RoundingMode rm = RoundingMode.CEILING;
356        MathContext mc = new MathContext(precision, rm);
357        String res = "732546982";
358        int resScale = 0;
359        BigDecimal result = new BigDecimal(a, mc);
360        assertEquals("incorrect value", res, result.unscaledValue().toString());
361        assertEquals("incorrect scale", resScale, result.scale());
362    }
363
364    /**
365     * new BigDecimal(long value)
366     */
367    public void testConstrLong() {
368        long a = 4576578677732546982L;
369        String res = "4576578677732546982";
370        int resScale = 0;
371        BigDecimal result = new BigDecimal(a);
372        assertEquals("incorrect value", res, result.unscaledValue().toString());
373        assertEquals("incorrect scale", resScale, result.scale());
374    }
375
376    /**
377     * new BigDecimal(long, MathContext)
378     */
379    public void testConstrLongMathContext() {
380        long a = 4576578677732546982L;
381        int precision = 5;
382        RoundingMode rm = RoundingMode.CEILING;
383        MathContext mc = new MathContext(precision, rm);
384        String res = "45766";
385        int resScale = -14;
386        BigDecimal result = new BigDecimal(a, mc);
387        assertEquals("incorrect value", res, result.unscaledValue().toString());
388        assertEquals("incorrect scale", resScale, result.scale());
389    }
390
391    /**
392     * new BigDecimal(double value) when value is denormalized
393     */
394    public void testConstrDoubleDenormalized() {
395        double a = 2.274341322658976E-309;
396        int aScale = 1073;
397        BigInteger bA = new BigInteger("227434132265897633950269241702666687639731047124115603942986140264569528085692462493371029187342478828091760934014851133733918639492582043963243759464684978401240614084312038547315281016804838374623558434472007664427140169018817050565150914041833284370702366055678057809362286455237716100382057360123091641959140448783514464639706721250400288267372238950016114583259228262046633530468551311769574111763316146065958042194569102063373243372766692713192728878701004405568459288708477607744497502929764155046100964958011009313090462293046650352146796805866786767887226278836423536035611825593567576424943331337401071583562754098901412372708947790843318760718495117047155597276492717187936854356663665005157041552436478744491526494952982062613955349661409854888916015625");
398        BigDecimal aNumber = new BigDecimal(a);
399        assertEquals("incorrect value", bA, aNumber.unscaledValue());
400        assertEquals("incorrect scale", aScale, aNumber.scale());
401    }
402
403    /**
404     * new BigDecimal(String value)
405     * when value is not a valid representation of BigDecimal.
406     */
407    public void testConstrStringException() {
408        String a = "-238768.787678287a+10";
409        try {
410            new BigDecimal(a);
411            fail("NumberFormatException has not been caught");
412        } catch (NumberFormatException e) {}
413    }
414
415    /**
416     * new BigDecimal(String value) when exponent is empty.
417     */
418    public void testConstrStringExceptionEmptyExponent1() {
419        String a = "-238768.787678287e";
420        try {
421            new BigDecimal(a);
422            fail("NumberFormatException has not been caught");
423        } catch (NumberFormatException e) {
424        }
425    }
426
427    /**
428     * new BigDecimal(String value) when exponent is empty.
429     */
430    public void testConstrStringExceptionEmptyExponent2() {
431        String a = "-238768.787678287e-";
432        try {
433            new BigDecimal(a);
434            fail("NumberFormatException has not been caught");
435        } catch (NumberFormatException e) {
436        }
437    }
438
439    /**
440     * new BigDecimal(String value) when exponent is greater than
441     * Integer.MAX_VALUE.
442     */
443    public void testConstrStringExceptionExponentGreaterIntegerMax() {
444        String a = "-238768.787678287e214748364767876";
445        try {
446            new BigDecimal(a);
447            fail("NumberFormatException has not been caught");
448        } catch (NumberFormatException e) {
449        }
450    }
451
452    /**
453     * new BigDecimal(String value) when exponent is less than
454     * Integer.MIN_VALUE.
455     */
456    public void testConstrStringExceptionExponentLessIntegerMin() {
457        String a = "-238768.787678287e-214748364767876";
458        try {
459            new BigDecimal(a);
460            fail("NumberFormatException has not been caught");
461        } catch (NumberFormatException e) {
462        }
463    }
464
465    /**
466     * new BigDecimal(String value)
467     * when exponent is Integer.MAX_VALUE.
468     */
469    public void testConstrStringExponentIntegerMax() {
470        String a = "-238768.787678287e2147483647";
471        int aScale = -2147483638;
472        BigInteger bA = new BigInteger("-238768787678287");
473        BigDecimal aNumber = new BigDecimal(a);
474        assertEquals("incorrect value", bA, aNumber.unscaledValue());
475        assertEquals("incorrect scale", aScale, aNumber.scale());
476    }
477
478    /**
479     * new BigDecimal(String value)
480     * when exponent is Integer.MIN_VALUE.
481     */
482    public void testConstrStringExponentIntegerMin() {
483        String a = ".238768e-2147483648";
484        try {
485           new BigDecimal(a);
486           fail("NumberFormatException expected");
487       } catch (NumberFormatException e) {
488       }
489    }
490
491    /**
492     * new BigDecimal(String value); value does not contain exponent
493     */
494      public void testConstrStringWithoutExpPos1() {
495        String a = "732546982374982347892379283571094797.287346782359284756";
496        int aScale = 18;
497        BigInteger bA = new BigInteger("732546982374982347892379283571094797287346782359284756");
498        BigDecimal aNumber = new BigDecimal(a);
499        assertEquals("incorrect value", bA, aNumber.unscaledValue());
500        assertEquals("incorrect scale", aScale, aNumber.scale());
501    }
502
503    /**
504     * new BigDecimal(String value); value does not contain exponent
505     */
506      public void testConstrStringWithoutExpPos2() {
507        String a = "+732546982374982347892379283571094797.287346782359284756";
508        int aScale = 18;
509        BigInteger bA = new BigInteger("732546982374982347892379283571094797287346782359284756");
510        BigDecimal aNumber = new BigDecimal(a);
511        assertEquals("incorrect value", bA, aNumber.unscaledValue());
512        assertEquals("incorrect scale", aScale, aNumber.scale());
513    }
514
515    /**
516     * new BigDecimal(String value); value does not contain exponent
517     */
518      public void testConstrStringWithoutExpNeg() {
519        String a = "-732546982374982347892379283571094797.287346782359284756";
520        int aScale = 18;
521        BigInteger bA = new BigInteger("-732546982374982347892379283571094797287346782359284756");
522        BigDecimal aNumber = new BigDecimal(a);
523        assertEquals("incorrect value", bA, aNumber.unscaledValue());
524        assertEquals("incorrect scale", aScale, aNumber.scale());
525    }
526
527    /**
528     * new BigDecimal(String value); value does not contain exponent
529     * and decimal point
530     */
531      public void testConstrStringWithoutExpWithoutPoint() {
532        String a = "-732546982374982347892379283571094797287346782359284756";
533        int aScale = 0;
534        BigInteger bA = new BigInteger("-732546982374982347892379283571094797287346782359284756");
535        BigDecimal aNumber = new BigDecimal(a);
536        assertEquals("incorrect value", bA, aNumber.unscaledValue());
537        assertEquals("incorrect scale", aScale, aNumber.scale());
538    }
539
540      /**
541       * new BigDecimal(String value); value contains exponent
542       * and does not contain decimal point
543       */
544      public void testConstrStringWithExponentWithoutPoint1() {
545          String a = "-238768787678287e214";
546          int aScale = -214;
547          BigInteger bA = new BigInteger("-238768787678287");
548          BigDecimal aNumber = new BigDecimal(a);
549          assertEquals("incorrect value", bA, aNumber.unscaledValue());
550          assertEquals("incorrect scale", aScale, aNumber.scale());
551      }
552
553    /**
554     * new BigDecimal(String value); value contains exponent
555     * and does not contain decimal point
556     */
557    public void testConstrStringWithExponentWithoutPoint2() {
558        String a = "-238768787678287e-214";
559        int aScale = 214;
560        BigInteger bA = new BigInteger("-238768787678287");
561        BigDecimal aNumber = new BigDecimal(a);
562        assertEquals("incorrect value", bA, aNumber.unscaledValue());
563        assertEquals("incorrect scale", aScale, aNumber.scale());
564    }
565
566    /**
567     * new BigDecimal(String value); value contains exponent
568     * and does not contain decimal point
569     */
570    public void testConstrStringWithExponentWithoutPoint3() {
571        String a = "238768787678287e-214";
572        int aScale = 214;
573        BigInteger bA = new BigInteger("238768787678287");
574        BigDecimal aNumber = new BigDecimal(a);
575        assertEquals("incorrect value", bA, aNumber.unscaledValue());
576        assertEquals("incorrect scale", aScale, aNumber.scale());
577    }
578
579    /**
580     * new BigDecimal(String value); value contains exponent
581     * and does not contain decimal point
582     */
583    public void testConstrStringWithExponentWithoutPoint4() {
584        String a = "238768787678287e+214";
585        int aScale = -214;
586        BigInteger bA = new BigInteger("238768787678287");
587        BigDecimal aNumber = new BigDecimal(a);
588        assertEquals("incorrect value", bA, aNumber.unscaledValue());
589        assertEquals("incorrect scale", aScale, aNumber.scale());
590    }
591
592    /**
593     * new BigDecimal(String value); value contains exponent
594     * and does not contain decimal point
595     */
596    public void testConstrStringWithExponentWithoutPoint5() {
597        String a = "238768787678287E214";
598        int aScale = -214;
599        BigInteger bA = new BigInteger("238768787678287");
600        BigDecimal aNumber = new BigDecimal(a);
601        assertEquals("incorrect value", bA, aNumber.unscaledValue());
602        assertEquals("incorrect scale", aScale, aNumber.scale());
603    }
604
605    /**
606     * new BigDecimal(String value);
607     * value contains both exponent and decimal point
608     */
609    public void testConstrStringWithExponentWithPoint1() {
610        String a = "23985439837984782435652424523876878.7678287e+214";
611        int aScale = -207;
612        BigInteger bA = new BigInteger("239854398379847824356524245238768787678287");
613        BigDecimal aNumber = new BigDecimal(a);
614        assertEquals("incorrect value", bA, aNumber.unscaledValue());
615        assertEquals("incorrect scale", aScale, aNumber.scale());
616    }
617
618    /**
619     * new BigDecimal(String value);
620     * value contains both exponent and decimal point
621     */
622    public void testConstrStringWithExponentWithPoint2() {
623        String a = "238096483923847545735673567457356356789029578490276878.7678287e-214";
624        int aScale = 221;
625        BigInteger bA = new BigInteger("2380964839238475457356735674573563567890295784902768787678287");
626        BigDecimal aNumber = new BigDecimal(a);
627        assertEquals("incorrect value", bA, aNumber.unscaledValue());
628        assertEquals("incorrect scale", aScale, aNumber.scale());
629    }
630
631    /**
632     * new BigDecimal(String value);
633     * value contains both exponent and decimal point
634     */
635    public void testConstrStringWithExponentWithPoint3() {
636        String a = "2380964839238475457356735674573563567890.295784902768787678287E+21";
637        int aScale = 0;
638        BigInteger bA = new BigInteger("2380964839238475457356735674573563567890295784902768787678287");
639        BigDecimal aNumber = new BigDecimal(a);
640        assertEquals("incorrect value", bA, aNumber.unscaledValue());
641        assertEquals("incorrect scale", aScale, aNumber.scale());
642    }
643
644    /**
645     * new BigDecimal(String value);
646     * value contains both exponent and decimal point
647     */
648    public void testConstrStringWithExponentWithPoint4() {
649        String a = "23809648392384754573567356745735635678.90295784902768787678287E+21";
650        int aScale = 2;
651        BigInteger bA = new BigInteger("2380964839238475457356735674573563567890295784902768787678287");
652        BigDecimal aNumber = new BigDecimal(a);
653        assertEquals("incorrect value", bA, aNumber.unscaledValue());
654        assertEquals("incorrect scale", aScale, aNumber.scale());
655    }
656
657    /**
658     * new BigDecimal(String value);
659     * value contains both exponent and decimal point
660     */
661    public void testConstrStringWithExponentWithPoint5() {
662        String a = "238096483923847545735673567457356356789029.5784902768787678287E+21";
663        int aScale = -2;
664        BigInteger bA = new BigInteger("2380964839238475457356735674573563567890295784902768787678287");
665        BigDecimal aNumber = new BigDecimal(a);
666        assertEquals("incorrect value", bA, aNumber.unscaledValue());
667        assertEquals("incorrect scale", aScale, aNumber.scale());
668    }
669
670    /**
671     * new BigDecimal(String value, MathContext)
672     */
673    public void testConstrStringMathContext() {
674        String a = "-238768787678287e214";
675        int precision = 5;
676        RoundingMode rm = RoundingMode.CEILING;
677        MathContext mc = new MathContext(precision, rm);
678        String res = "-23876";
679        int resScale = -224;
680        BigDecimal result = new BigDecimal(a, mc);
681        assertEquals("incorrect value", res, result.unscaledValue().toString());
682        assertEquals("incorrect scale", resScale, result.scale());
683    }
684}
685