1 // Tags: JDK1.2 |
|
2 |
|
3 /* This code was derived from test code from IBM's ICU project, which |
|
4 uses the following license... |
|
5 |
|
6 Copyright (c) 1995-2001 International Business Machines Corporation and others |
|
7 |
|
8 All rights reserved. |
|
9 |
|
10 Permission is hereby granted, free of charge, to any person obtaining |
|
11 a copy of this software and associated documentation files (the |
|
12 "Software"), to deal in the Software without restriction, including |
|
13 without limitation the rights to use, copy, modify, merge, publish, |
|
14 distribute, and/or sell copies of the Software, and to permit persons |
|
15 to whom the Software is furnished to do so, provided that the above |
|
16 copyright notice(s) and this permission notice appear in all copies of |
|
17 the Software and that both the above copyright notice(s) and this |
|
18 permission notice appear in supporting documentation. |
|
19 |
|
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT |
|
23 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
24 HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY |
|
25 SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER |
|
26 RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
|
27 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|
28 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
29 |
|
30 Except as contained in this notice, the name of a copyright holder |
|
31 shall not be used in advertising or otherwise to promote the sale, use |
|
32 or other dealings in this Software without prior written authorization |
|
33 of the copyright holder. |
|
34 |
|
35 All trademarks and registered trademarks mentioned herein are the |
|
36 property of their respective owners. |
|
37 |
|
38 */ |
|
39 |
|
40 |
|
41 /* Generated from 'DiagBigDecimal.nrx' 27 Mar 2000 22:38:44 [v1.162] */ |
|
42 /* Options: Binary Comments Crossref Format Java Logo Trace1 Verbose3 */ |
|
43 package gnu.testlet.java.math.BigDecimal; |
|
44 |
|
45 import java.math.*; |
|
46 import gnu.testlet.Testlet; |
|
47 import gnu.testlet.TestHarness; |
|
48 |
|
49 /* ------------------------------------------------------------------ */ |
|
50 /* Decimal diagnostic tests mfc */ |
|
51 /* Copyright (c) IBM Corporation 1996, 2000. All Rights Reserved. */ |
|
52 /* ------------------------------------------------------------------ */ |
|
53 /* DiagBigDecimal */ |
|
54 /* */ |
|
55 /* A class that tests the BigDecimal and MathContext classes. */ |
|
56 /* */ |
|
57 /* The tests here are derived from or cover the same paths as: */ |
|
58 /* -- ANSI X3-274 testcases */ |
|
59 /* -- Java JCK testcases */ |
|
60 /* -- NetRexx testcases */ |
|
61 /* -- VM/CMS S/370 REXX implementation testcases [1981+] */ |
|
62 /* -- IBM Vienna Laboratory Rexx compiler testcases [1988+] */ |
|
63 /* -- New testcases */ |
|
64 /* */ |
|
65 /* The authoritative sources for how the underlying technology */ |
|
66 /* (arithmetic) should work are: */ |
|
67 /* -- for digits=0 (fixed point): java.math.BigDecimal */ |
|
68 /* -- for digits>0 (floating point): ANSI X3.274-1996 + errata */ |
|
69 /* */ |
|
70 /* ------------------------------------------------------------------ */ |
|
71 /* Change list */ |
|
72 /* 1997.09.05 Initial implementation, from DiagRexx [NetRexx tests] */ |
|
73 /* 1998.05.02 0.07 changes (e.g., compareTo) */ |
|
74 /* 1998.06.06 Rounding modes and format additions */ |
|
75 /* 1998.06.25 Rename from DiagDecimal; make stand-alone [add */ |
|
76 /* DiagException as a Minor class] */ |
|
77 /* 1998.06.27 Start adding testcases for DIGITS=0/FORM=PLAIN cases */ |
|
78 /* Reorganize for faster trace compilation */ |
|
79 /* 1998.06.28 new: valueof, scale, movePointX, unscaledValue, etc. */ |
|
80 /* 1998.07.07 Scaled divide */ |
|
81 /* 1998.07.08 setScale */ |
|
82 /* 1998.07.15 new scaffolding (Minor Test class) -- see diagabs */ |
|
83 /* 1998.12.14 add toBigDecimal and BigDecimal(java.math.BigDecimal) */ |
|
84 /* 1999.02.04 number preparation rounds instead of digits+1 trunc */ |
|
85 /* 1999.02.09 format method now only has two signatures */ |
|
86 /* 1999.02.27 no longer use Rexx class or RexxIO class */ |
|
87 /* 1999.03.05 add MathContext tests */ |
|
88 /* 1999.03.05 update for 0.96 [no null settings, etc.] */ |
|
89 /* drop sundry constructors; no blanks; char[] gets ints */ |
|
90 /* drop sundry converters, add Exact converters */ |
|
91 /* 1999.05.27 additional tests for scaled arithmetic */ |
|
92 /* 1999.06.29 additional tests for exponent overflows */ |
|
93 /* 1999.07.03 add 'continue' option */ |
|
94 /* 1999.07.10 additional tests for scaled arithmetic */ |
|
95 /* 1999.07.18 randomly-generated tests added for base operators */ |
|
96 /* 1999.10.28 weird intValueExact bad cases */ |
|
97 /* 1999.12.21 multiplication fast path failure and edge cases */ |
|
98 /* 2000.01.01 copyright update */ |
|
99 /* 2000.03.26 cosmetic updates; add extra format() testcases */ |
|
100 /* 2000.03.27 1.00 move to com.ibm.icu.math package; open source release; */ |
|
101 /* change to javadoc comments */ |
|
102 /* ------------------------------------------------------------------ */ |
|
103 |
|
104 // note BINARY for conversions checking |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 /** |
|
110 * The <code>DiagBigDecimal</code> class forms a standalone test suite |
|
111 * for the <code>com.ibm.icu.math.BigDecimal</code> and |
|
112 * <code>com.ibm.icu.math.MathContext</code> classes (or, by changing the |
|
113 * <code>package</code> statement, other classes of the same names and |
|
114 * definition in other packages). It may also be used as a constructed |
|
115 * object to embed the tests in an external test harness. |
|
116 * <p> |
|
117 * The tests are collected into <i>groups</i>, each corresponding to a |
|
118 * tested method or a more general grouping. By default, when run from |
|
119 * the static {@link #main(java.lang.String[])} method, the run will end |
|
120 * if any test fails in a group. The <code>continue</code> argument may |
|
121 * be specified to force the tests to run to completion. |
|
122 * <p> |
|
123 * Two minor (inner) classes are used; {@link |
|
124 * DiagBigDecimal.DiagException} is used to signal the failure of a test |
|
125 * group, and {@link DiagBigDecimal.Test}, a dependent minor class, is |
|
126 * used to register tests so that a summary of failures (or success) can be |
|
127 * presented as each group is completed. |
|
128 * |
|
129 * @see com.ibm.icu.math.BigDecimal |
|
130 * @see com.ibm.icu.math.MathContext |
|
131 * @version 1.00 2000.03.27 |
|
132 * @author Mike Cowlishaw |
|
133 */ |
|
134 |
|
135 public class DiagBigDecimal implements Testlet { |
|
136 private final boolean CHECK_EXCEPTION_MESSAGES = false; |
|
137 |
|
138 private static final java.lang.String xx0="DiagBigDecimal.nrx"; |
|
139 |
|
140 /* properties shared */ |
|
141 java.util.Vector Tests=new java.util.Vector(100); // scaffolding |
|
142 |
|
143 /* properties private */ |
|
144 private int totalcount=0; // counts tests run |
|
145 |
|
146 /* properties constant private */ |
|
147 |
|
148 /* Count of test groups */ |
|
149 private static final int testcount=38; |
|
150 |
|
151 private static final BigDecimal zero=new BigDecimal (BigInteger.valueOf (0), 0); |
|
152 private static final BigDecimal one=new BigDecimal (BigInteger.valueOf (1), 0); |
|
153 private static final BigDecimal two=new BigDecimal (BigInteger.valueOf (2), 0); |
|
154 private static final BigDecimal ten=new BigDecimal (BigInteger.valueOf (10), 0); |
|
155 private static final BigDecimal tenlong=new BigDecimal((long)1234554321); // 10-digiter |
|
156 |
|
157 /* boundary primitive values */ |
|
158 private static final byte bmin=-128; |
|
159 private static final byte bmax=127; |
|
160 private static final byte bzer=0; |
|
161 private static final byte bneg=-1; |
|
162 private static final byte bpos=1; |
|
163 private static final int imin=-2147483648; |
|
164 private static final int imax=2147483647; |
|
165 private static final int izer=0; |
|
166 private static final int ineg=-1; |
|
167 private static final int ipos=1; |
|
168 private static final long lmin=-9223372036854775808L; |
|
169 private static final long lmax=9223372036854775807L; |
|
170 private static final String lminString="-9223372036854775808"; |
|
171 private static final String lmaxString="9223372036854775807"; |
|
172 private static final long lzer=(long)0; |
|
173 private static final long lneg=(long)-1; |
|
174 private static final long lpos=(long)1; |
|
175 private static final short smin=-32768; |
|
176 private static final short smax=32767; |
|
177 private static final short szer=(short)0; |
|
178 private static final short sneg=(short)(-1); |
|
179 private static final short spos=(short)1; |
|
180 |
|
181 |
|
182 /* properties constant private unused */ // present but not referenced |
|
183 private static final java.lang.String copyright=" Copyright (c) IBM Corporation 1996, 2000. All rights reserved. "; |
|
184 |
|
185 |
|
186 /** Constructs a <code>DiagBigDecimal</code> test suite. |
|
187 * <p> |
|
188 * Invoke its {@link #diagrun} method to run the tests. |
|
189 */ |
|
190 |
|
191 public DiagBigDecimal(){super(); |
|
192 return; |
|
193 } |
|
194 |
|
195 /** Run the tests in the test suite. |
|
196 * |
|
197 * @param isContinue The <code>boolean</code> which determines whether |
|
198 * to stop running after a group fails. If 1 (true) |
|
199 * then the tests should be run to completion if |
|
200 * possible; if 0 (false) then the run will end if a |
|
201 * group fails. |
|
202 * @return an <code>int</code> which is 0 if all tests were |
|
203 * successful, >0 (the count of failures) if some failures were |
|
204 * detected, or <0 if an unexpected Exception was signalled. |
|
205 */ |
|
206 |
|
207 public void diagrun(TestHarness harness){ |
|
208 int num=0; |
|
209 RuntimeException de=null; |
|
210 java.lang.RuntimeException e=null; |
|
211 java.lang.String rest=null; |
|
212 |
|
213 try{num=1;num:for(;num<=testcount;num++){ // [testcount is constant set above] |
|
214 try{ |
|
215 dotest(harness, num); |
|
216 } |
|
217 catch (RuntimeException xx1){de=xx1; |
|
218 say(harness); |
|
219 harness.verbose("**** Failed:"+" "+de.getMessage()+" "+"****"); |
|
220 say(harness); |
|
221 } |
|
222 } |
|
223 } |
|
224 catch (java.lang.RuntimeException xx2){e=xx2; // any other exception is total failure; just show trace and quit |
|
225 say(harness); |
|
226 harness.verbose("**** Failed: unexpected exception ****"); |
|
227 e.printStackTrace(); |
|
228 return; |
|
229 }/*num*/ |
|
230 |
|
231 return; |
|
232 } |
|
233 |
|
234 /* Run test by number -- method for development/private switching */ |
|
235 |
|
236 private void dotest(TestHarness harness, int num){ |
|
237 {/*select*/switch(num){ |
|
238 /* -------------------------------------------------------------- */ |
|
239 /* MathContext */ |
|
240 /* -------------------------------------------------------------- */ |
|
241 case 1: |
|
242 break; |
|
243 |
|
244 /* -------------------------------------------------------------- */ |
|
245 /* Constructors */ |
|
246 /* -------------------------------------------------------------- */ |
|
247 case 2: |
|
248 /* diagconstructors(harness); */ break; |
|
249 |
|
250 /* -------------------------------------------------------------- */ |
|
251 /* Operator methods */ |
|
252 /* -------------------------------------------------------------- */ |
|
253 case 3: |
|
254 diagabs(harness);break; |
|
255 case 4: |
|
256 diagadd(harness);break; |
|
257 case 5: |
|
258 diagcompareto(harness);break; |
|
259 case 6: |
|
260 diagdivide(harness);break; |
|
261 case 7: |
|
262 break; |
|
263 case 8: |
|
264 diagmax(harness);break; |
|
265 case 9: |
|
266 diagmin(harness);break; |
|
267 case 10: |
|
268 diagmultiply(harness);break; |
|
269 case 11: |
|
270 diagnegate(harness);break; |
|
271 case 12: |
|
272 break; |
|
273 case 13: |
|
274 break; |
|
275 case 14: |
|
276 break; |
|
277 case 15: |
|
278 diagsubtract(harness);break; |
|
279 case 16: |
|
280 break; |
|
281 |
|
282 /* -------------------------------------------------------------- */ |
|
283 /* Other methods */ |
|
284 /* -------------------------------------------------------------- */ |
|
285 case 17: |
|
286 diagbyteValue(harness);break; |
|
287 case 18: |
|
288 diagcomparetoObj(harness);break; |
|
289 case 19: |
|
290 diagdoublevalue(harness);break; |
|
291 case 20: |
|
292 diagequals(harness);break; |
|
293 case 21: |
|
294 diagfloatvalue(harness);break; |
|
295 case 22: |
|
296 break; |
|
297 case 23: |
|
298 diaghashcode(harness);break; |
|
299 case 24: |
|
300 diagintvalue(harness);break; |
|
301 case 25: |
|
302 diaglongvalue(harness);break; |
|
303 case 26: |
|
304 diagmovepointleft(harness);break; |
|
305 case 27: |
|
306 diagmovepointright(harness);break; |
|
307 case 28: |
|
308 diagscale(harness);break; |
|
309 case 29: |
|
310 diagsetscale(harness);break; |
|
311 case 30: |
|
312 diagshortvalue(harness);break; |
|
313 case 31: |
|
314 diagsignum(harness);break; |
|
315 case 32: |
|
316 break; |
|
317 case 33: |
|
318 diagtobiginteger(harness);break; |
|
319 case 34: |
|
320 break; |
|
321 case 35: |
|
322 diagtostring(harness);break; |
|
323 case 36: |
|
324 break; |
|
325 case 37: |
|
326 diagvalueof(harness);break; |
|
327 |
|
328 /* -------------------------------------------------------------- */ |
|
329 /* Mutation test [must be the last test] */ |
|
330 /* -------------------------------------------------------------- */ |
|
331 case 38: |
|
332 diagmutation(harness);break; |
|
333 // if any more, increase testcount above |
|
334 default:{ |
|
335 say("*** dotest case not found:"+" "+num+" "+"***", harness); |
|
336 }} |
|
337 } |
|
338 return; |
|
339 } |
|
340 |
|
341 /*--------------------------------------------------------------------*/ |
|
342 /* Diagnostic group methods */ |
|
343 /*--------------------------------------------------------------------*/ |
|
344 |
|
345 /** Test constructors (and {@link #toString()} for equalities). */ |
|
346 |
|
347 public void diagconstructors(TestHarness harness){ |
|
348 boolean flag=false; |
|
349 java.lang.String num; |
|
350 java.math.BigInteger bip; |
|
351 java.math.BigInteger biz; |
|
352 java.math.BigInteger bin; |
|
353 BigDecimal bda; |
|
354 BigDecimal bdb; |
|
355 BigDecimal bmc; |
|
356 BigDecimal bmd; |
|
357 BigDecimal bme; |
|
358 java.lang.RuntimeException e=null; |
|
359 char ca[]; |
|
360 double dzer; |
|
361 double dpos; |
|
362 double dneg; |
|
363 double dpos5; |
|
364 double dneg5; |
|
365 double dmin; |
|
366 double dmax; |
|
367 double d; |
|
368 java.lang.String badstrings[]; |
|
369 int i=0; |
|
370 |
|
371 // constants [statically-called constructors] |
|
372 harness.check ((zero.toString()).equals("0"), "con001"); |
|
373 harness.check ((one.toString()).equals("1"), "con002"); |
|
374 harness.check ((ten.toString()).equals("10"), "con003"); |
|
375 harness.check ((zero.intValue())==0, "con004"); |
|
376 harness.check ((one.intValue())==1, "con005"); |
|
377 harness.check ((ten.intValue())==10, "con006"); |
|
378 |
|
379 // [java.math.] BigDecimal |
|
380 harness.check (((new BigDecimal(new BigDecimal("0").toString())).toString()).equals("0"), "cbd001"); |
|
381 harness.check (((new BigDecimal(new BigDecimal("1").toString())).toString()).equals("1"), "cbd002"); |
|
382 harness.check (((new BigDecimal(new BigDecimal("10").toString())).toString()).equals("10"), "cbd003"); |
|
383 harness.check (((new BigDecimal(new BigDecimal("1000").toString())).toString()).equals("1000"), "cbd004"); |
|
384 harness.check (((new BigDecimal(new BigDecimal("10.0").toString())).toString()).equals("10.0"), "cbd005"); |
|
385 harness.check (((new BigDecimal(new BigDecimal("10.1").toString())).toString()).equals("10.1"), "cbd006"); |
|
386 harness.check (((new BigDecimal(new BigDecimal("-1.1").toString())).toString()).equals("-1.1"), "cbd007"); |
|
387 harness.check (((new BigDecimal(new BigDecimal("-9.0").toString())).toString()).equals("-9.0"), "cbd008"); |
|
388 harness.check (((new BigDecimal(new BigDecimal("0.9").toString())).toString()).equals("0.9"), "cbd009"); |
|
389 |
|
390 num="123456789.123456789"; |
|
391 harness.check (((new BigDecimal(new BigDecimal(num).toString())).toString()).equals(num), "cbd010"); |
|
392 num="123456789.000000000"; |
|
393 harness.check (((new BigDecimal(new BigDecimal(num).toString())).toString()).equals(num), "cbd011"); |
|
394 num="123456789000000000"; |
|
395 harness.check (((new BigDecimal(new BigDecimal(num).toString())).toString()).equals(num), "cbd012"); |
|
396 num="0.00000123456789"; |
|
397 harness.check (((new BigDecimal(new BigDecimal(num).toString())).toString()).equals(num), "cbd013"); |
|
398 num="0.000000123456789"; |
|
399 harness.check (((new BigDecimal(new BigDecimal(num).toString())).toString()).equals(num), "cbd014"); |
|
400 |
|
401 // BigInteger |
|
402 bip=new BigInteger("987654321987654321987654321"); // biggie +ve |
|
403 biz=new BigInteger("0"); // biggie 0 |
|
404 bin=new BigInteger("-12345678998765432112345678"); // biggie -ve |
|
405 harness.check (((new BigDecimal(bip)).toString()).equals(bip.toString()), "cbi001"); |
|
406 harness.check (((new BigDecimal(biz)).toString()).equals("0"), "cbi002"); |
|
407 harness.check (((new BigDecimal(bin)).toString()).equals(bin.toString()), "cbi003"); |
|
408 try{checknull:do{ |
|
409 new BigDecimal((java.math.BigInteger)null); |
|
410 flag=false; |
|
411 }while(false);} |
|
412 catch (java.lang.NullPointerException xx4){ |
|
413 flag=true; |
|
414 }/*checknull*/ |
|
415 harness.check (flag, "cbi004"); |
|
416 |
|
417 // BigInteger with scale |
|
418 bip=new BigInteger("123456789"); // bigish |
|
419 bda=new BigDecimal(bip); |
|
420 bdb=new BigDecimal(bip,5); |
|
421 bmc=new BigDecimal(bip,15); |
|
422 harness.check ((bda.toString()).equals("123456789"), "cbs001"); |
|
423 harness.check ((bdb.toString()).equals("1234.56789"), "cbs002"); |
|
424 harness.check ((bmc.toString()).equals("0.000000123456789"), "cbs003"); |
|
425 bip=new BigInteger("123456789123456789123456789"); // biggie |
|
426 bda=new BigDecimal(bip); |
|
427 bdb=new BigDecimal(bip,7); |
|
428 bmc=new BigDecimal(bip,13); |
|
429 bmd=new BigDecimal(bip,19); |
|
430 bme=new BigDecimal(bip,29); |
|
431 harness.check ((bda.toString()).equals("123456789123456789123456789"), "cbs011"); |
|
432 harness.check ((bdb.toString()).equals("12345678912345678912.3456789"), "cbs012"); |
|
433 harness.check ((bmc.toString()).equals("12345678912345.6789123456789"), "cbs013"); |
|
434 harness.check ((bmd.toString()).equals("12345678.9123456789123456789"), "cbs014"); |
|
435 harness.check ((bme.toString()).equals("0.00123456789123456789123456789"), "cbs015"); |
|
436 try{checknull:do{ |
|
437 new BigDecimal((java.math.BigInteger)null,1); |
|
438 flag=false; |
|
439 }while(false);} |
|
440 catch (java.lang.NullPointerException xx5){ |
|
441 flag=true; |
|
442 }/*checknull*/ |
|
443 harness.check (flag, "cbs004"); |
|
444 try{checkscale:do{ |
|
445 new BigDecimal(bip,-8); |
|
446 flag=false; |
|
447 }while(false);} |
|
448 catch (java.lang.RuntimeException xx6){e=xx6; |
|
449 flag=checkMessage(e, "Negative scale: -8"); |
|
450 }/*checkscale*/ |
|
451 harness.check (flag, "cbs005"); |
|
452 |
|
453 // double [deprecated] |
|
454 // Note that many of these differ from the valueOf(double) results. |
|
455 dzer=(double)0; |
|
456 dpos=(double)1; |
|
457 dpos=dpos/((double)10); |
|
458 dneg=(double)-dpos; |
|
459 harness.check (((new BigDecimal(dneg)).toString()).equals("-0.1000000000000000055511151231257827021181583404541015625"), "cdo001"); |
|
460 |
|
461 harness.check (((new BigDecimal(dzer)).toString()).equals("0"), "cdo002"); // NB, not '0.0' |
|
462 harness.check (((new BigDecimal(dpos)).toString()).equals("0.1000000000000000055511151231257827021181583404541015625"), "cdo003"); |
|
463 |
|
464 dpos5=(double)0.5D; |
|
465 dneg5=(double)-dpos5; |
|
466 harness.check (((new BigDecimal(dneg5)).toString()).equals("-0.5"), "cdo004"); |
|
467 harness.check (((new BigDecimal(dpos5)).toString()).equals("0.5"), "cdo005"); |
|
468 dmin=java.lang.Double.MIN_VALUE; |
|
469 dmax=java.lang.Double.MAX_VALUE; |
|
470 harness.check (((new BigDecimal(dmin)).toString()).equals("0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625"), "cdo006"); |
|
471 |
|
472 harness.check (((new BigDecimal(dmax)).toString()).equals("179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368"), "cdo007"); |
|
473 |
|
474 |
|
475 // nasties |
|
476 d=(double)9; |
|
477 d=d/((double)10); |
|
478 harness.check (((new BigDecimal(d)).toString()).equals("0.90000000000000002220446049250313080847263336181640625"), "cdo010"); |
|
479 |
|
480 d=d/((double)10); |
|
481 harness.check (((new BigDecimal(d)).toString()).equals("0.0899999999999999966693309261245303787291049957275390625"), "cdo011"); |
|
482 |
|
483 d=d/((double)10); |
|
484 harness.check (((new BigDecimal(d)).toString()).equals("0.00899999999999999931998839741709161899052560329437255859375"), "cdo012"); |
|
485 |
|
486 d=d/((double)10); |
|
487 harness.check (((new BigDecimal(d)).toString()).equals("0.00089999999999999997536692664112933925935067236423492431640625"), "cdo013"); |
|
488 |
|
489 d=d/((double)10); |
|
490 harness.check (((new BigDecimal(d)).toString()).equals("0.00008999999999999999211568180168541175589780323207378387451171875"), "cdo014"); |
|
491 |
|
492 d=d/((double)10); |
|
493 harness.check (((new BigDecimal(d)).toString()).equals("0.00000899999999999999853394182236510090433512232266366481781005859375"), "cdo015"); |
|
494 |
|
495 d=d/((double)10); |
|
496 harness.check (((new BigDecimal(d)).toString()).equals("0.000000899999999999999853394182236510090433512232266366481781005859375"), "cdo016"); |
|
497 |
|
498 d=d/((double)10); |
|
499 harness.check (((new BigDecimal(d)).toString()).equals("0.0000000899999999999999853394182236510090433512232266366481781005859375"), "cdo017"); |
|
500 |
|
501 d=d/((double)10); |
|
502 harness.check (((new BigDecimal(d)).toString()).equals("0.000000008999999999999997872197332322678764437995369007694534957408905029296875"), "cdo018"); |
|
503 |
|
504 |
|
505 try{checkpin:do{ |
|
506 new BigDecimal(java.lang.Double.POSITIVE_INFINITY); |
|
507 flag=false; |
|
508 }while(false);} |
|
509 catch (java.lang.NumberFormatException xx13){ |
|
510 flag=true; |
|
511 }/*checkpin*/ |
|
512 harness.check (flag, "cdo101"); |
|
513 try{checknin:do{ |
|
514 new BigDecimal(java.lang.Double.NEGATIVE_INFINITY); |
|
515 flag=false; |
|
516 }while(false);} |
|
517 catch (java.lang.NumberFormatException xx14){ |
|
518 flag=true; |
|
519 }/*checknin*/ |
|
520 harness.check (flag, "cdo102"); |
|
521 try{checknan:do{ |
|
522 new BigDecimal(java.lang.Double.NaN); |
|
523 flag=false; |
|
524 }while(false);} |
|
525 catch (java.lang.NumberFormatException xx15){ |
|
526 flag=true; |
|
527 }/*checknan*/ |
|
528 harness.check (flag, "cdo103"); |
|
529 |
|
530 // int |
|
531 harness.check (((new BigDecimal(imin)).toString()).equals("-2147483648"), "cin001"); |
|
532 harness.check (((new BigDecimal(imax)).toString()).equals("2147483647"), "cin002"); |
|
533 harness.check (((new BigDecimal(ineg)).toString()).equals("-1"), "cin003"); |
|
534 harness.check (((new BigDecimal(izer)).toString()).equals("0"), "cin004"); |
|
535 harness.check (((new BigDecimal(ipos)).toString()).equals("1"), "cin005"); |
|
536 harness.check (((new BigDecimal(10)).toString()).equals("10"), "cin006"); |
|
537 harness.check (((new BigDecimal(9)).toString()).equals("9"), "cin007"); |
|
538 harness.check (((new BigDecimal(5)).toString()).equals("5"), "cin008"); |
|
539 harness.check (((new BigDecimal(2)).toString()).equals("2"), "cin009"); |
|
540 harness.check (((new BigDecimal(-2)).toString()).equals("-2"), "cin010"); |
|
541 harness.check (((new BigDecimal(-5)).toString()).equals("-5"), "cin011"); |
|
542 harness.check (((new BigDecimal(-9)).toString()).equals("-9"), "cin012"); |
|
543 harness.check (((new BigDecimal(-10)).toString()).equals("-10"), "cin013"); |
|
544 harness.check (((new BigDecimal(-11)).toString()).equals("-11"), "cin014"); |
|
545 harness.check (((new BigDecimal(-99)).toString()).equals("-99"), "cin015"); |
|
546 harness.check (((new BigDecimal(-100)).toString()).equals("-100"), "cin016"); |
|
547 harness.check (((new BigDecimal(-999)).toString()).equals("-999"), "cin017"); |
|
548 harness.check (((new BigDecimal(-1000)).toString()).equals("-1000"), "cin018"); |
|
549 |
|
550 harness.check (((new BigDecimal(11)).toString()).equals("11"), "cin019"); |
|
551 harness.check (((new BigDecimal(99)).toString()).equals("99"), "cin020"); |
|
552 harness.check (((new BigDecimal(100)).toString()).equals("100"), "cin021"); |
|
553 harness.check (((new BigDecimal(999)).toString()).equals("999"), "cin022"); |
|
554 harness.check (((new BigDecimal(1000)).toString()).equals("1000"), "cin023"); |
|
555 |
|
556 // long |
|
557 harness.check (((new BigDecimal(lmin)).toString()).equals("-9223372036854775808"), "clo001"); |
|
558 harness.check (((new BigDecimal(lmax)).toString()).equals("9223372036854775807"), "clo002"); |
|
559 harness.check (((new BigDecimal(lneg)).toString()).equals("-1"), "clo003"); |
|
560 harness.check (((new BigDecimal(lzer)).toString()).equals("0"), "clo004"); |
|
561 harness.check (((new BigDecimal(lpos)).toString()).equals("1"), "clo005"); |
|
562 |
|
563 // String [many more examples are elsewhere] |
|
564 // strings without E cannot generate E in result |
|
565 harness.check (((new BigDecimal("12")).toString()).equals("12"), "cst001"); |
|
566 harness.check (((new BigDecimal("-76")).toString()).equals("-76"), "cst002"); |
|
567 harness.check (((new BigDecimal("12.76")).toString()).equals("12.76"), "cst003"); |
|
568 harness.check (((new BigDecimal("+12.76")).toString()).equals("12.76"), "cst004"); |
|
569 harness.check (((new BigDecimal("012.76")).toString()).equals("12.76"), "cst005"); |
|
570 harness.check (((new BigDecimal("+0.003")).toString()).equals("0.003"), "cst006"); |
|
571 harness.check (((new BigDecimal("17.")).toString()).equals("17"), "cst007"); |
|
572 harness.check (((new BigDecimal(".5")).toString()).equals("0.5"), "cst008"); |
|
573 harness.check (((new BigDecimal("044")).toString()).equals("44"), "cst009"); |
|
574 harness.check (((new BigDecimal("0044")).toString()).equals("44"), "cst010"); |
|
575 harness.check (((new BigDecimal("0.0005")).toString()).equals("0.0005"), "cst011"); |
|
576 harness.check (((new BigDecimal("00.00005")).toString()).equals("0.00005"), "cst012"); |
|
577 harness.check (((new BigDecimal("0.000005")).toString()).equals("0.000005"), "cst013"); |
|
578 harness.check (((new BigDecimal("0.0000005")).toString()).equals("0.0000005"), "cst014"); |
|
579 harness.check (((new BigDecimal("0.00000005")).toString()).equals("0.00000005"), "cst015"); |
|
580 harness.check (((new BigDecimal("12345678.876543210")).toString()).equals("12345678.876543210"), "cst016"); |
|
581 harness.check (((new BigDecimal("2345678.876543210")).toString()).equals("2345678.876543210"), "cst017"); |
|
582 harness.check (((new BigDecimal("345678.876543210")).toString()).equals("345678.876543210"), "cst018"); |
|
583 harness.check (((new BigDecimal("0345678.87654321")).toString()).equals("345678.87654321"), "cst019"); |
|
584 harness.check (((new BigDecimal("345678.8765432")).toString()).equals("345678.8765432"), "cst020"); |
|
585 harness.check (((new BigDecimal("+345678.8765432")).toString()).equals("345678.8765432"), "cst021"); |
|
586 harness.check (((new BigDecimal("+0345678.8765432")).toString()).equals("345678.8765432"), "cst022"); |
|
587 harness.check (((new BigDecimal("+00345678.8765432")).toString()).equals("345678.8765432"), "cst023"); |
|
588 harness.check (((new BigDecimal("-345678.8765432")).toString()).equals("-345678.8765432"), "cst024"); |
|
589 harness.check (((new BigDecimal("-0345678.8765432")).toString()).equals("-345678.8765432"), "cst025"); |
|
590 harness.check (((new BigDecimal("-00345678.8765432")).toString()).equals("-345678.8765432"), "cst026"); |
|
591 |
|
592 // exotics -- |
|
593 harness.check (((new BigDecimal("\u0e57.\u0e50")).toString()).equals("7.0"), "cst035"); |
|
594 harness.check (((new BigDecimal("\u0b66.\u0b67")).toString()).equals("0.1"), "cst036"); |
|
595 harness.check (((new BigDecimal("\u0b66\u0b66")).toString()).equals("0"), "cst037"); |
|
596 harness.check (((new BigDecimal("\u0b6a\u0b66")).toString()).equals("40"), "cst038"); |
|
597 |
|
598 // strings with E |
|
599 // Some implementations throw a NumberFormatException here. |
|
600 try { |
|
601 harness.check (((new BigDecimal("1E+9")).toString()).equals("1E+9"), "cst040"); |
|
602 } catch (Exception ecst040) { |
|
603 harness.check (false, "cst040"); |
|
604 } |
|
605 try { |
|
606 harness.check (((new BigDecimal("1e+09")).toString()).equals("1E+9"), "cst041"); |
|
607 } catch (Exception ecst041) { |
|
608 harness.check (false, "cst041"); |
|
609 } |
|
610 try { |
|
611 harness.check (((new BigDecimal("1E+90")).toString()).equals("1E+90"), "cst042"); |
|
612 } catch (Exception ecst042) { |
|
613 harness.check (false, "cst042"); |
|
614 } |
|
615 try { |
|
616 harness.check (((new BigDecimal("+1E+009")).toString()).equals("1E+9"), "cst043"); |
|
617 } catch (Exception ecst043) { |
|
618 harness.check (false, "cst043"); |
|
619 } |
|
620 try { |
|
621 harness.check (((new BigDecimal("0E+9")).toString()).equals("0"), "cst044"); |
|
622 } catch (Exception ecst044) { |
|
623 harness.check (false, "cst044"); |
|
624 } |
|
625 try { |
|
626 harness.check (((new BigDecimal("1E+9")).toString()).equals("1E+9"), "cst045"); |
|
627 } catch (Exception ecst045) { |
|
628 harness.check (false, "cst045"); |
|
629 } |
|
630 try { |
|
631 harness.check (((new BigDecimal("1E+09")).toString()).equals("1E+9"), "cst046"); |
|
632 } catch (Exception ecst046) { |
|
633 harness.check (false, "cst046"); |
|
634 } |
|
635 try { |
|
636 harness.check (((new BigDecimal("1e+90")).toString()).equals("1E+90"), "cst047"); |
|
637 } catch (Exception ecst047) { |
|
638 harness.check (false, "cst047"); |
|
639 } |
|
640 try { |
|
641 harness.check (((new BigDecimal("1E+009")).toString()).equals("1E+9"), "cst048"); |
|
642 } catch (Exception ecst048) { |
|
643 harness.check (false, "cst048"); |
|
644 } |
|
645 try { |
|
646 harness.check (((new BigDecimal("0E+9")).toString()).equals("0"), "cst049"); |
|
647 } catch (Exception ecst049) { |
|
648 harness.check (false, "cst049"); |
|
649 } |
|
650 try { |
|
651 harness.check (((new BigDecimal("1E9")).toString()).equals("1E+9"), "cst050"); |
|
652 } catch (Exception ecst050) { |
|
653 harness.check (false, "cst050"); |
|
654 } |
|
655 try { |
|
656 harness.check (((new BigDecimal("1e09")).toString()).equals("1E+9"), "cst051"); |
|
657 } catch (Exception ecst051) { |
|
658 harness.check (false, "cst051"); |
|
659 } |
|
660 try { |
|
661 harness.check (((new BigDecimal("1E90")).toString()).equals("1E+90"), "cst052"); |
|
662 } catch (Exception ecst052) { |
|
663 harness.check (false, "cst052"); |
|
664 } |
|
665 try { |
|
666 harness.check (((new BigDecimal("1E009")).toString()).equals("1E+9"), "cst053"); |
|
667 } catch (Exception ecst053) { |
|
668 harness.check (false, "cst053"); |
|
669 } |
|
670 try { |
|
671 harness.check (((new BigDecimal("0E9")).toString()).equals("0"), "cst054"); |
|
672 } catch (Exception ecst054) { |
|
673 harness.check (false, "cst054"); |
|
674 } |
|
675 try { |
|
676 harness.check (((new BigDecimal("0.000e+0")).toString()).equals("0"), "cst055"); |
|
677 } catch (Exception ecst055) { |
|
678 harness.check (false, "cst055"); |
|
679 } |
|
680 try { |
|
681 harness.check (((new BigDecimal("0.000E-1")).toString()).equals("0"), "cst056"); |
|
682 } catch (Exception ecst056) { |
|
683 harness.check (false, "cst056"); |
|
684 } |
|
685 try { |
|
686 harness.check (((new BigDecimal("4E+9")).toString()).equals("4E+9"), "cst057"); |
|
687 } catch (Exception ecst057) { |
|
688 harness.check (false, "cst057"); |
|
689 } |
|
690 try { |
|
691 harness.check (((new BigDecimal("44E+9")).toString()).equals("4.4E+10"), "cst058"); |
|
692 } catch (Exception ecst058) { |
|
693 harness.check (false, "cst058"); |
|
694 } |
|
695 try { |
|
696 harness.check (((new BigDecimal("0.73e-7")).toString()).equals("7.3E-8"), "cst059"); |
|
697 } catch (Exception ecst059) { |
|
698 harness.check (false, "cst059"); |
|
699 } |
|
700 try { |
|
701 harness.check (((new BigDecimal("00E+9")).toString()).equals("0"), "cst060"); |
|
702 } catch (Exception ecst060) { |
|
703 harness.check (false, "cst060"); |
|
704 } |
|
705 try { |
|
706 harness.check (((new BigDecimal("00E-9")).toString()).equals("0"), "cst061"); |
|
707 } catch (Exception ecst061) { |
|
708 harness.check (false, "cst061"); |
|
709 } |
|
710 try { |
|
711 harness.check (((new BigDecimal("10E+9")).toString()).equals("1.0E+10"), "cst062"); |
|
712 } catch (Exception ecst062) { |
|
713 harness.check (false, "cst062"); |
|
714 } |
|
715 try { |
|
716 harness.check (((new BigDecimal("10E+09")).toString()).equals("1.0E+10"), "cst063"); |
|
717 } catch (Exception ecst063) { |
|
718 harness.check (false, "cst063"); |
|
719 } |
|
720 try { |
|
721 harness.check (((new BigDecimal("10e+90")).toString()).equals("1.0E+91"), "cst064"); |
|
722 } catch (Exception ecst064) { |
|
723 harness.check (false, "cst064"); |
|
724 } |
|
725 try { |
|
726 harness.check (((new BigDecimal("10E+009")).toString()).equals("1.0E+10"), "cst065"); |
|
727 } catch (Exception ecst065) { |
|
728 harness.check (false, "cst065"); |
|
729 } |
|
730 try { |
|
731 harness.check (((new BigDecimal("100e+9")).toString()).equals("1.00E+11"), "cst066"); |
|
732 } catch (Exception ecst066) { |
|
733 harness.check (false, "cst066"); |
|
734 } |
|
735 try { |
|
736 harness.check (((new BigDecimal("100e+09")).toString()).equals("1.00E+11"), "cst067"); |
|
737 } catch (Exception ecst067) { |
|
738 harness.check (false, "cst067"); |
|
739 } |
|
740 try { |
|
741 harness.check (((new BigDecimal("100E+90")).toString()).equals("1.00E+92"), "cst068"); |
|
742 } catch (Exception ecst068) { |
|
743 harness.check (false, "cst068"); |
|
744 } |
|
745 try { |
|
746 harness.check (((new BigDecimal("100e+009")).toString()).equals("1.00E+11"), "cst069"); |
|
747 } catch (Exception ecst069) { |
|
748 harness.check (false, "cst069"); |
|
749 } |
|
750 |
|
751 try { |
|
752 harness.check (((new BigDecimal("1.265")).toString()).equals("1.265"), "cst070"); |
|
753 } catch (Exception ecst070) { |
|
754 harness.check (false, "cst070"); |
|
755 } |
|
756 try { |
|
757 harness.check (((new BigDecimal("1.265E-20")).toString()).equals("1.265E-20"), "cst071"); |
|
758 } catch (Exception ecst071) { |
|
759 harness.check (false, "cst071"); |
|
760 } |
|
761 try { |
|
762 harness.check (((new BigDecimal("1.265E-8")).toString()).equals("1.265E-8"), "cst072"); |
|
763 } catch (Exception ecst072) { |
|
764 harness.check (false, "cst072"); |
|
765 } |
|
766 try { |
|
767 harness.check (((new BigDecimal("1.265E-4")).toString()).equals("1.265E-4"), "cst073"); |
|
768 } catch (Exception ecst073) { |
|
769 harness.check (false, "cst073"); |
|
770 } |
|
771 try { |
|
772 harness.check (((new BigDecimal("1.265E-3")).toString()).equals("1.265E-3"), "cst074"); |
|
773 } catch (Exception ecst074) { |
|
774 harness.check (false, "cst074"); |
|
775 } |
|
776 try { |
|
777 harness.check (((new BigDecimal("1.265E-2")).toString()).equals("1.265E-2"), "cst075"); |
|
778 } catch (Exception ecst075) { |
|
779 harness.check (false, "cst075"); |
|
780 } |
|
781 try { |
|
782 harness.check (((new BigDecimal("1.265E-1")).toString()).equals("1.265E-1"), "cst076"); |
|
783 } catch (Exception ecst076) { |
|
784 harness.check (false, "cst076"); |
|
785 } |
|
786 try { |
|
787 harness.check (((new BigDecimal("1.265E-0")).toString()).equals("1.265"), "cst077"); |
|
788 } catch (Exception ecst077) { |
|
789 harness.check (false, "cst077"); |
|
790 } |
|
791 try { |
|
792 harness.check (((new BigDecimal("1.265E+1")).toString()).equals("1.265E+1"), "cst078"); |
|
793 } catch (Exception ecst078) { |
|
794 harness.check (false, "cst078"); |
|
795 } |
|
796 try { |
|
797 harness.check (((new BigDecimal("1.265E+2")).toString()).equals("1.265E+2"), "cst079"); |
|
798 } catch (Exception ecst079) { |
|
799 harness.check (false, "cst079"); |
|
800 } |
|
801 try { |
|
802 harness.check (((new BigDecimal("1.265E+3")).toString()).equals("1.265E+3"), "cst080"); |
|
803 } catch (Exception ecst080) { |
|
804 harness.check (false, "cst080"); |
|
805 } |
|
806 try { |
|
807 harness.check (((new BigDecimal("1.265E+4")).toString()).equals("1.265E+4"), "cst081"); |
|
808 } catch (Exception ecst081) { |
|
809 harness.check (false, "cst081"); |
|
810 } |
|
811 try { |
|
812 harness.check (((new BigDecimal("1.265E+8")).toString()).equals("1.265E+8"), "cst082"); |
|
813 } catch (Exception ecst082) { |
|
814 harness.check (false, "cst082"); |
|
815 } |
|
816 try { |
|
817 harness.check (((new BigDecimal("1.265E+20")).toString()).equals("1.265E+20"), "cst083"); |
|
818 } catch (Exception ecst083) { |
|
819 harness.check (false, "cst083"); |
|
820 } |
|
821 |
|
822 try { |
|
823 harness.check (((new BigDecimal("12.65")).toString()).equals("12.65"), "cst090"); |
|
824 } catch (Exception ecst090) { |
|
825 harness.check (false, "cst090"); |
|
826 } |
|
827 try { |
|
828 harness.check (((new BigDecimal("12.65E-20")).toString()).equals("1.265E-19"), "cst091"); |
|
829 } catch (Exception ecst091) { |
|
830 harness.check (false, "cst091"); |
|
831 } |
|
832 try { |
|
833 harness.check (((new BigDecimal("12.65E-8")).toString()).equals("1.265E-7"), "cst092"); |
|
834 } catch (Exception ecst092) { |
|
835 harness.check (false, "cst092"); |
|
836 } |
|
837 try { |
|
838 harness.check (((new BigDecimal("12.65E-4")).toString()).equals("1.265E-3"), "cst093"); |
|
839 } catch (Exception ecst093) { |
|
840 harness.check (false, "cst093"); |
|
841 } |
|
842 try { |
|
843 harness.check (((new BigDecimal("12.65E-3")).toString()).equals("1.265E-2"), "cst094"); |
|
844 } catch (Exception ecst094) { |
|
845 harness.check (false, "cst094"); |
|
846 } |
|
847 try { |
|
848 harness.check (((new BigDecimal("12.65E-2")).toString()).equals("1.265E-1"), "cst095"); |
|
849 } catch (Exception ecst095) { |
|
850 harness.check (false, "cst095"); |
|
851 } |
|
852 try { |
|
853 harness.check (((new BigDecimal("12.65E-1")).toString()).equals("1.265"), "cst096"); |
|
854 } catch (Exception ecst096) { |
|
855 harness.check (false, "cst096"); |
|
856 } |
|
857 try { |
|
858 harness.check (((new BigDecimal("12.65E-0")).toString()).equals("1.265E+1"), "cst097"); |
|
859 } catch (Exception ecst097) { |
|
860 harness.check (false, "cst097"); |
|
861 } |
|
862 try { |
|
863 harness.check (((new BigDecimal("12.65E+1")).toString()).equals("1.265E+2"), "cst098"); |
|
864 } catch (Exception ecst098) { |
|
865 harness.check (false, "cst098"); |
|
866 } |
|
867 try { |
|
868 harness.check (((new BigDecimal("12.65E+2")).toString()).equals("1.265E+3"), "cst099"); |
|
869 } catch (Exception ecst099) { |
|
870 harness.check (false, "cst099"); |
|
871 } |
|
872 try { |
|
873 harness.check (((new BigDecimal("12.65E+3")).toString()).equals("1.265E+4"), "cst100"); |
|
874 } catch (Exception ecst100) { |
|
875 harness.check (false, "cst100"); |
|
876 } |
|
877 try { |
|
878 harness.check (((new BigDecimal("12.65E+4")).toString()).equals("1.265E+5"), "cst101"); |
|
879 } catch (Exception ecst101) { |
|
880 harness.check (false, "cst101"); |
|
881 } |
|
882 try { |
|
883 harness.check (((new BigDecimal("12.65E+8")).toString()).equals("1.265E+9"), "cst102"); |
|
884 } catch (Exception ecst102) { |
|
885 harness.check (false, "cst102"); |
|
886 } |
|
887 try { |
|
888 harness.check (((new BigDecimal("12.65E+20")).toString()).equals("1.265E+21"), "cst103"); |
|
889 } catch (Exception ecst103) { |
|
890 harness.check (false, "cst103"); |
|
891 } |
|
892 |
|
893 try { |
|
894 harness.check (((new BigDecimal("126.5")).toString()).equals("126.5"), "cst110"); |
|
895 } catch (Exception ecst110) { |
|
896 harness.check (false, "cst110"); |
|
897 } |
|
898 try { |
|
899 harness.check (((new BigDecimal("126.5E-20")).toString()).equals("1.265E-18"), "cst111"); |
|
900 } catch (Exception ecst111) { |
|
901 harness.check (false, "cst111"); |
|
902 } |
|
903 try { |
|
904 harness.check (((new BigDecimal("126.5E-8")).toString()).equals("1.265E-6"), "cst112"); |
|
905 } catch (Exception ecst112) { |
|
906 harness.check (false, "cst112"); |
|
907 } |
|
908 try { |
|
909 harness.check (((new BigDecimal("126.5E-4")).toString()).equals("1.265E-2"), "cst113"); |
|
910 } catch (Exception ecst113) { |
|
911 harness.check (false, "cst113"); |
|
912 } |
|
913 try { |
|
914 harness.check (((new BigDecimal("126.5E-3")).toString()).equals("1.265E-1"), "cst114"); |
|
915 } catch (Exception ecst114) { |
|
916 harness.check (false, "cst114"); |
|
917 } |
|
918 try { |
|
919 harness.check (((new BigDecimal("126.5E-2")).toString()).equals("1.265"), "cst115"); |
|
920 } catch (Exception ecst115) { |
|
921 harness.check (false, "cst115"); |
|
922 } |
|
923 try { |
|
924 harness.check (((new BigDecimal("126.5E-1")).toString()).equals("1.265E+1"), "cst116"); |
|
925 } catch (Exception ecst116) { |
|
926 harness.check (false, "cst116"); |
|
927 } |
|
928 try { |
|
929 harness.check (((new BigDecimal("126.5E-0")).toString()).equals("1.265E+2"), "cst117"); |
|
930 } catch (Exception ecst117) { |
|
931 harness.check (false, "cst117"); |
|
932 } |
|
933 try { |
|
934 harness.check (((new BigDecimal("126.5E+1")).toString()).equals("1.265E+3"), "cst118"); |
|
935 } catch (Exception ecst118) { |
|
936 harness.check (false, "cst118"); |
|
937 } |
|
938 try { |
|
939 harness.check (((new BigDecimal("126.5E+2")).toString()).equals("1.265E+4"), "cst119"); |
|
940 } catch (Exception ecst119) { |
|
941 harness.check (false, "cst119"); |
|
942 } |
|
943 try { |
|
944 harness.check (((new BigDecimal("126.5E+3")).toString()).equals("1.265E+5"), "cst120"); |
|
945 } catch (Exception ecst120) { |
|
946 harness.check (false, "cst120"); |
|
947 } |
|
948 try { |
|
949 harness.check (((new BigDecimal("126.5E+4")).toString()).equals("1.265E+6"), "cst121"); |
|
950 } catch (Exception ecst121) { |
|
951 harness.check (false, "cst121"); |
|
952 } |
|
953 try { |
|
954 harness.check (((new BigDecimal("126.5E+8")).toString()).equals("1.265E+10"), "cst122"); |
|
955 } catch (Exception ecst122) { |
|
956 harness.check (false, "cst122"); |
|
957 } |
|
958 try { |
|
959 harness.check (((new BigDecimal("126.5E+20")).toString()).equals("1.265E+22"), "cst123"); |
|
960 } catch (Exception ecst123) { |
|
961 harness.check (false, "cst123"); |
|
962 } |
|
963 |
|
964 try { |
|
965 harness.check (((new BigDecimal("1265")).toString()).equals("1265"), "cst130"); |
|
966 } catch (Exception ecst130) { |
|
967 harness.check (false, "cst130"); |
|
968 } |
|
969 try { |
|
970 harness.check (((new BigDecimal("1265E-20")).toString()).equals("1.265E-17"), "cst131"); |
|
971 } catch (Exception ecst131) { |
|
972 harness.check (false, "cst131"); |
|
973 } |
|
974 try { |
|
975 harness.check (((new BigDecimal("1265E-8")).toString()).equals("1.265E-5"), "cst132"); |
|
976 } catch (Exception ecst132) { |
|
977 harness.check (false, "cst132"); |
|
978 } |
|
979 try { |
|
980 harness.check (((new BigDecimal("1265E-4")).toString()).equals("1.265E-1"), "cst133"); |
|
981 } catch (Exception ecst133) { |
|
982 harness.check (false, "cst133"); |
|
983 } |
|
984 try { |
|
985 harness.check (((new BigDecimal("1265E-3")).toString()).equals("1.265"), "cst134"); |
|
986 } catch (Exception ecst134) { |
|
987 harness.check (false, "cst134"); |
|
988 } |
|
989 try { |
|
990 harness.check (((new BigDecimal("1265E-2")).toString()).equals("1.265E+1"), "cst135"); |
|
991 } catch (Exception ecst135) { |
|
992 harness.check (false, "cst135"); |
|
993 } |
|
994 try { |
|
995 harness.check (((new BigDecimal("1265E-1")).toString()).equals("1.265E+2"), "cst136"); |
|
996 } catch (Exception ecst136) { |
|
997 harness.check (false, "cst136"); |
|
998 } |
|
999 try { |
|
1000 harness.check (((new BigDecimal("1265E-0")).toString()).equals("1.265E+3"), "cst137"); |
|
1001 } catch (Exception ecst137) { |
|
1002 harness.check (false, "cst137"); |
|
1003 } |
|
1004 try { |
|
1005 harness.check (((new BigDecimal("1265E+1")).toString()).equals("1.265E+4"), "cst138"); |
|
1006 } catch (Exception ecst138) { |
|
1007 harness.check (false, "cst138"); |
|
1008 } |
|
1009 try { |
|
1010 harness.check (((new BigDecimal("1265E+2")).toString()).equals("1.265E+5"), "cst139"); |
|
1011 } catch (Exception ecst139) { |
|
1012 harness.check (false, "cst139"); |
|
1013 } |
|
1014 try { |
|
1015 harness.check (((new BigDecimal("1265E+3")).toString()).equals("1.265E+6"), "cst140"); |
|
1016 } catch (Exception ecst140) { |
|
1017 harness.check (false, "cst140"); |
|
1018 } |
|
1019 try { |
|
1020 harness.check (((new BigDecimal("1265E+4")).toString()).equals("1.265E+7"), "cst141"); |
|
1021 } catch (Exception ecst141) { |
|
1022 harness.check (false, "cst141"); |
|
1023 } |
|
1024 try { |
|
1025 harness.check (((new BigDecimal("1265E+8")).toString()).equals("1.265E+11"), "cst142"); |
|
1026 } catch (Exception ecst142) { |
|
1027 harness.check (false, "cst142"); |
|
1028 } |
|
1029 try { |
|
1030 harness.check (((new BigDecimal("1265E+20")).toString()).equals("1.265E+23"), "cst143"); |
|
1031 } catch (Exception ecst143) { |
|
1032 harness.check (false, "cst143"); |
|
1033 } |
|
1034 try { |
|
1035 harness.check (((new BigDecimal("0.1265")).toString()).equals("0.1265"), "cst150"); |
|
1036 } catch (Exception ecst150) { |
|
1037 harness.check (false, "cst150"); |
|
1038 } |
|
1039 try { |
|
1040 harness.check (((new BigDecimal("0.1265E-20")).toString()).equals("1.265E-21"), "cst151"); |
|
1041 } catch (Exception ecst151) { |
|
1042 harness.check (false, "cst151"); |
|
1043 } |
|
1044 try { |
|
1045 harness.check (((new BigDecimal("0.1265E-8")).toString()).equals("1.265E-9"), "cst152"); |
|
1046 } catch (Exception ecst152) { |
|
1047 harness.check (false, "cst152"); |
|
1048 } |
|
1049 try { |
|
1050 harness.check (((new BigDecimal("0.1265E-4")).toString()).equals("1.265E-5"), "cst153"); |
|
1051 } catch (Exception ecst153) { |
|
1052 harness.check (false, "cst153"); |
|
1053 } |
|
1054 try { |
|
1055 harness.check (((new BigDecimal("0.1265E-3")).toString()).equals("1.265E-4"), "cst154"); |
|
1056 } catch (Exception ecst154) { |
|
1057 harness.check (false, "cst154"); |
|
1058 } |
|
1059 try { |
|
1060 harness.check (((new BigDecimal("0.1265E-2")).toString()).equals("1.265E-3"), "cst155"); |
|
1061 } catch (Exception ecst155) { |
|
1062 harness.check (false, "cst155"); |
|
1063 } |
|
1064 try { |
|
1065 harness.check (((new BigDecimal("0.1265E-1")).toString()).equals("1.265E-2"), "cst156"); |
|
1066 } catch (Exception ecst156) { |
|
1067 harness.check (false, "cst156"); |
|
1068 } |
|
1069 try { |
|
1070 harness.check (((new BigDecimal("0.1265E-0")).toString()).equals("1.265E-1"), "cst157"); |
|
1071 } catch (Exception ecst157) { |
|
1072 harness.check (false, "cst157"); |
|
1073 } |
|
1074 try { |
|
1075 harness.check (((new BigDecimal("0.1265E+1")).toString()).equals("1.265"), "cst158"); |
|
1076 } catch (Exception ecst158) { |
|
1077 harness.check (false, "cst158"); |
|
1078 } |
|
1079 try { |
|
1080 harness.check (((new BigDecimal("0.1265E+2")).toString()).equals("1.265E+1"), "cst159"); |
|
1081 } catch (Exception ecst159) { |
|
1082 harness.check (false, "cst159"); |
|
1083 } |
|
1084 try { |
|
1085 harness.check (((new BigDecimal("0.1265E+3")).toString()).equals("1.265E+2"), "cst160"); |
|
1086 } catch (Exception ecst160) { |
|
1087 harness.check (false, "cst160"); |
|
1088 } |
|
1089 try { |
|
1090 harness.check (((new BigDecimal("0.1265E+4")).toString()).equals("1.265E+3"), "cst161"); |
|
1091 } catch (Exception ecst161) { |
|
1092 harness.check (false, "cst161"); |
|
1093 } |
|
1094 try { |
|
1095 harness.check (((new BigDecimal("0.1265E+8")).toString()).equals("1.265E+7"), "cst162"); |
|
1096 } catch (Exception ecst162) { |
|
1097 harness.check (false, "cst162"); |
|
1098 } |
|
1099 try { |
|
1100 harness.check (((new BigDecimal("0.1265E+20")).toString()).equals("1.265E+19"), "cst163"); |
|
1101 } catch (Exception ecst163) { |
|
1102 harness.check (false, "cst163"); |
|
1103 } |
|
1104 try { |
|
1105 harness.check (((new BigDecimal("0.09e999999999")).toString()).equals("9E+999999997"), "cst170"); |
|
1106 } catch (Exception ecst170) { |
|
1107 harness.check (false, "cst170"); |
|
1108 } |
|
1109 try { |
|
1110 harness.check (((new BigDecimal("0.9e999999999")).toString()).equals("9E+999999998"), "cst171"); |
|
1111 } catch (Exception ecst171) { |
|
1112 harness.check (false, "cst171"); |
|
1113 } |
|
1114 try { |
|
1115 harness.check (((new BigDecimal("9e999999999")).toString()).equals("9E+999999999"), "cst172"); |
|
1116 } catch (Exception ecst172) { |
|
1117 harness.check (false, "cst172"); |
|
1118 } |
|
1119 try { |
|
1120 harness.check (((new BigDecimal("9.9e999999999")).toString()).equals("9.9E+999999999"), "cst173"); |
|
1121 } catch (Exception ecst173) { |
|
1122 harness.check (false, "cst173"); |
|
1123 } |
|
1124 try { |
|
1125 harness.check (((new BigDecimal("9.99e999999999")).toString()).equals("9.99E+999999999"), "cst174"); |
|
1126 } catch (Exception ecst174) { |
|
1127 harness.check (false, "cst174"); |
|
1128 } |
|
1129 try { |
|
1130 harness.check (((new BigDecimal("9.99e-999999999")).toString()).equals("9.99E-999999999"), "cst175"); |
|
1131 } catch (Exception ecst175) { |
|
1132 harness.check (false, "cst175"); |
|
1133 } |
|
1134 try { |
|
1135 harness.check (((new BigDecimal("9.9e-999999999")).toString()).equals("9.9E-999999999"), "cst176"); |
|
1136 } catch (Exception ecst176) { |
|
1137 harness.check (false, "cst176"); |
|
1138 } |
|
1139 try { |
|
1140 harness.check (((new BigDecimal("9e-999999999")).toString()).equals("9E-999999999"), "cst177"); |
|
1141 } catch (Exception ecst177) { |
|
1142 harness.check (false, "cst177"); |
|
1143 } |
|
1144 try { |
|
1145 harness.check (((new BigDecimal("99e-999999999")).toString()).equals("9.9E-999999998"), "cst179"); |
|
1146 } catch (Exception ecst179) { |
|
1147 harness.check (false, "cst179"); |
|
1148 } |
|
1149 try { |
|
1150 harness.check (((new BigDecimal("999e-999999999")).toString()).equals("9.99E-999999997"), "cst180"); |
|
1151 } catch (Exception ecst180) { |
|
1152 harness.check (false, "cst180"); |
|
1153 } |
|
1154 |
|
1155 // baddies -- |
|
1156 badstrings=new java.lang.String[]{"1..2",".","..","++1","--1","-+1","+-1","12e","12e++","12f4"," +1","+ 1","12 "," + 1"," - 1 ","x","-1-","12-","3+","","1e-","7e1000000000","","e100","\u0e5a","\u0b65","99e999999999","999e999999999","0.9e-999999999","0.09e-999999999","0.1e1000000000","10e-1000000000","0.9e9999999999","99e-9999999999","111e9999999999","1111e-9999999999"+" "+"111e*123","111e123-","111e+12+","111e1-3-","111e1*23","111e1e+3","1e1.0","1e123e","ten","ONE","1e.1","1e1.","1ee","e+1"}; // 200-203 |
|
1157 // 204-207 |
|
1158 // 208-211 |
|
1159 // 211-214 |
|
1160 // 215-219 |
|
1161 // 220-222 |
|
1162 // 223-224 |
|
1163 // 225-226 |
|
1164 // 227-228 |
|
1165 // 229-230 |
|
1166 // 231-232 |
|
1167 // 233-234 |
|
1168 // 235-237 |
|
1169 // 238-240 |
|
1170 // 241-244 |
|
1171 // 245-248 |
|
1172 |
|
1173 // watch out for commas on continuation lines |
|
1174 |
|
1175 {int xx16=badstrings.length;i=0;i:for(;xx16>0;xx16--,i++){ |
|
1176 try{ |
|
1177 new BigDecimal(badstrings[i]); |
|
1178 say(">>> cst"+(200+i)+":"+" "+badstrings[i]+" "+(new BigDecimal(badstrings[i])).toString(), harness); |
|
1179 flag=false; |
|
1180 } |
|
1181 catch (java.lang.NumberFormatException xx17){ |
|
1182 flag=true; |
|
1183 } |
|
1184 harness.check (flag, "cst"+(200+i)); |
|
1185 } |
|
1186 }/*i*/ |
|
1187 |
|
1188 try{checknull:do{ |
|
1189 new BigDecimal((java.lang.String)null); |
|
1190 flag=false; |
|
1191 }while(false);} |
|
1192 catch (java.lang.NullPointerException xx18){ |
|
1193 flag=true; |
|
1194 }/*checknull*/ |
|
1195 harness.check (flag, "cst301"); |
|
1196 |
|
1197 return; |
|
1198 } |
|
1199 |
|
1200 /** Mutation tests (checks that contents of constant objects are unchanged). */ |
|
1201 |
|
1202 public void diagmutation(TestHarness harness){ |
|
1203 /* ---------------------------------------------------------------- */ |
|
1204 /* Final tests -- check constants haven't mutated */ |
|
1205 /* -- also that MC objects haven't mutated */ |
|
1206 /* ---------------------------------------------------------------- */ |
|
1207 harness.check ((zero.toString()).equals("0"), "cuc001"); |
|
1208 harness.check ((one.toString()).equals("1"), "cuc002"); |
|
1209 harness.check ((ten.toString()).equals("10"), "cuc003"); |
|
1210 |
|
1211 return;} |
|
1212 |
|
1213 |
|
1214 /* ----------------------------------------------------------------- */ |
|
1215 /* Operator test methods */ |
|
1216 /* ----------------------------------------------------------------- */ |
|
1217 // The use of context in these tests are primarily to show that they |
|
1218 // are correctly passed to the methods, except that we check that |
|
1219 // each method checks for lostDigits. |
|
1220 |
|
1221 /** Test the {@link BigDecimal#abs} method. */ |
|
1222 |
|
1223 public void diagabs(TestHarness harness){ |
|
1224 boolean flag=false; |
|
1225 java.lang.ArithmeticException ae=null; |
|
1226 |
|
1227 // most of the function of this is tested by add |
|
1228 harness.check (((new BigDecimal("2")).abs().toString()).equals("2"), "abs001"); |
|
1229 harness.check (((new BigDecimal("-2")).abs().toString()).equals("2"), "abs002"); |
|
1230 harness.check (((new BigDecimal("+0.000")).abs().toString()).equals("0.000"), "abs003"); |
|
1231 harness.check (((new BigDecimal("00.000")).abs().toString()).equals("0.000"), "abs004"); |
|
1232 harness.check (((new BigDecimal("-0.000")).abs().toString()).equals("0.000"), "abs005"); |
|
1233 harness.check (((new BigDecimal("-2000000")).abs().toString()).equals("2000000"), "abs009"); |
|
1234 harness.check (((new BigDecimal("0.2")).abs().toString()).equals("0.2"), "abs013"); |
|
1235 harness.check (((new BigDecimal("-0.2")).abs().toString()).equals("0.2"), "abs014"); |
|
1236 harness.check (((new BigDecimal("0.01")).abs().toString()).equals("0.01"), "abs015"); |
|
1237 harness.check (((new BigDecimal("-0.01")).abs().toString()).equals("0.01"), "abs016"); |
|
1238 |
|
1239 return;} |
|
1240 /* ----------------------------------------------------------------- */ |
|
1241 |
|
1242 /** Test the {@link BigDecimal#add} method. */ |
|
1243 |
|
1244 public void diagadd(TestHarness harness){ |
|
1245 boolean flag=false; |
|
1246 BigDecimal alhs; |
|
1247 BigDecimal arhs; |
|
1248 java.lang.ArithmeticException ae=null; |
|
1249 |
|
1250 // [Now the same group with fixed arithmetic] |
|
1251 harness.check (((new BigDecimal(2)).add(new BigDecimal(3)).toString()).equals("5"), "add030"); |
|
1252 harness.check (((new BigDecimal("5.75")).add(new BigDecimal("3.3")).toString()).equals("9.05"), "add031"); |
|
1253 harness.check (((new BigDecimal("5")).add(new BigDecimal("-3")).toString()).equals("2"), "add032"); |
|
1254 harness.check (((new BigDecimal("-5")).add(new BigDecimal("-3")).toString()).equals("-8"), "add033"); |
|
1255 harness.check (((new BigDecimal("-7")).add(new BigDecimal("2.5")).toString()).equals("-4.5"), "add034"); |
|
1256 harness.check (((new BigDecimal("0.7")).add(new BigDecimal("0.3")).toString()).equals("1.0"), "add035"); |
|
1257 harness.check (((new BigDecimal("1.25")).add(new BigDecimal("1.25")).toString()).equals("2.50"), "add036"); |
|
1258 harness.check (((new BigDecimal("1.23456789")).add(new BigDecimal("1.00000000")).toString()).equals("2.23456789"), "add037"); |
|
1259 |
|
1260 harness.check (((new BigDecimal("1.23456789")).add(new BigDecimal("1.00000011")).toString()).equals("2.23456800"), "add038"); |
|
1261 |
|
1262 |
|
1263 harness.check (((new BigDecimal("0.4444444444")).add(new BigDecimal("0.5555555555")).toString()).equals("0.9999999999"), "add039"); |
|
1264 |
|
1265 harness.check (((new BigDecimal("0.4444444440")).add(new BigDecimal("0.5555555555")).toString()).equals("0.9999999995"), "add040"); |
|
1266 |
|
1267 harness.check (((new BigDecimal("0.4444444444")).add(new BigDecimal("0.5555555550")).toString()).equals("0.9999999994"), "add041"); |
|
1268 |
|
1269 harness.check (((new BigDecimal("0.4444444444999")).add(new BigDecimal("0")).toString()).equals("0.4444444444999"), "add042"); |
|
1270 |
|
1271 harness.check (((new BigDecimal("0.4444444445000")).add(new BigDecimal("0")).toString()).equals("0.4444444445000"), "add043"); |
|
1272 |
|
1273 |
|
1274 harness.check (((new BigDecimal("70")).add(new BigDecimal("10000e+9")).toString()).equals("10000000000070"), "add044"); |
|
1275 |
|
1276 harness.check (((new BigDecimal("700")).add(new BigDecimal("10000e+9")).toString()).equals("10000000000700"), "add045"); |
|
1277 |
|
1278 harness.check (((new BigDecimal("7000")).add(new BigDecimal("10000e+9")).toString()).equals("10000000007000"), "add046"); |
|
1279 |
|
1280 harness.check (((new BigDecimal("70000")).add(new BigDecimal("10000e+9")).toString()).equals("10000000070000"), "add047"); |
|
1281 |
|
1282 harness.check (((new BigDecimal("700000")).add(new BigDecimal("10000e+9")).toString()).equals("10000000700000"), "add048"); |
|
1283 |
|
1284 harness.check (((new BigDecimal("10000e+9")).add(new BigDecimal("70")).toString()).equals("10000000000070"), "add054"); |
|
1285 |
|
1286 harness.check (((new BigDecimal("10000e+9")).add(new BigDecimal("700")).toString()).equals("10000000000700"), "add055"); |
|
1287 |
|
1288 harness.check (((new BigDecimal("10000e+9")).add(new BigDecimal("7000")).toString()).equals("10000000007000"), "add056"); |
|
1289 |
|
1290 harness.check (((new BigDecimal("10000e+9")).add(new BigDecimal("70000")).toString()).equals("10000000070000"), "add057"); |
|
1291 |
|
1292 harness.check (((new BigDecimal("10000e+9")).add(new BigDecimal("700000")).toString()).equals("10000000700000"), "add058"); |
|
1293 |
|
1294 // some rounding effects |
|
1295 harness.check (((new BigDecimal("0.9998")).add(new BigDecimal("0.0000")).toString()).equals("0.9998"), "add059"); |
|
1296 |
|
1297 harness.check (((new BigDecimal("0.9998")).add(new BigDecimal("0.0001")).toString()).equals("0.9999"), "add060"); |
|
1298 |
|
1299 harness.check (((new BigDecimal("0.9998")).add(new BigDecimal("0.0002")).toString()).equals("1.0000"), "add061"); |
|
1300 |
|
1301 harness.check (((new BigDecimal("0.9998")).add(new BigDecimal("0.0003")).toString()).equals("1.0001"), "add062"); |
|
1302 |
|
1303 // more fixed, LHS swaps |
|
1304 harness.check (((new BigDecimal("-56267E-10")).add(zero).toString()).equals("-0.0000056267"), "add090"); |
|
1305 harness.check (((new BigDecimal("-56267E-6")).add(zero).toString()).equals("-0.056267"), "add091"); |
|
1306 harness.check (((new BigDecimal("-56267E-5")).add(zero).toString()).equals("-0.56267"), "add092"); |
|
1307 harness.check (((new BigDecimal("-56267E-4")).add(zero).toString()).equals("-5.6267"), "add093"); |
|
1308 harness.check (((new BigDecimal("-56267E-3")).add(zero).toString()).equals("-56.267"), "add094"); |
|
1309 harness.check (((new BigDecimal("-56267E-2")).add(zero).toString()).equals("-562.67"), "add095"); |
|
1310 harness.check (((new BigDecimal("-56267E-1")).add(zero).toString()).equals("-5626.7"), "add096"); |
|
1311 harness.check (((new BigDecimal("-56267E-0")).add(zero).toString()).equals("-56267"), "add097"); |
|
1312 harness.check (((new BigDecimal("-5E-10")).add(zero).toString()).equals("-5E-10"), "add098"); |
|
1313 harness.check (((new BigDecimal("-5E-5")).add(zero).toString()).equals("-0.00005"), "add099"); |
|
1314 harness.check (((new BigDecimal("-5E-1")).add(zero).toString()).equals("-0.5"), "add100"); |
|
1315 harness.check (((new BigDecimal("-5E-10")).add(zero).toString()).equals("-5E-10"), "add101"); |
|
1316 harness.check (((new BigDecimal("-5E-5")).add(zero).toString()).equals("-0.00005"), "add102"); |
|
1317 harness.check (((new BigDecimal("-5E-1")).add(zero).toString()).equals("-0.5"), "add103"); |
|
1318 harness.check (((new BigDecimal("-5E10")).add(zero).toString()).equals("-50000000000"), "add104"); |
|
1319 harness.check (((new BigDecimal("-5E5")).add(zero).toString()).equals("-500000"), "add105"); |
|
1320 harness.check (((new BigDecimal("-5E1")).add(zero).toString()).equals("-50"), "add106"); |
|
1321 harness.check (((new BigDecimal("-5E0")).add(zero).toString()).equals("-5"), "add107"); |
|
1322 |
|
1323 // more fixed, RHS swaps |
|
1324 harness.check ((zero.add(new BigDecimal("-56267E-10")).toString()).equals("-0.0000056267"), "add108"); |
|
1325 harness.check ((zero.add(new BigDecimal("-56267E-6")).toString()).equals("-0.056267"), "add109"); |
|
1326 harness.check ((zero.add(new BigDecimal("-56267E-5")).toString()).equals("-0.56267"), "add110"); |
|
1327 harness.check ((zero.add(new BigDecimal("-56267E-4")).toString()).equals("-5.6267"), "add111"); |
|
1328 harness.check ((zero.add(new BigDecimal("-56267E-3")).toString()).equals("-56.267"), "add112"); |
|
1329 harness.check ((zero.add(new BigDecimal("-56267E-2")).toString()).equals("-562.67"), "add113"); |
|
1330 harness.check ((zero.add(new BigDecimal("-56267E-1")).toString()).equals("-5626.7"), "add114"); |
|
1331 harness.check ((zero.add(new BigDecimal("-56267E-0")).toString()).equals("-56267"), "add115"); |
|
1332 harness.check ((zero.add(new BigDecimal("-5E-10")).toString()).equals("-5E-10"), "add116"); |
|
1333 harness.check ((zero.add(new BigDecimal("-5E-5")).toString()).equals("-0.00005"), "add117"); |
|
1334 harness.check ((zero.add(new BigDecimal("-5E-1")).toString()).equals("-0.5"), "add118"); |
|
1335 harness.check ((zero.add(new BigDecimal("-5E-10")).toString()).equals("-5E-10"), "add129"); |
|
1336 harness.check ((zero.add(new BigDecimal("-5E-5")).toString()).equals("-0.00005"), "add130"); |
|
1337 harness.check ((zero.add(new BigDecimal("-5E-1")).toString()).equals("-0.5"), "add131"); |
|
1338 harness.check ((zero.add(new BigDecimal("-5E10")).toString()).equals("-50000000000"), "add132"); |
|
1339 harness.check ((zero.add(new BigDecimal("-5E5")).toString()).equals("-500000"), "add133"); |
|
1340 harness.check ((zero.add(new BigDecimal("-5E1")).toString()).equals("-50"), "add134"); |
|
1341 harness.check ((zero.add(new BigDecimal("-5E0")).toString()).equals("-5"), "add135"); |
|
1342 |
|
1343 harness.check (((new BigDecimal("00.0")).add(new BigDecimal("0.00")).toString()).equals("0.00"), "add150"); |
|
1344 harness.check (((new BigDecimal("0.00")).add(new BigDecimal("00.0")).toString()).equals("0.00"), "add151"); |
|
1345 harness.check (((new BigDecimal("3")).add(new BigDecimal(".3")).toString()).equals("3.3"), "add152"); |
|
1346 harness.check (((new BigDecimal("3.")).add(new BigDecimal(".3")).toString()).equals("3.3"), "add153"); |
|
1347 harness.check (((new BigDecimal("3.0")).add(new BigDecimal(".3")).toString()).equals("3.3"), "add154"); |
|
1348 harness.check (((new BigDecimal("3.00")).add(new BigDecimal(".3")).toString()).equals("3.30"), "add155"); |
|
1349 harness.check (((new BigDecimal("3")).add(new BigDecimal("3")).toString()).equals("6"), "add156"); |
|
1350 harness.check (((new BigDecimal("3")).add(new BigDecimal("+3")).toString()).equals("6"), "add157"); |
|
1351 harness.check (((new BigDecimal("3")).add(new BigDecimal("-3")).toString()).equals("0"), "add158"); |
|
1352 harness.check (((new BigDecimal("0.3")).add(new BigDecimal("-0.3")).toString()).equals("0.0"), "add159"); |
|
1353 harness.check (((new BigDecimal("0.03")).add(new BigDecimal("-0.03")).toString()).equals("0.00"), "add160"); |
|
1354 |
|
1355 // input preparation tests |
|
1356 alhs=new BigDecimal("12345678900000"); |
|
1357 arhs=new BigDecimal("9999999999999"); |
|
1358 |
|
1359 try{checknull:do{ |
|
1360 ten.add((BigDecimal)null); |
|
1361 flag=false; |
|
1362 }while(false);} |
|
1363 catch (java.lang.NullPointerException xx22){ |
|
1364 flag=true; |
|
1365 }/*checknull*/ |
|
1366 harness.check (flag, "add200"); |
|
1367 |
|
1368 return;} |
|
1369 |
|
1370 /* ----------------------------------------------------------------- */ |
|
1371 /** Test the {@link BigDecimal#compareTo(BigDecimal)} method. */ |
|
1372 |
|
1373 public void diagcompareto(TestHarness harness){ |
|
1374 boolean flag=false; |
|
1375 java.lang.ArithmeticException ae=null; |
|
1376 // we assume add/subtract test function; this just |
|
1377 // tests existence, exceptions, and possible results |
|
1378 |
|
1379 harness.check (((new BigDecimal("5")).compareTo(new BigDecimal("2")))==1, "cpt001"); |
|
1380 harness.check (((new BigDecimal("5")).compareTo(new BigDecimal("5")))==0, "cpt002"); |
|
1381 harness.check (((new BigDecimal("5")).compareTo(new BigDecimal("5.00")))==0, "cpt003"); |
|
1382 harness.check (((new BigDecimal("0.5")).compareTo(new BigDecimal("0.5")))==0, "cpt004"); |
|
1383 harness.check (((new BigDecimal("2")).compareTo(new BigDecimal("5")))==(-1), "cpt005"); |
|
1384 try{checknull:do{ |
|
1385 ten.compareTo((BigDecimal)null); |
|
1386 flag=false; |
|
1387 }while(false);} |
|
1388 catch (java.lang.NullPointerException xx28){ |
|
1389 flag=true; |
|
1390 }/*checknull*/ |
|
1391 harness.check (flag, "cpt100"); |
|
1392 |
|
1393 return;} |
|
1394 |
|
1395 /* ----------------------------------------------------------------- */ |
|
1396 |
|
1397 /** Test the {@link BigDecimal#divide} method. */ |
|
1398 |
|
1399 public void diagdivide(TestHarness harness){ |
|
1400 boolean flag=false; |
|
1401 int rhu; |
|
1402 int rd; |
|
1403 int ru; |
|
1404 java.lang.RuntimeException e=null; |
|
1405 java.lang.ArithmeticException ae=null; |
|
1406 |
|
1407 // fixed point... |
|
1408 harness.check (((new BigDecimal("1")).divide(new BigDecimal("3"), BigDecimal.ROUND_HALF_UP).toString()).equals("0"), "div350"); |
|
1409 harness.check (((new BigDecimal("2")).divide(new BigDecimal("3"), BigDecimal.ROUND_HALF_UP).toString()).equals("1"), "div351"); |
|
1410 harness.check (((new BigDecimal("2.4")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("2.4"), "div352"); |
|
1411 harness.check (((new BigDecimal("2.4")).divide(new BigDecimal("-1"), BigDecimal.ROUND_HALF_UP).toString()).equals("-2.4"), "div353"); |
|
1412 harness.check (((new BigDecimal("-2.4")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("-2.4"), "div354"); |
|
1413 harness.check (((new BigDecimal("-2.4")).divide(new BigDecimal("-1"), BigDecimal.ROUND_HALF_UP).toString()).equals("2.4"), "div355"); |
|
1414 harness.check (((new BigDecimal("2.40")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("2.40"), "div356"); |
|
1415 harness.check (((new BigDecimal("2.400")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("2.400"), "div357"); |
|
1416 harness.check (((new BigDecimal("2.4")).divide(new BigDecimal("2"), BigDecimal.ROUND_HALF_UP).toString()).equals("1.2"), "div358"); |
|
1417 harness.check (((new BigDecimal("2.400")).divide(new BigDecimal("2"), BigDecimal.ROUND_HALF_UP).toString()).equals("1.200"), "div359"); |
|
1418 harness.check (((new BigDecimal("2.")).divide(new BigDecimal("2"), BigDecimal.ROUND_HALF_UP).toString()).equals("1"), "div360"); |
|
1419 harness.check (((new BigDecimal("20")).divide(new BigDecimal("20"), BigDecimal.ROUND_HALF_UP).toString()).equals("1"), "div361"); |
|
1420 harness.check (((new BigDecimal("187")).divide(new BigDecimal("187"), BigDecimal.ROUND_HALF_UP).toString()).equals("1"), "div362"); |
|
1421 harness.check (((new BigDecimal("5")).divide(new BigDecimal("2"), BigDecimal.ROUND_HALF_UP).toString()).equals("3"), "div363"); |
|
1422 harness.check (((new BigDecimal("5")).divide(new BigDecimal("2.0"), BigDecimal.ROUND_HALF_UP).toString()).equals("3"), "div364"); |
|
1423 harness.check (((new BigDecimal("5")).divide(new BigDecimal("2.000"), BigDecimal.ROUND_HALF_UP).toString()).equals("3"), "div365"); |
|
1424 harness.check (((new BigDecimal("5")).divide(new BigDecimal("0.200"), BigDecimal.ROUND_HALF_UP).toString()).equals("25"), "div366"); |
|
1425 harness.check (((new BigDecimal("5.0")).divide(new BigDecimal("2"), BigDecimal.ROUND_HALF_UP).toString()).equals("2.5"), "div367"); |
|
1426 harness.check (((new BigDecimal("5.0")).divide(new BigDecimal("2.0"), BigDecimal.ROUND_HALF_UP).toString()).equals("2.5"), "div368"); |
|
1427 harness.check (((new BigDecimal("5.0")).divide(new BigDecimal("2.000"), BigDecimal.ROUND_HALF_UP).toString()).equals("2.5"), "div369"); |
|
1428 harness.check (((new BigDecimal("5.0")).divide(new BigDecimal("0.200"), BigDecimal.ROUND_HALF_UP).toString()).equals("25.0"), "div370"); |
|
1429 harness.check (((new BigDecimal("999999999")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("999999999"), "div371"); |
|
1430 harness.check (((new BigDecimal("999999999.4")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("999999999.4"), "div372"); |
|
1431 harness.check (((new BigDecimal("999999999.5")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("999999999.5"), "div373"); |
|
1432 harness.check (((new BigDecimal("999999999.9")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("999999999.9"), "div374"); |
|
1433 harness.check (((new BigDecimal("999999999.999")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("999999999.999"), "div375"); |
|
1434 harness.check (((new BigDecimal("0.0000E-5")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("0E-9"), "div376"); |
|
1435 harness.check (((new BigDecimal("0.000000000")).divide(new BigDecimal("1"), BigDecimal.ROUND_HALF_UP).toString()).equals("0E-9"), "div377"); |
|
1436 |
|
1437 //- Fixed point; explicit scales & rounds [old BigDecimal divides] |
|
1438 harness.check (((new BigDecimal("0")).divide(new BigDecimal("3"), BigDecimal.ROUND_HALF_UP).toString()).equals("0"), "div001"); |
|
1439 harness.check (((new BigDecimal("1")).divide(new BigDecimal("3"), BigDecimal.ROUND_HALF_UP).toString()).equals("0"), "div008"); |
|
1440 harness.check (((new BigDecimal("2")).divide(new BigDecimal("3"), BigDecimal.ROUND_HALF_UP).toString()).equals("1"), "div015"); |
|
1441 |
|
1442 try{div0:do{ |
|
1443 (new BigDecimal("5")).divide(new BigDecimal("0.00"), BigDecimal.ROUND_HALF_UP); |
|
1444 flag=false; |
|
1445 }while(false);} |
|
1446 catch (java.lang.ArithmeticException xx40){ae=xx40; |
|
1447 flag=checkMessage(ae, "Divide by 0"); |
|
1448 }/*div0*/ |
|
1449 harness.check (flag, "div204"); |
|
1450 |
|
1451 return;} |
|
1452 /* ----------------------------------------------------------------- */ |
|
1453 |
|
1454 /** Test the {@link BigDecimal#max} method. */ |
|
1455 |
|
1456 public void diagmax(TestHarness harness){ |
|
1457 boolean flag=false; |
|
1458 java.lang.ArithmeticException ae=null; |
|
1459 |
|
1460 // we assume add/subtract test function; this and min just |
|
1461 // test existence and test the truth table |
|
1462 harness.check (((new BigDecimal("5")).max(new BigDecimal("2")).toString()).equals("5"), "max001"); |
|
1463 harness.check (((new BigDecimal("5")).max(new BigDecimal("5")).toString()).equals("5"), "max002"); |
|
1464 harness.check (((new BigDecimal("2")).max(new BigDecimal("7")).toString()).equals("7"), "max003"); |
|
1465 harness.check (((new BigDecimal("2E+3")).max(new BigDecimal("7")).toString()).equals("2E+3"), "max006"); |
|
1466 harness.check (((new BigDecimal("7")).max(new BigDecimal("2E+3")).toString()).equals("2E+3"), "max008"); |
|
1467 |
|
1468 try{checknull:do{ |
|
1469 ten.max((BigDecimal)null); |
|
1470 flag=false; |
|
1471 }while(false);} |
|
1472 catch (java.lang.NullPointerException xx47){ |
|
1473 flag=true; |
|
1474 }/*checknull*/ |
|
1475 harness.check (flag, "max010"); |
|
1476 return;} |
|
1477 |
|
1478 /** Test the {@link BigDecimal#min} method. */ |
|
1479 |
|
1480 public void diagmin(TestHarness harness){ |
|
1481 boolean flag=false; |
|
1482 BigDecimal minx=null; |
|
1483 java.lang.ArithmeticException ae=null; |
|
1484 // we assume add/subtract test function; this and max just |
|
1485 // test existence and test the truth table |
|
1486 |
|
1487 harness.check (((new BigDecimal("5")).min(new BigDecimal("2")).toString()).equals("2"), "min001"); |
|
1488 harness.check (((new BigDecimal("5")).min(new BigDecimal("5")).toString()).equals("5"), "min002"); |
|
1489 harness.check (((new BigDecimal("2")).min(new BigDecimal("7")).toString()).equals("2"), "min003"); |
|
1490 harness.check (((new BigDecimal("-2E+3")).min(new BigDecimal("7")).toString()).equals("-2E+3"), "min006"); |
|
1491 harness.check (((new BigDecimal("7")).min(new BigDecimal("-2E+3")).toString()).equals("-2E+3"), "min008"); |
|
1492 try{checknull:do{ |
|
1493 minx=ten; |
|
1494 minx.min((BigDecimal)null); |
|
1495 flag=false; |
|
1496 }while(false);} |
|
1497 catch (java.lang.NullPointerException xx51){ |
|
1498 flag=true; |
|
1499 }/*checknull*/ |
|
1500 harness.check (flag, "min010"); |
|
1501 |
|
1502 return;} |
|
1503 /* ----------------------------------------------------------------- */ |
|
1504 |
|
1505 /** Test the {@link BigDecimal#multiply} method. */ |
|
1506 |
|
1507 public void diagmultiply(TestHarness harness){ |
|
1508 boolean flag=false; |
|
1509 BigDecimal l9; |
|
1510 BigDecimal l77e; |
|
1511 BigDecimal l12345; |
|
1512 BigDecimal edge; |
|
1513 BigDecimal tenedge; |
|
1514 BigDecimal hunedge; |
|
1515 BigDecimal opo; |
|
1516 BigDecimal d1=null; |
|
1517 BigDecimal d2=null; |
|
1518 java.lang.ArithmeticException oe=null; |
|
1519 java.lang.ArithmeticException ae=null; |
|
1520 |
|
1521 harness.check (((new BigDecimal("2")).multiply(new BigDecimal("3")).toString()).equals("6"), "mul020"); |
|
1522 harness.check (((new BigDecimal("5")).multiply(new BigDecimal("1")).toString()).equals("5"), "mul021"); |
|
1523 harness.check (((new BigDecimal("5")).multiply(new BigDecimal("2")).toString()).equals("10"), "mul022"); |
|
1524 harness.check (((new BigDecimal("1.20")).multiply(new BigDecimal("2")).toString()).equals("2.40"), "mul023"); |
|
1525 harness.check (((new BigDecimal("1.20")).multiply(new BigDecimal("0")).toString()).equals("0.00"), "mul024"); |
|
1526 harness.check (((new BigDecimal("1.20")).multiply(new BigDecimal("-2")).toString()).equals("-2.40"), "mul025"); |
|
1527 harness.check (((new BigDecimal("-1.20")).multiply(new BigDecimal("2")).toString()).equals("-2.40"), "mul026"); |
|
1528 harness.check (((new BigDecimal("-1.20")).multiply(new BigDecimal("0")).toString()).equals("0.00"), "mul027"); |
|
1529 harness.check (((new BigDecimal("-1.20")).multiply(new BigDecimal("-2")).toString()).equals("2.40"), "mul028"); |
|
1530 harness.check (((new BigDecimal("5.09")).multiply(new BigDecimal("7.1")).toString()).equals("36.139"), "mul029"); |
|
1531 harness.check (((new BigDecimal("2.5")).multiply(new BigDecimal("4")).toString()).equals("10.0"), "mul030"); |
|
1532 harness.check (((new BigDecimal("2.50")).multiply(new BigDecimal("4")).toString()).equals("10.00"), "mul031"); |
|
1533 harness.check (((new BigDecimal("1.23456789")).multiply(new BigDecimal("1.00000000")).toString()).equals("1.2345678900000000"), "mul032"); |
|
1534 |
|
1535 harness.check (((new BigDecimal("1234.56789")).multiply(new BigDecimal("-1000.00000")).toString()).equals("-1234567.8900000000"), "mul033"); |
|
1536 |
|
1537 harness.check (((new BigDecimal("-1234.56789")).multiply(new BigDecimal("1000.00000")).toString()).equals("-1234567.8900000000"), "mul034"); |
|
1538 |
|
1539 harness.check (((new BigDecimal("9.999999999")).multiply(new BigDecimal("9.999999999")).toString()).equals("99.999999980000000001"), "mul035"); |
|
1540 |
|
1541 harness.check (((new BigDecimal("5.00")).multiply(new BigDecimal("1E-3")).toString()).equals("0.00500"), "mul036"); |
|
1542 harness.check (((new BigDecimal("00.00")).multiply(new BigDecimal("0.000")).toString()).equals("0.00000"), "mul037"); |
|
1543 harness.check (((new BigDecimal("00.00")).multiply(new BigDecimal("0E-3")).toString()).equals("0.00000"), "mul038"); |
|
1544 // 1999.12.21: next one is a edge case if intermediate longs are used |
|
1545 harness.check (((new BigDecimal("999999999999")).multiply(new BigDecimal("9765625")).toString()).equals("9765624999990234375"), "mul039"); |
|
1546 |
|
1547 l9=new BigDecimal("123456789E+10"); |
|
1548 l77e=new BigDecimal("77E-20"); |
|
1549 harness.check ((l9.multiply(new BigDecimal("3456757")).toString()).equals("4.26760119573273E+24"), "mul040"); |
|
1550 harness.check ((l9.multiply(l77e).toString()).equals("0.9506172753"), "mul042"); |
|
1551 |
|
1552 // test some more edge cases and carries |
|
1553 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("9")).toString()).equals("81"), "mul101"); |
|
1554 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("90")).toString()).equals("810"), "mul102"); |
|
1555 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("900")).toString()).equals("8100"), "mul103"); |
|
1556 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("9000")).toString()).equals("81000"), "mul104"); |
|
1557 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("90000")).toString()).equals("810000"), "mul105"); |
|
1558 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("900000")).toString()).equals("8100000"), "mul106"); |
|
1559 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("9000000")).toString()).equals("81000000"), "mul107"); |
|
1560 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("90000000")).toString()).equals("810000000"), "mul108"); |
|
1561 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("900000000")).toString()).equals("8100000000"), "mul109"); |
|
1562 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("9000000000")).toString()).equals("81000000000"), "mul110"); |
|
1563 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("90000000000")).toString()).equals("810000000000"), "mul111"); |
|
1564 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("900000000000")).toString()).equals("8100000000000"), "mul112"); |
|
1565 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("9000000000000")).toString()).equals("81000000000000"), "mul113"); |
|
1566 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("90000000000000")).toString()).equals("810000000000000"), "mul114"); |
|
1567 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("900000000000000")).toString()).equals("8100000000000000"), "mul115"); |
|
1568 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("9000000000000000")).toString()).equals("81000000000000000"), "mul116"); |
|
1569 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("90000000000000000")).toString()).equals("810000000000000000"), "mul117"); |
|
1570 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("900000000000000000")).toString()).equals("8100000000000000000"), "mul118"); |
|
1571 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("9000000000000000000")).toString()).equals("81000000000000000000"), "mul119"); |
|
1572 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("90000000000000000000")).toString()).equals("810000000000000000000"), "mul120"); |
|
1573 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("900000000000000000000")).toString()).equals("8100000000000000000000"), "mul121"); |
|
1574 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("9000000000000000000000")).toString()).equals("81000000000000000000000"), "mul122"); |
|
1575 harness.check (((new BigDecimal("9")).multiply(new BigDecimal("90000000000000000000000")).toString()).equals("810000000000000000000000"), "mul123"); |
|
1576 // test some more edge cases without carries |
|
1577 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("3")).toString()).equals("9"), "mul131"); |
|
1578 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("30")).toString()).equals("90"), "mul132"); |
|
1579 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("300")).toString()).equals("900"), "mul133"); |
|
1580 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("3000")).toString()).equals("9000"), "mul134"); |
|
1581 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("30000")).toString()).equals("90000"), "mul135"); |
|
1582 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("300000")).toString()).equals("900000"), "mul136"); |
|
1583 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("3000000")).toString()).equals("9000000"), "mul137"); |
|
1584 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("30000000")).toString()).equals("90000000"), "mul138"); |
|
1585 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("300000000")).toString()).equals("900000000"), "mul139"); |
|
1586 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("3000000000")).toString()).equals("9000000000"), "mul140"); |
|
1587 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("30000000000")).toString()).equals("90000000000"), "mul141"); |
|
1588 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("300000000000")).toString()).equals("900000000000"), "mul142"); |
|
1589 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("3000000000000")).toString()).equals("9000000000000"), "mul143"); |
|
1590 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("30000000000000")).toString()).equals("90000000000000"), "mul144"); |
|
1591 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("300000000000000")).toString()).equals("900000000000000"), "mul145"); |
|
1592 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("3000000000000000")).toString()).equals("9000000000000000"), "mul146"); |
|
1593 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("30000000000000000")).toString()).equals("90000000000000000"), "mul147"); |
|
1594 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("300000000000000000")).toString()).equals("900000000000000000"), "mul148"); |
|
1595 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("3000000000000000000")).toString()).equals("9000000000000000000"), "mul149"); |
|
1596 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("30000000000000000000")).toString()).equals("90000000000000000000"), "mul150"); |
|
1597 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("300000000000000000000")).toString()).equals("900000000000000000000"), "mul151"); |
|
1598 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("3000000000000000000000")).toString()).equals("9000000000000000000000"), "mul152"); |
|
1599 harness.check (((new BigDecimal("3")).multiply(new BigDecimal("30000000000000000000000")).toString()).equals("90000000000000000000000"), "mul153"); |
|
1600 |
|
1601 try{checknull:do{ |
|
1602 ten.multiply((BigDecimal)null); |
|
1603 flag=false; |
|
1604 }while(false);} |
|
1605 catch (java.lang.NullPointerException xx55){ |
|
1606 flag=true; |
|
1607 }/*checknull*/ |
|
1608 harness.check (flag, "mul200"); |
|
1609 |
|
1610 return;} |
|
1611 |
|
1612 /* ----------------------------------------------------------------- */ |
|
1613 |
|
1614 /** Test the {@link BigDecimal#negate} method. */ |
|
1615 |
|
1616 public void diagnegate(TestHarness harness){ |
|
1617 boolean flag=false; |
|
1618 java.lang.ArithmeticException ae=null; |
|
1619 |
|
1620 harness.check (((new BigDecimal("2")).negate().toString()).equals("-2"), "neg001"); |
|
1621 harness.check (((new BigDecimal("-2")).negate().toString()).equals("2"), "neg002"); |
|
1622 |
|
1623 harness.check (((new BigDecimal("2.00")).negate().toString()).equals("-2.00"), "neg010"); |
|
1624 harness.check (((new BigDecimal("-2.00")).negate().toString()).equals("2.00"), "neg011"); |
|
1625 harness.check (((new BigDecimal("0")).negate().toString()).equals("0"), "neg012"); |
|
1626 harness.check (((new BigDecimal("0.00")).negate().toString()).equals("0.00"), "neg013"); |
|
1627 harness.check (((new BigDecimal("00.0")).negate().toString()).equals("0.0"), "neg014"); |
|
1628 harness.check (((new BigDecimal("00.00")).negate().toString()).equals("0.00"), "neg015"); |
|
1629 harness.check (((new BigDecimal("00")).negate().toString()).equals("0"), "neg016"); |
|
1630 |
|
1631 harness.check (((new BigDecimal("-2000000")).negate().toString()).equals("2000000"), "neg020"); |
|
1632 |
|
1633 return;} |
|
1634 /* ----------------------------------------------------------------- */ |
|
1635 |
|
1636 /** Test the {@link BigDecimal#subtract} method. */ |
|
1637 |
|
1638 public void diagsubtract(TestHarness harness){ |
|
1639 boolean flag=false; |
|
1640 BigDecimal alhs; |
|
1641 BigDecimal arhs; |
|
1642 java.lang.ArithmeticException ae=null; |
|
1643 |
|
1644 harness.check (((new BigDecimal(2)).subtract(new BigDecimal(3)).toString()).equals("-1"), "sub001"); |
|
1645 harness.check (((new BigDecimal("5.75")).subtract(new BigDecimal("3.3")).toString()).equals("2.45"), "sub002"); |
|
1646 harness.check (((new BigDecimal("5")).subtract(new BigDecimal("-3")).toString()).equals("8"), "sub003"); |
|
1647 harness.check (((new BigDecimal("-5")).subtract(new BigDecimal("-3")).toString()).equals("-2"), "sub004"); |
|
1648 harness.check (((new BigDecimal("-7")).subtract(new BigDecimal("2.5")).toString()).equals("-9.5"), "sub005"); |
|
1649 harness.check (((new BigDecimal("0.7")).subtract(new BigDecimal("0.3")).toString()).equals("0.4"), "sub006"); |
|
1650 harness.check (((new BigDecimal("1.3")).subtract(new BigDecimal("0.3")).toString()).equals("1.0"), "sub007"); |
|
1651 harness.check (((new BigDecimal("1.25")).subtract(new BigDecimal("1.25")).toString()).equals("0.00"), "sub008"); |
|
1652 harness.check (((new BigDecimal("0.02")).subtract(new BigDecimal("0.02")).toString()).equals("0.00"), "sub009"); |
|
1653 |
|
1654 harness.check (((new BigDecimal("1.23456789")).subtract(new BigDecimal("1.00000000")).toString()).equals("0.23456789"), "sub010"); |
|
1655 |
|
1656 harness.check (((new BigDecimal("1.23456789")).subtract(new BigDecimal("1.00000089")).toString()).equals("0.23456700"), "sub011"); |
|
1657 |
|
1658 harness.check (((new BigDecimal("0.5555555559")).subtract(new BigDecimal("0.0000000001")).toString()).equals("0.5555555558"), "sub012"); |
|
1659 |
|
1660 harness.check (((new BigDecimal("0.5555555559")).subtract(new BigDecimal("0.0000000005")).toString()).equals("0.5555555554"), "sub013"); |
|
1661 |
|
1662 harness.check (((new BigDecimal("0.4444444444")).subtract(new BigDecimal("0.1111111111")).toString()).equals("0.3333333333"), "sub014"); |
|
1663 |
|
1664 harness.check (((new BigDecimal("1.0000000000")).subtract(new BigDecimal("0.00000001")).toString()).equals("0.9999999900"), "sub015"); |
|
1665 |
|
1666 harness.check (((new BigDecimal("0.4444444444999")).subtract(new BigDecimal("0")).toString()).equals("0.4444444444999"), "sub016"); |
|
1667 |
|
1668 harness.check (((new BigDecimal("0.4444444445000")).subtract(new BigDecimal("0")).toString()).equals("0.4444444445000"), "sub017"); |
|
1669 |
|
1670 |
|
1671 harness.check (((new BigDecimal("70")).subtract(new BigDecimal("10000e+9")).toString()).equals("-9999999999930"), "sub018"); |
|
1672 |
|
1673 harness.check (((new BigDecimal("700")).subtract(new BigDecimal("10000e+9")).toString()).equals("-9999999999300"), "sub019"); |
|
1674 |
|
1675 harness.check (((new BigDecimal("7000")).subtract(new BigDecimal("10000e+9")).toString()).equals("-9999999993000"), "sub020"); |
|
1676 |
|
1677 harness.check (((new BigDecimal("70000")).subtract(new BigDecimal("10000e+9")).toString()).equals("-9999999930000"), "sub021"); |
|
1678 |
|
1679 harness.check (((new BigDecimal("700000")).subtract(new BigDecimal("10000e+9")).toString()).equals("-9999999300000"), "sub022"); |
|
1680 |
|
1681 // symmetry: |
|
1682 harness.check (((new BigDecimal("10000e+9")).subtract(new BigDecimal("70")).toString()).equals("9999999999930"), "sub023"); |
|
1683 |
|
1684 harness.check (((new BigDecimal("10000e+9")).subtract(new BigDecimal("700")).toString()).equals("9999999999300"), "sub024"); |
|
1685 |
|
1686 harness.check (((new BigDecimal("10000e+9")).subtract(new BigDecimal("7000")).toString()).equals("9999999993000"), "sub025"); |
|
1687 |
|
1688 harness.check (((new BigDecimal("10000e+9")).subtract(new BigDecimal("70000")).toString()).equals("9999999930000"), "sub026"); |
|
1689 |
|
1690 harness.check (((new BigDecimal("10000e+9")).subtract(new BigDecimal("700000")).toString()).equals("9999999300000"), "sub027"); |
|
1691 |
|
1692 // some of the next group are really constructor tests |
|
1693 harness.check (((new BigDecimal("00.0")).subtract(new BigDecimal("0.0")).toString()).equals("0.0"), "sub040"); |
|
1694 harness.check (((new BigDecimal("00.0")).subtract(new BigDecimal("0.00")).toString()).equals("0.00"), "sub041"); |
|
1695 harness.check (((new BigDecimal("0.00")).subtract(new BigDecimal("00.0")).toString()).equals("0.00"), "sub042"); |
|
1696 harness.check (((new BigDecimal("3")).subtract(new BigDecimal(".3")).toString()).equals("2.7"), "sub052"); |
|
1697 harness.check (((new BigDecimal("3.")).subtract(new BigDecimal(".3")).toString()).equals("2.7"), "sub053"); |
|
1698 harness.check (((new BigDecimal("3.0")).subtract(new BigDecimal(".3")).toString()).equals("2.7"), "sub054"); |
|
1699 harness.check (((new BigDecimal("3.00")).subtract(new BigDecimal(".3")).toString()).equals("2.70"), "sub055"); |
|
1700 harness.check (((new BigDecimal("3")).subtract(new BigDecimal("3")).toString()).equals("0"), "sub056"); |
|
1701 harness.check (((new BigDecimal("3")).subtract(new BigDecimal("+3")).toString()).equals("0"), "sub057"); |
|
1702 harness.check (((new BigDecimal("3")).subtract(new BigDecimal("-3")).toString()).equals("6"), "sub058"); |
|
1703 |
|
1704 |
|
1705 alhs=new BigDecimal("12345678900000"); |
|
1706 arhs=new BigDecimal("9999999999999"); |
|
1707 harness.check ((alhs.subtract(arhs).toString()).equals("2345678900001"), "sub112"); |
|
1708 harness.check ((arhs.subtract(alhs).toString()).equals("-2345678900001"), "sub113"); |
|
1709 |
|
1710 // additional scaled arithmetic tests [0.97 problem] |
|
1711 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".1")).toString()).equals("-0.1"), "sub120"); |
|
1712 harness.check (((new BigDecimal("00")).subtract(new BigDecimal(".97983")).toString()).equals("-0.97983"), "sub121"); |
|
1713 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".9")).toString()).equals("-0.9"), "sub122"); |
|
1714 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("0.102")).toString()).equals("-0.102"), "sub123"); |
|
1715 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".4")).toString()).equals("-0.4"), "sub124"); |
|
1716 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".307")).toString()).equals("-0.307"), "sub125"); |
|
1717 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".43822")).toString()).equals("-0.43822"), "sub126"); |
|
1718 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".911")).toString()).equals("-0.911"), "sub127"); |
|
1719 harness.check (((new BigDecimal(".0")).subtract(new BigDecimal(".02")).toString()).equals("-0.02"), "sub128"); |
|
1720 harness.check (((new BigDecimal("00")).subtract(new BigDecimal(".392")).toString()).equals("-0.392"), "sub129"); |
|
1721 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".26")).toString()).equals("-0.26"), "sub130"); |
|
1722 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("0.51")).toString()).equals("-0.51"), "sub131"); |
|
1723 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".2234")).toString()).equals("-0.2234"), "sub132"); |
|
1724 harness.check (((new BigDecimal("0")).subtract(new BigDecimal(".2")).toString()).equals("-0.2"), "sub133"); |
|
1725 harness.check (((new BigDecimal(".0")).subtract(new BigDecimal(".0008")).toString()).equals("-0.0008"), "sub134"); |
|
1726 // 0. on left |
|
1727 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.1")).toString()).equals("0.1"), "sub140"); |
|
1728 harness.check (((new BigDecimal("0.00")).subtract(new BigDecimal("-.97983")).toString()).equals("0.97983"), "sub141"); |
|
1729 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.9")).toString()).equals("0.9"), "sub142"); |
|
1730 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-0.102")).toString()).equals("0.102"), "sub143"); |
|
1731 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.4")).toString()).equals("0.4"), "sub144"); |
|
1732 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.307")).toString()).equals("0.307"), "sub145"); |
|
1733 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.43822")).toString()).equals("0.43822"), "sub146"); |
|
1734 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.911")).toString()).equals("0.911"), "sub147"); |
|
1735 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.02")).toString()).equals("0.02"), "sub148"); |
|
1736 harness.check (((new BigDecimal("0.00")).subtract(new BigDecimal("-.392")).toString()).equals("0.392"), "sub149"); |
|
1737 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.26")).toString()).equals("0.26"), "sub150"); |
|
1738 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-0.51")).toString()).equals("0.51"), "sub151"); |
|
1739 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.2234")).toString()).equals("0.2234"), "sub152"); |
|
1740 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.2")).toString()).equals("0.2"), "sub153"); |
|
1741 harness.check (((new BigDecimal("0.0")).subtract(new BigDecimal("-.0008")).toString()).equals("0.0008"), "sub154"); |
|
1742 // negatives of same |
|
1743 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.1")).toString()).equals("0.1"), "sub160"); |
|
1744 harness.check (((new BigDecimal("00")).subtract(new BigDecimal("-.97983")).toString()).equals("0.97983"), "sub161"); |
|
1745 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.9")).toString()).equals("0.9"), "sub162"); |
|
1746 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-0.102")).toString()).equals("0.102"), "sub163"); |
|
1747 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.4")).toString()).equals("0.4"), "sub164"); |
|
1748 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.307")).toString()).equals("0.307"), "sub165"); |
|
1749 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.43822")).toString()).equals("0.43822"), "sub166"); |
|
1750 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.911")).toString()).equals("0.911"), "sub167"); |
|
1751 harness.check (((new BigDecimal(".0")).subtract(new BigDecimal("-.02")).toString()).equals("0.02"), "sub168"); |
|
1752 harness.check (((new BigDecimal("00")).subtract(new BigDecimal("-.392")).toString()).equals("0.392"), "sub169"); |
|
1753 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.26")).toString()).equals("0.26"), "sub170"); |
|
1754 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-0.51")).toString()).equals("0.51"), "sub171"); |
|
1755 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.2234")).toString()).equals("0.2234"), "sub172"); |
|
1756 harness.check (((new BigDecimal("0")).subtract(new BigDecimal("-.2")).toString()).equals("0.2"), "sub173"); |
|
1757 harness.check (((new BigDecimal(".0")).subtract(new BigDecimal("-.0008")).toString()).equals("0.0008"), "sub174"); |
|
1758 |
|
1759 // more fixed, LHS swaps [really same as testcases under add] |
|
1760 harness.check (((new BigDecimal("-56267E-10")).subtract(zero).toString()).equals("-0.0000056267"), "sub180"); |
|
1761 harness.check (((new BigDecimal("-56267E-5")).subtract(zero).toString()).equals("-0.56267"), "sub181"); |
|
1762 harness.check (((new BigDecimal("-56267E-2")).subtract(zero).toString()).equals("-562.67"), "sub182"); |
|
1763 harness.check (((new BigDecimal("-56267E-1")).subtract(zero).toString()).equals("-5626.7"), "sub183"); |
|
1764 harness.check (((new BigDecimal("-56267E-0")).subtract(zero).toString()).equals("-56267"), "sub185"); |
|
1765 |
|
1766 try{checknull:do{ |
|
1767 ten.subtract((BigDecimal)null); |
|
1768 flag=false; |
|
1769 }while(false);} |
|
1770 catch (java.lang.NullPointerException xx83){ |
|
1771 flag=true; |
|
1772 }/*checknull*/ |
|
1773 harness.check (flag, "sub200"); |
|
1774 |
|
1775 return;} |
|
1776 /* ----------------------------------------------------------------- */ |
|
1777 |
|
1778 /* ----------------------------------------------------------------- */ |
|
1779 /* Other methods */ |
|
1780 /* ----------------------------------------------------------------- */ |
|
1781 |
|
1782 /** Test the <code>BigDecimal.byteValue()</code> method. */ |
|
1783 |
|
1784 public void diagbyteValue(TestHarness harness){ |
|
1785 boolean flag=false; |
|
1786 java.lang.String v=null; |
|
1787 java.lang.ArithmeticException ae=null; |
|
1788 java.lang.String badstrings[]; |
|
1789 int i=0; |
|
1790 java.lang.String norm=null; |
|
1791 |
|
1792 |
|
1793 harness.check (((((byte)-128)))==((new BigDecimal("-128")).byteValue()), "byv001"); |
|
1794 harness.check (((0))==((new BigDecimal("0")).byteValue()), "byv002"); |
|
1795 harness.check (((1))==((new BigDecimal("1")).byteValue()), "byv003"); |
|
1796 harness.check (((99))==((new BigDecimal("99")).byteValue()), "byv004"); |
|
1797 harness.check (((127))==((new BigDecimal("127")).byteValue()), "byv005"); |
|
1798 harness.check (((-128))==((new BigDecimal("128")).byteValue()), "byv006"); |
|
1799 harness.check (((-127))==((new BigDecimal("129")).byteValue()), "byv007"); |
|
1800 harness.check (((127))==((new BigDecimal("-129")).byteValue()), "byv008"); |
|
1801 harness.check (((126))==((new BigDecimal("-130")).byteValue()), "byv009"); |
|
1802 harness.check (((bmax))==((new BigDecimal(bmax)).byteValue()), "byv010"); |
|
1803 harness.check (((bmin))==((new BigDecimal(bmin)).byteValue()), "byv011"); |
|
1804 harness.check (((bneg))==((new BigDecimal(bneg)).byteValue()), "byv012"); |
|
1805 harness.check (((bzer))==((new BigDecimal(bzer)).byteValue()), "byv013"); |
|
1806 harness.check (((bpos))==((new BigDecimal(bpos)).byteValue()), "byv014"); |
|
1807 harness.check (((bmin))==((new BigDecimal(bmax+1)).byteValue()), "byv015"); |
|
1808 harness.check (((bmax))==((new BigDecimal(bmin-1)).byteValue()), "byv016"); |
|
1809 |
|
1810 badstrings=new java.lang.String[]{"1234",(new BigDecimal(bmax)).add(one).toString(),(new BigDecimal(bmin)).subtract(one).toString(),"170","270","370","470","570","670","770","870","970","-170","-270","-370","-470","-570","-670","-770","-870","-970",(new BigDecimal(bmin)).multiply(two).toString(),(new BigDecimal(bmax)).multiply(two).toString(),(new BigDecimal(bmin)).multiply(ten).toString(),(new BigDecimal(bmax)).multiply(ten).toString(),"-1234"}; // 220 |
|
1811 // 221 |
|
1812 // 222 |
|
1813 // 223 |
|
1814 // 224 |
|
1815 // 225 |
|
1816 // 226 |
|
1817 // 227 |
|
1818 // 228 |
|
1819 // 229 |
|
1820 // 230 |
|
1821 // 231 |
|
1822 // 232 |
|
1823 // 233 |
|
1824 // 234 |
|
1825 // 235 |
|
1826 // 236 |
|
1827 // 237 |
|
1828 // 238 |
|
1829 // 239 |
|
1830 // 240 |
|
1831 // 241 |
|
1832 // 242 |
|
1833 // 243 |
|
1834 // 244 |
|
1835 // 245 |
|
1836 |
|
1837 return;} |
|
1838 /* ----------------------------------------------------------------- */ |
|
1839 |
|
1840 /** Test the {@link BigDecimal#compareTo(java.lang.Object)} method. */ |
|
1841 |
|
1842 public void diagcomparetoObj(TestHarness harness){ |
|
1843 boolean flag=false; |
|
1844 BigDecimal d; |
|
1845 BigDecimal long1; |
|
1846 BigDecimal long2; |
|
1847 |
|
1848 d=new BigDecimal(17); |
|
1849 harness.check ((((Comparable)d).compareTo((java.lang.Object)(new BigDecimal(66))))==(-1), "cto001"); |
|
1850 harness.check ((((Comparable)d).compareTo((java.lang.Object)((new BigDecimal(10)).add(new BigDecimal(7)))))==0, "cto002"); |
|
1851 harness.check ((((Comparable)d).compareTo((java.lang.Object)(new BigDecimal(10))))==1, "cto003"); |
|
1852 long1=new BigDecimal("12345678903"); |
|
1853 long2=new BigDecimal("12345678900"); |
|
1854 harness.check ((((Comparable)long1).compareTo((java.lang.Object)long2))==1, "cto004"); |
|
1855 harness.check ((((Comparable)long2).compareTo((java.lang.Object)long1))==(-1), "cto005"); |
|
1856 harness.check ((((Comparable)long2).compareTo((java.lang.Object)long2))==0, "cto006"); |
|
1857 try{ |
|
1858 ((Comparable)d).compareTo((java.lang.Object)null); |
|
1859 flag=false; |
|
1860 } |
|
1861 catch (java.lang.NullPointerException xx92){ |
|
1862 flag=true; // should get here |
|
1863 } |
|
1864 harness.check (flag, "cto101"); |
|
1865 try{ |
|
1866 ((Comparable)d).compareTo((java.lang.Object)"foo"); |
|
1867 flag=false; |
|
1868 } |
|
1869 catch (java.lang.ClassCastException xx93){ |
|
1870 flag=true; // should get here |
|
1871 } |
|
1872 harness.check (flag, "cto102"); |
|
1873 |
|
1874 return;} |
|
1875 /* ----------------------------------------------------------------- */ |
|
1876 |
|
1877 /** Test the {@link BigDecimal#doubleValue} method. */ |
|
1878 |
|
1879 public void diagdoublevalue(TestHarness harness){ |
|
1880 java.lang.String val; |
|
1881 // 1999.03.07 Infinities no longer errors |
|
1882 val="-1"; |
|
1883 harness.check (((new BigDecimal(val)).doubleValue())==((new java.lang.Double(val)).doubleValue()), "dov001"); |
|
1884 val="-0.1"; |
|
1885 harness.check (((new BigDecimal(val)).doubleValue())==((new java.lang.Double(val)).doubleValue()), "dov002"); |
|
1886 val="0"; |
|
1887 harness.check (((new BigDecimal(val)).doubleValue())==((new java.lang.Double(val)).doubleValue()), "dov003"); |
|
1888 val="0.1"; |
|
1889 harness.check (((new BigDecimal(val)).doubleValue())==((new java.lang.Double(val)).doubleValue()), "dov004"); |
|
1890 val="1"; |
|
1891 harness.check (((new BigDecimal(val)).doubleValue())==((new java.lang.Double(val)).doubleValue()), "dov005"); |
|
1892 val="1e1000"; |
|
1893 harness.check (((new BigDecimal(val)).doubleValue())==java.lang.Double.POSITIVE_INFINITY, "dov006"); |
|
1894 val="-1e1000"; |
|
1895 harness.check (((new BigDecimal(val)).doubleValue())==java.lang.Double.NEGATIVE_INFINITY, "dov007"); |
|
1896 return;} |
|
1897 /* ----------------------------------------------------------------- */ |
|
1898 |
|
1899 /** Test the {@link BigDecimal#equals} method. */ |
|
1900 |
|
1901 public void diagequals(TestHarness harness){ |
|
1902 BigDecimal d; |
|
1903 d=new BigDecimal(17); |
|
1904 harness.check ((!(d.equals((java.lang.Object)null))), "equ001"); |
|
1905 harness.check ((!(d.equals((java.lang.Object)"foo"))), "equ002"); |
|
1906 harness.check ((!(d.equals((java.lang.Object)(new BigDecimal(66))))), "equ003"); |
|
1907 harness.check (d.equals((java.lang.Object)d), "equ004"); |
|
1908 harness.check (d.equals((java.lang.Object)((new BigDecimal(10)).add(new BigDecimal(7)))), "equ005"); |
|
1909 return;} |
|
1910 |
|
1911 /* ----------------------------------------------------------------- */ |
|
1912 |
|
1913 /** Test the {@link BigDecimal#floatValue} method. */ |
|
1914 |
|
1915 public void diagfloatvalue(TestHarness harness){ |
|
1916 java.lang.String val; |
|
1917 // 1999.03.07 Infinities no longer errors |
|
1918 val="-1"; |
|
1919 harness.check (((new BigDecimal(val)).floatValue())==((new java.lang.Float(val)).floatValue()), "flv001"); |
|
1920 val="-0.1"; |
|
1921 harness.check (((new BigDecimal(val)).floatValue())==((new java.lang.Float(val)).floatValue()), "flv002"); |
|
1922 val="0"; |
|
1923 harness.check (((new BigDecimal(val)).floatValue())==((new java.lang.Float(val)).floatValue()), "flv003"); |
|
1924 val="0.1"; |
|
1925 harness.check (((new BigDecimal(val)).floatValue())==((new java.lang.Float(val)).floatValue()), "flv004"); |
|
1926 val="1"; |
|
1927 harness.check (((new BigDecimal(val)).floatValue())==((new java.lang.Float(val)).floatValue()), "flv005"); |
|
1928 val="1e200"; |
|
1929 harness.check (((new BigDecimal(val)).floatValue())==java.lang.Float.POSITIVE_INFINITY, "flv006"); |
|
1930 val="-1e200"; |
|
1931 harness.check (((new BigDecimal(val)).floatValue())==java.lang.Float.NEGATIVE_INFINITY, "flv007"); |
|
1932 val="1e1000"; |
|
1933 harness.check (((new BigDecimal(val)).floatValue())==java.lang.Float.POSITIVE_INFINITY, "flv008"); |
|
1934 val="-1e1000"; |
|
1935 harness.check (((new BigDecimal(val)).floatValue())==java.lang.Float.NEGATIVE_INFINITY, "flv009"); |
|
1936 return;} |
|
1937 |
|
1938 /* ----------------------------------------------------------------- */ |
|
1939 |
|
1940 /** Test the {@link BigDecimal#hashCode} method. */ |
|
1941 |
|
1942 public void diaghashcode(TestHarness harness){ |
|
1943 // These tests are all wrong. The JDK API for BigDecimal.hashCode() |
|
1944 // does not say how the hash values should be calculated. |
|
1945 // |
|
1946 // java.lang.String hs; |
|
1947 // BigDecimal d; |
|
1948 // hs="27827817"; |
|
1949 // d=new BigDecimal(hs); |
|
1950 // harness.check ((d.hashCode())==(hs.hashCode()), "has001"); |
|
1951 // hs="1.265E+200"; |
|
1952 // d=new BigDecimal(hs); |
|
1953 // harness.check ((d.hashCode())==(hs.hashCode()), "has002"); |
|
1954 // hs="126.5E+200"; |
|
1955 // d=new BigDecimal(hs); |
|
1956 // harness.check ((d.hashCode())!=(hs.hashCode()), "has003"); |
|
1957 return;} |
|
1958 /* ----------------------------------------------------------------- */ |
|
1959 |
|
1960 /** Test the {@link BigDecimal#intValue} method. */ |
|
1961 |
|
1962 public void diagintvalue(TestHarness harness){ |
|
1963 boolean flag=false; |
|
1964 java.lang.String v=null; |
|
1965 java.lang.ArithmeticException ae=null; |
|
1966 int i=0; |
|
1967 java.lang.String norm=null; |
|
1968 BigDecimal dimax; |
|
1969 BigDecimal num=null; |
|
1970 BigDecimal dv=null; |
|
1971 BigDecimal dimin; |
|
1972 |
|
1973 |
|
1974 // intValue -- |
|
1975 |
|
1976 harness.check (imin==((new BigDecimal(imin)).intValue()), "inv001"); |
|
1977 harness.check (((99))==((new BigDecimal("99")).intValue()), "inv002"); |
|
1978 harness.check (((1))==((new BigDecimal("1")).intValue()), "inv003"); |
|
1979 harness.check (((0))==((new BigDecimal("0")).intValue()), "inv004"); |
|
1980 harness.check (((-1))==((new BigDecimal("-1")).intValue()), "inv005"); |
|
1981 harness.check (((-99))==((new BigDecimal("-99")).intValue()), "inv006"); |
|
1982 harness.check (imax==((new BigDecimal(imax)).intValue()), "inv007"); |
|
1983 harness.check (((5))==((new BigDecimal("5.0")).intValue()), "inv008"); |
|
1984 harness.check (((5))==((new BigDecimal("5.3")).intValue()), "inv009"); |
|
1985 harness.check (((5))==((new BigDecimal("5.5")).intValue()), "inv010"); |
|
1986 harness.check (((5))==((new BigDecimal("5.7")).intValue()), "inv011"); |
|
1987 harness.check (((5))==((new BigDecimal("5.9")).intValue()), "inv012"); |
|
1988 harness.check (((-5))==((new BigDecimal("-5.0")).intValue()), "inv013"); |
|
1989 harness.check (((-5))==((new BigDecimal("-5.3")).intValue()), "inv014"); |
|
1990 harness.check (((-5))==((new BigDecimal("-5.5")).intValue()), "inv015"); |
|
1991 harness.check (((-5))==((new BigDecimal("-5.7")).intValue()), "inv016"); |
|
1992 harness.check (((-5))==((new BigDecimal("-5.9")).intValue()), "inv017"); |
|
1993 harness.check (((new BigDecimal("88888888888")).intValue())==(-1305424328), "inv018"); // ugh |
|
1994 harness.check (((new BigDecimal("-88888888888")).intValue())==1305424328, "inv019"); // ugh |
|
1995 harness.check (((imin))==((new BigDecimal((((long)imax))+1)).intValue()), "inv020"); |
|
1996 harness.check (((imax))==((new BigDecimal((((long)imin))-1)).intValue()), "inv021"); |
|
1997 |
|
1998 harness.check (((99))==((new BigDecimal("99")).intValue()), "inv102"); |
|
1999 harness.check (((1))==((new BigDecimal("1")).intValue()), "inv103"); |
|
2000 harness.check (((0))==((new BigDecimal("0")).intValue()), "inv104"); |
|
2001 harness.check (((-1))==((new BigDecimal("-1")).intValue()), "inv105"); |
|
2002 harness.check (((-99))==((new BigDecimal("-99")).intValue()), "inv106"); |
|
2003 harness.check (imax==((new BigDecimal(imax)).intValue()), "inv107"); |
|
2004 harness.check (((5))==((new BigDecimal("5.0")).intValue()), "inv108"); |
|
2005 harness.check (((-5))==((new BigDecimal("-5.0")).intValue()), "inv109"); |
|
2006 |
|
2007 return;} |
|
2008 |
|
2009 /* ----------------------------------------------------------------- */ |
|
2010 |
|
2011 /** Test the {@link BigDecimal#longValue} method. */ |
|
2012 |
|
2013 public void diaglongvalue(TestHarness harness){ |
|
2014 boolean flag=false; |
|
2015 java.lang.String v=null; |
|
2016 java.lang.ArithmeticException ae=null; |
|
2017 java.lang.String badstrings[]; |
|
2018 int i=0; |
|
2019 java.lang.String norm=null; |
|
2020 BigDecimal dlmax; |
|
2021 BigDecimal num=null; |
|
2022 BigDecimal dv=null; |
|
2023 BigDecimal dlmin; |
|
2024 |
|
2025 |
|
2026 // longValue -- |
|
2027 |
|
2028 harness.check (lmin==((new BigDecimal(lmin)).longValue()), "lov001"); |
|
2029 harness.check (lmin==((new BigDecimal(lminString)).longValue()), "lov001a"); |
|
2030 harness.check ((((long)99))==((new BigDecimal("99")).longValue()), "lov002"); |
|
2031 harness.check ((((long)1))==((new BigDecimal("1")).longValue()), "lov003"); |
|
2032 harness.check ((((long)0))==((new BigDecimal("0")).longValue()), "lov004"); |
|
2033 harness.check ((((long)-1))==((new BigDecimal("-1")).longValue()), "lov005"); |
|
2034 harness.check ((((long)-99))==((new BigDecimal("-99")).longValue()), "lov006"); |
|
2035 // This version of the test uses the BigDecimal(double) constructor. |
|
2036 // The test fails because ((long)((double) lmax)) != lmax |
|
2037 // harness.check (lmax==((new BigDecimal(lmax)).longValue()), "lov007"); |
|
2038 harness.check (lmax==((new BigDecimal(lmaxString)).longValue()), "lov007a"); |
|
2039 harness.check ((((long)5))==((new BigDecimal("5.0")).longValue()), "lov008"); |
|
2040 harness.check ((((long)5))==((new BigDecimal("5.3")).longValue()), "lov009"); |
|
2041 harness.check ((((long)5))==((new BigDecimal("5.5")).longValue()), "lov010"); |
|
2042 harness.check ((((long)5))==((new BigDecimal("5.7")).longValue()), "lov011"); |
|
2043 harness.check ((((long)5))==((new BigDecimal("5.9")).longValue()), "lov012"); |
|
2044 harness.check ((((long)-5))==((new BigDecimal("-5.0")).longValue()), "lov013"); |
|
2045 harness.check ((((long)-5))==((new BigDecimal("-5.3")).longValue()), "lov014"); |
|
2046 harness.check ((((long)-5))==((new BigDecimal("-5.5")).longValue()), "lov015"); |
|
2047 harness.check ((((long)-5))==((new BigDecimal("-5.7")).longValue()), "lov016"); |
|
2048 harness.check ((((long)-5))==((new BigDecimal("-5.9")).longValue()), "lov017"); |
|
2049 harness.check (((new BigDecimal("888888888899999999998")).longValue())==3445173361941522430L, "lov018"); // ugh |
|
2050 harness.check (((new BigDecimal("-888888888899999999998")).longValue())==(-3445173361941522430L), "lov019"); // ugh |
|
2051 |
|
2052 harness.check (lmin==((new BigDecimal(lminString)).longValue()), "lov101"); |
|
2053 harness.check ((((long)99))==((new BigDecimal("99")).longValue()), "lov102"); |
|
2054 harness.check ((((long)1))==((new BigDecimal("1")).longValue()), "lov103"); |
|
2055 harness.check ((((long)0))==((new BigDecimal("0")).longValue()), "lov104"); |
|
2056 harness.check ((((long)-1))==((new BigDecimal("-1")).longValue()), "lov105"); |
|
2057 harness.check ((((long)-99))==((new BigDecimal("-99")).longValue()), "lov106"); |
|
2058 // This version of this test is incorrect: see 'lov007' |
|
2059 // harness.check (lmax==((new BigDecimal(lmax)).longValue()), "lov107"); |
|
2060 harness.check (lmax==((new BigDecimal(lmaxString)).longValue()), "lov107a"); |
|
2061 harness.check ((((long)5))==((new BigDecimal("5.0")).longValue()), "lov108"); |
|
2062 harness.check ((((long)-5))==((new BigDecimal("-5.0")).longValue()), "lov109"); |
|
2063 |
|
2064 return;} |
|
2065 |
|
2066 /* ----------------------------------------------------------------- */ |
|
2067 |
|
2068 /** Test the {@link BigDecimal#movePointLeft} method. */ |
|
2069 |
|
2070 public void diagmovepointleft(TestHarness harness){ |
|
2071 harness.check (((new BigDecimal("-1")).movePointLeft(-10).toString()).equals("-10000000000"), "mpl001"); |
|
2072 harness.check (((new BigDecimal("-1")).movePointLeft(-5).toString()).equals("-100000"), "mpl002"); |
|
2073 harness.check (((new BigDecimal("-1")).movePointLeft(-1).toString()).equals("-10"), "mpl003"); |
|
2074 harness.check (((new BigDecimal("-1")).movePointLeft(0).toString()).equals("-1"), "mpl004"); |
|
2075 harness.check (((new BigDecimal("-1")).movePointLeft(+1).toString()).equals("-0.1"), "mpl005"); |
|
2076 harness.check (((new BigDecimal("-1")).movePointLeft(+5).toString()).equals("-0.00001"), "mpl006"); |
|
2077 harness.check (((new BigDecimal("-1")).movePointLeft(+10).toString()).equals("-1E-10"), "mpl007"); |
|
2078 |
|
2079 harness.check (((new BigDecimal("0")).movePointLeft(-10).toString()).equals("0"), "mpl010"); |
|
2080 harness.check (((new BigDecimal("0")).movePointLeft(-5).toString()).equals("0"), "mpl010"); |
|
2081 harness.check (((new BigDecimal("0")).movePointLeft(-1).toString()).equals("0"), "mpl010"); |
|
2082 harness.check (((new BigDecimal("0")).movePointLeft(0).toString()).equals("0"), "mpl010"); |
|
2083 harness.check (((new BigDecimal("0")).movePointLeft(+1).toString()).equals("0.0"), "mpl010"); |
|
2084 harness.check (((new BigDecimal("0")).movePointLeft(+5).toString()).equals("0.00000"), "mpl010"); |
|
2085 harness.check (((new BigDecimal("0")).movePointLeft(+10).toString()).equals("0E-10"), "mpl010"); |
|
2086 |
|
2087 harness.check (((new BigDecimal("+1")).movePointLeft(-10).toString()).equals("10000000000"), "mpl020"); |
|
2088 harness.check (((new BigDecimal("+1")).movePointLeft(-5).toString()).equals("100000"), "mpl021"); |
|
2089 harness.check (((new BigDecimal("+1")).movePointLeft(-1).toString()).equals("10"), "mpl022"); |
|
2090 harness.check (((new BigDecimal("+1")).movePointLeft(0).toString()).equals("1"), "mpl023"); |
|
2091 harness.check (((new BigDecimal("+1")).movePointLeft(+1).toString()).equals("0.1"), "mpl024"); |
|
2092 harness.check (((new BigDecimal("+1")).movePointLeft(+5).toString()).equals("0.00001"), "mpl025"); |
|
2093 harness.check (((new BigDecimal("+1")).movePointLeft(+10).toString()).equals("1E-10"), "mpl026"); |
|
2094 |
|
2095 harness.check (((new BigDecimal("0.5E+1")).movePointLeft(-10).toString()).equals("50000000000"), "mpl030"); |
|
2096 harness.check (((new BigDecimal("0.5E+1")).movePointLeft(-5).toString()).equals("500000"), "mpl031"); |
|
2097 harness.check (((new BigDecimal("0.5E+1")).movePointLeft(-1).toString()).equals("50"), "mpl032"); |
|
2098 harness.check (((new BigDecimal("0.5E+1")).movePointLeft(0).toString()).equals("5"), "mpl033"); |
|
2099 harness.check (((new BigDecimal("0.5E+1")).movePointLeft(+1).toString()).equals("0.5"), "mpl034"); |
|
2100 harness.check (((new BigDecimal("0.5E+1")).movePointLeft(+5).toString()).equals("0.00005"), "mpl035"); |
|
2101 harness.check (((new BigDecimal("0.5E+1")).movePointLeft(+10).toString()).equals("5E-10"), "mpl036"); |
|
2102 |
|
2103 return;} |
|
2104 /* ----------------------------------------------------------------- */ |
|
2105 |
|
2106 /** Test the {@link BigDecimal#movePointRight} method. */ |
|
2107 |
|
2108 public void diagmovepointright(TestHarness harness){ |
|
2109 harness.check (((new BigDecimal("-1")).movePointRight(+10).toString()).equals("-10000000000"), "mpr001"); |
|
2110 harness.check (((new BigDecimal("-1")).movePointRight(+5).toString()).equals("-100000"), "mpr002"); |
|
2111 harness.check (((new BigDecimal("-1")).movePointRight(+1).toString()).equals("-10"), "mpr003"); |
|
2112 harness.check (((new BigDecimal("-1")).movePointRight(0).toString()).equals("-1"), "mpr004"); |
|
2113 harness.check (((new BigDecimal("-1")).movePointRight(-1).toString()).equals("-0.1"), "mpr005"); |
|
2114 harness.check (((new BigDecimal("-1")).movePointRight(-5).toString()).equals("-0.00001"), "mpr006"); |
|
2115 harness.check (((new BigDecimal("-1")).movePointRight(-10).toString()).equals("-1E-10"), "mpr007"); |
|
2116 |
|
2117 harness.check (((new BigDecimal("0")).movePointRight(+10).toString()).equals("0"), "mpr010"); |
|
2118 harness.check (((new BigDecimal("0")).movePointRight(+5).toString()).equals("0"), "mpr011"); |
|
2119 harness.check (((new BigDecimal("0")).movePointRight(+1).toString()).equals("0"), "mpr012"); |
|
2120 harness.check (((new BigDecimal("0")).movePointRight(0).toString()).equals("0"), "mpr013"); |
|
2121 harness.check (((new BigDecimal("0")).movePointRight(-1).toString()).equals("0.0"), "mpr014"); |
|
2122 harness.check (((new BigDecimal("0")).movePointRight(-5).toString()).equals("0.00000"), "mpr015"); |
|
2123 harness.check (((new BigDecimal("0")).movePointRight(-10).toString()).equals("0E-10"), "mpr016"); |
|
2124 |
|
2125 harness.check (((new BigDecimal("+1")).movePointRight(+10).toString()).equals("10000000000"), "mpr020"); |
|
2126 harness.check (((new BigDecimal("+1")).movePointRight(+5).toString()).equals("100000"), "mpr021"); |
|
2127 harness.check (((new BigDecimal("+1")).movePointRight(+1).toString()).equals("10"), "mpr022"); |
|
2128 harness.check (((new BigDecimal("+1")).movePointRight(0).toString()).equals("1"), "mpr023"); |
|
2129 harness.check (((new BigDecimal("+1")).movePointRight(-1).toString()).equals("0.1"), "mpr024"); |
|
2130 harness.check (((new BigDecimal("+1")).movePointRight(-5).toString()).equals("0.00001"), "mpr025"); |
|
2131 harness.check (((new BigDecimal("+1")).movePointRight(-10).toString()).equals("1E-10"), "mpr026"); |
|
2132 |
|
2133 harness.check (((new BigDecimal("0.5E+1")).movePointRight(+10).toString()).equals("50000000000"), "mpr030"); |
|
2134 harness.check (((new BigDecimal("0.5E+1")).movePointRight(+5).toString()).equals("500000"), "mpr031"); |
|
2135 harness.check (((new BigDecimal("0.5E+1")).movePointRight(+1).toString()).equals("50"), "mpr032"); |
|
2136 harness.check (((new BigDecimal("0.5E+1")).movePointRight(0).toString()).equals("5"), "mpr033"); |
|
2137 harness.check (((new BigDecimal("0.5E+1")).movePointRight(-1).toString()).equals("0.5"), "mpr034"); |
|
2138 harness.check (((new BigDecimal("0.5E+1")).movePointRight(-5).toString()).equals("0.00005"), "mpr035"); |
|
2139 harness.check (((new BigDecimal("0.5E+1")).movePointRight(-10).toString()).equals("5E-10"), "mpr036"); |
|
2140 |
|
2141 return;} |
|
2142 /* ----------------------------------------------------------------- */ |
|
2143 |
|
2144 /** Test the {@link BigDecimal#scale} method. */ |
|
2145 |
|
2146 public void diagscale(TestHarness harness){ |
|
2147 harness.check (((new BigDecimal("-1")).scale())==0, "sca001"); |
|
2148 harness.check (((new BigDecimal("-10")).scale())==0, "sca002"); |
|
2149 harness.check (((new BigDecimal("+1")).scale())==0, "sca003"); |
|
2150 harness.check (((new BigDecimal("+10")).scale())==0, "sca004"); |
|
2151 harness.check (((new BigDecimal("1E+10")).scale())==-10, "sca005"); |
|
2152 harness.check (((new BigDecimal("1E-10")).scale())==10, "sca006"); |
|
2153 harness.check (((new BigDecimal("0E-10")).scale())==10, "sca007"); |
|
2154 harness.check (((new BigDecimal("0.000")).scale())==3, "sca008"); |
|
2155 harness.check (((new BigDecimal("0.00")).scale())==2, "sca009"); |
|
2156 harness.check (((new BigDecimal("0.0")).scale())==1, "sca010"); |
|
2157 harness.check (((new BigDecimal("0.1")).scale())==1, "sca011"); |
|
2158 harness.check (((new BigDecimal("0.12")).scale())==2, "sca012"); |
|
2159 harness.check (((new BigDecimal("0.123")).scale())==3, "sca013"); |
|
2160 harness.check (((new BigDecimal("-0.0")).scale())==1, "sca014"); |
|
2161 harness.check (((new BigDecimal("-0.1")).scale())==1, "sca015"); |
|
2162 harness.check (((new BigDecimal("-0.12")).scale())==2, "sca016"); |
|
2163 harness.check (((new BigDecimal("-0.123")).scale())==3, "sca017"); |
|
2164 return;} |
|
2165 |
|
2166 /* ----------------------------------------------------------------- */ |
|
2167 |
|
2168 /** Test the {@link BigDecimal#setScale} method. */ |
|
2169 |
|
2170 public void diagsetscale(TestHarness harness){ |
|
2171 boolean flag=false; |
|
2172 java.lang.RuntimeException e=null; |
|
2173 |
|
2174 harness.check (((new BigDecimal("-1")).setScale(0).toString()).equals("-1"), "ssc001"); |
|
2175 harness.check (((new BigDecimal("-1")).setScale(1).toString()).equals("-1.0"), "ssc002"); |
|
2176 harness.check (((new BigDecimal("-1")).setScale(2).toString()).equals("-1.00"), "ssc003"); |
|
2177 harness.check (((new BigDecimal("0")).setScale(0).toString()).equals("0"), "ssc004"); |
|
2178 harness.check (((new BigDecimal("0")).setScale(1).toString()).equals("0.0"), "ssc005"); |
|
2179 harness.check (((new BigDecimal("0")).setScale(2).toString()).equals("0.00"), "ssc006"); |
|
2180 harness.check (((new BigDecimal("+1")).setScale(0).toString()).equals("1"), "ssc007"); |
|
2181 harness.check (((new BigDecimal("+1")).setScale(1).toString()).equals("1.0"), "ssc008"); |
|
2182 harness.check (((new BigDecimal("+1")).setScale(2).toString()).equals("1.00"), "ssc009"); |
|
2183 |
|
2184 try{checkscale:do{ |
|
2185 (new BigDecimal(1)).setScale(-8); |
|
2186 flag=false; |
|
2187 }while(false);} |
|
2188 catch (java.lang.ArithmeticException xx117){e=xx117; |
|
2189 flag=checkMessage(e, "Negative scale: -8"); |
|
2190 }/*checkscale*/ |
|
2191 harness.check (flag, "ssc100"); |
|
2192 try{checkrunn:do{ |
|
2193 (new BigDecimal(1.0001D)).setScale(3); |
|
2194 flag=false; |
|
2195 }while(false);} |
|
2196 catch (java.lang.ArithmeticException xx118){e=xx118; |
|
2197 flag=checkMessage(e, "Rounding necessary"); |
|
2198 }/*checkrunn*/ |
|
2199 harness.check (flag, "ssc101"); |
|
2200 try{checkrunn:do{ |
|
2201 (new BigDecimal(1E-8D)).setScale(3); |
|
2202 flag=false; |
|
2203 }while(false);} |
|
2204 catch (java.lang.ArithmeticException xx119){e=xx119; |
|
2205 flag=checkMessage(e, "Rounding necessary"); |
|
2206 }/*checkrunn*/ |
|
2207 harness.check (flag, "ssc102"); |
|
2208 return;} |
|
2209 |
|
2210 /* ----------------------------------------------------------------- */ |
|
2211 |
|
2212 /** Test the <code>BigDecimal.shortValue()</code> method. */ |
|
2213 |
|
2214 public void diagshortvalue(TestHarness harness){ |
|
2215 boolean flag=false; |
|
2216 java.lang.String v=null; |
|
2217 java.lang.ArithmeticException ae=null; |
|
2218 java.lang.String badstrings[]; |
|
2219 int i=0; |
|
2220 java.lang.String norm=null; |
|
2221 |
|
2222 harness.check ((((short)0))==((new BigDecimal("0")).shortValue()), "shv002"); |
|
2223 harness.check ((((short)1))==((new BigDecimal("1")).shortValue()), "shv003"); |
|
2224 harness.check ((((short)99))==((new BigDecimal("99")).shortValue()), "shv004"); |
|
2225 harness.check (((smax))==((new BigDecimal(smax)).shortValue()), "shv006"); |
|
2226 harness.check (((smin))==((new BigDecimal(smin)).shortValue()), "shv007"); |
|
2227 harness.check (((sneg))==((new BigDecimal(sneg)).shortValue()), "shv008"); |
|
2228 harness.check (((szer))==((new BigDecimal(szer)).shortValue()), "shv009"); |
|
2229 harness.check (((spos))==((new BigDecimal(spos)).shortValue()), "shv010"); |
|
2230 harness.check (((smin))==((new BigDecimal(smax+1)).shortValue()), "shv011"); |
|
2231 harness.check (((smax))==((new BigDecimal(smin-1)).shortValue()), "shv012"); |
|
2232 |
|
2233 return;} |
|
2234 |
|
2235 /* ----------------------------------------------------------------- */ |
|
2236 |
|
2237 /** Test the {@link BigDecimal#signum} method. */ |
|
2238 |
|
2239 public void diagsignum(TestHarness harness){ |
|
2240 // necessarily checks some obscure constructions, too |
|
2241 harness.check ((-1)==((new BigDecimal("-1")).signum()), "sig001"); |
|
2242 harness.check ((-1)==((new BigDecimal("-0.0010")).signum()), "sig002"); |
|
2243 harness.check ((-1)==((new BigDecimal("-0.001")).signum()), "sig003"); |
|
2244 harness.check (0==((new BigDecimal("-0.00")).signum()), "sig004"); |
|
2245 harness.check (0==((new BigDecimal("-0")).signum()), "sig005"); |
|
2246 harness.check (0==((new BigDecimal("0")).signum()), "sig006"); |
|
2247 harness.check (0==((new BigDecimal("00")).signum()), "sig007"); |
|
2248 harness.check (0==((new BigDecimal("00.0")).signum()), "sig008"); |
|
2249 harness.check (1==((new BigDecimal("00.01")).signum()), "sig009"); |
|
2250 harness.check (1==((new BigDecimal("00.01")).signum()), "sig010"); |
|
2251 harness.check (1==((new BigDecimal("00.010")).signum()), "sig011"); |
|
2252 harness.check (1==((new BigDecimal("01.01")).signum()), "sig012"); |
|
2253 harness.check (1==((new BigDecimal("+0.01")).signum()), "sig013"); |
|
2254 harness.check (1==((new BigDecimal("+0.001")).signum()), "sig014"); |
|
2255 harness.check (1==((new BigDecimal("1")).signum()), "sig015"); |
|
2256 harness.check (1==((new BigDecimal("1e+12")).signum()), "sig016"); |
|
2257 harness.check (0==((new BigDecimal("00e+12")).signum()), "sig017"); |
|
2258 return;} |
|
2259 |
|
2260 /* ----------------------------------------------------------------- */ |
|
2261 |
|
2262 /** Test the {@link BigDecimal#toBigInteger} method. */ |
|
2263 |
|
2264 public void diagtobiginteger(TestHarness harness){ |
|
2265 boolean flag=false; |
|
2266 java.lang.String badstrings[]; |
|
2267 int i=0; |
|
2268 harness.check (((new BigDecimal("-1")).toBigInteger().toString()).equals("-1"), "tbi001"); |
|
2269 harness.check (((new BigDecimal("0")).toBigInteger().toString()).equals("0"), "tbi002"); |
|
2270 harness.check (((new BigDecimal("+1")).toBigInteger().toString()).equals("1"), "tbi003"); |
|
2271 harness.check (((new BigDecimal("10")).toBigInteger().toString()).equals("10"), "tbi004"); |
|
2272 harness.check (((new BigDecimal("1000")).toBigInteger().toString()).equals("1000"), "tbi005"); |
|
2273 harness.check (((new BigDecimal("-1E+0")).toBigInteger().toString()).equals("-1"), "tbi006"); |
|
2274 harness.check (((new BigDecimal("0E+0")).toBigInteger().toString()).equals("0"), "tbi007"); |
|
2275 harness.check (((new BigDecimal("+1E+0")).toBigInteger().toString()).equals("1"), "tbi008"); |
|
2276 harness.check (((new BigDecimal("10E+0")).toBigInteger().toString()).equals("10"), "tbi009"); |
|
2277 harness.check (((new BigDecimal("1E+3")).toBigInteger().toString()).equals("1000"), "tbi010"); |
|
2278 harness.check (((new BigDecimal("0.00")).toBigInteger().toString()).equals("0"), "tbi011"); |
|
2279 harness.check (((new BigDecimal("0.01")).toBigInteger().toString()).equals("0"), "tbi012"); |
|
2280 harness.check (((new BigDecimal("0.0")).toBigInteger().toString()).equals("0"), "tbi013"); |
|
2281 harness.check (((new BigDecimal("0.1")).toBigInteger().toString()).equals("0"), "tbi014"); |
|
2282 harness.check (((new BigDecimal("-0.00")).toBigInteger().toString()).equals("0"), "tbi015"); |
|
2283 harness.check (((new BigDecimal("-0.01")).toBigInteger().toString()).equals("0"), "tbi016"); |
|
2284 harness.check (((new BigDecimal("-0.0")).toBigInteger().toString()).equals("0"), "tbi017"); |
|
2285 harness.check (((new BigDecimal("-0.1")).toBigInteger().toString()).equals("0"), "tbi018"); |
|
2286 harness.check (((new BigDecimal("1.00")).toBigInteger().toString()).equals("1"), "tbi019"); |
|
2287 harness.check (((new BigDecimal("1.01")).toBigInteger().toString()).equals("1"), "tbi020"); |
|
2288 harness.check (((new BigDecimal("1.0")).toBigInteger().toString()).equals("1"), "tbi021"); |
|
2289 harness.check (((new BigDecimal("1.1")).toBigInteger().toString()).equals("1"), "tbi022"); |
|
2290 harness.check (((new BigDecimal("-1.00")).toBigInteger().toString()).equals("-1"), "tbi023"); |
|
2291 harness.check (((new BigDecimal("-1.01")).toBigInteger().toString()).equals("-1"), "tbi024"); |
|
2292 harness.check (((new BigDecimal("-1.0")).toBigInteger().toString()).equals("-1"), "tbi025"); |
|
2293 harness.check (((new BigDecimal("-1.1")).toBigInteger().toString()).equals("-1"), "tbi026"); |
|
2294 harness.check (((new BigDecimal("-111.111")).toBigInteger().toString()).equals("-111"), "tbi027"); |
|
2295 harness.check (((new BigDecimal("+111.111")).toBigInteger().toString()).equals("111"), "tbi028"); |
|
2296 harness.check (((new BigDecimal("0.09")).toBigInteger().toString()).equals("0"), "tbi029"); |
|
2297 harness.check (((new BigDecimal("0.9")).toBigInteger().toString()).equals("0"), "tbi030"); |
|
2298 harness.check (((new BigDecimal("1.09")).toBigInteger().toString()).equals("1"), "tbi031"); |
|
2299 harness.check (((new BigDecimal("1.05")).toBigInteger().toString()).equals("1"), "tbi032"); |
|
2300 harness.check (((new BigDecimal("1.04")).toBigInteger().toString()).equals("1"), "tbi033"); |
|
2301 harness.check (((new BigDecimal("1.99")).toBigInteger().toString()).equals("1"), "tbi034"); |
|
2302 harness.check (((new BigDecimal("1.9")).toBigInteger().toString()).equals("1"), "tbi034"); |
|
2303 harness.check (((new BigDecimal("1.5")).toBigInteger().toString()).equals("1"), "tbi035"); |
|
2304 harness.check (((new BigDecimal("1.4")).toBigInteger().toString()).equals("1"), "tbi036"); |
|
2305 harness.check (((new BigDecimal("-1.09")).toBigInteger().toString()).equals("-1"), "tbi037"); |
|
2306 harness.check (((new BigDecimal("-1.05")).toBigInteger().toString()).equals("-1"), "tbi038"); |
|
2307 harness.check (((new BigDecimal("-1.04")).toBigInteger().toString()).equals("-1"), "tbi039"); |
|
2308 harness.check (((new BigDecimal("-1.99")).toBigInteger().toString()).equals("-1"), "tbi040"); |
|
2309 harness.check (((new BigDecimal("-1.9")).toBigInteger().toString()).equals("-1"), "tbi041"); |
|
2310 harness.check (((new BigDecimal("-1.5")).toBigInteger().toString()).equals("-1"), "tbi042"); |
|
2311 harness.check (((new BigDecimal("-1.4")).toBigInteger().toString()).equals("-1"), "tbi043"); |
|
2312 harness.check (((new BigDecimal("1E-1000")).toBigInteger().toString()).equals("0"), "tbi044"); |
|
2313 harness.check (((new BigDecimal("-1E-1000")).toBigInteger().toString()).equals("0"), "tbi045"); |
|
2314 |
|
2315 return;} |
|
2316 |
|
2317 /* ----------------------------------------------------------------- */ |
|
2318 |
|
2319 /** Test the {@link BigDecimal#toString} method. */ |
|
2320 |
|
2321 public void diagtostring(TestHarness harness){ |
|
2322 java.lang.String str; |
|
2323 char car[]; |
|
2324 BigDecimal d; |
|
2325 char ca[]; |
|
2326 java.lang.String cs; |
|
2327 // the function of this has been tested above, this is simply an |
|
2328 // existence proof and type-check |
|
2329 str="123.45"; |
|
2330 d=new BigDecimal(str); |
|
2331 cs=d.toString(); |
|
2332 harness.check ((str.length())==(cs.length()), "tos002"); |
|
2333 harness.check (str.equals((java.lang.Object)cs), "tos004"); |
|
2334 harness.check ((cs instanceof java.lang.String), "tos005"); |
|
2335 harness.check ((d.toString() instanceof java.lang.String), "tos006"); |
|
2336 return;} |
|
2337 |
|
2338 /* ----------------------------------------------------------------- */ |
|
2339 |
|
2340 /** Test the {@link BigDecimal#valueOf} method [long and double]. */ |
|
2341 |
|
2342 public void diagvalueof(TestHarness harness){ |
|
2343 boolean flag=false; |
|
2344 java.lang.NumberFormatException e=null; |
|
2345 double dzer; |
|
2346 double dpos; |
|
2347 double dneg; |
|
2348 double dpos5; |
|
2349 double dneg5; |
|
2350 double dmin; |
|
2351 double dmax; |
|
2352 double d; |
|
2353 |
|
2354 // valueOf(long [,scale]) -- |
|
2355 |
|
2356 harness.check ((BigDecimal.valueOf((long)((byte)-2)).toString()).equals("-2"), "val001"); |
|
2357 harness.check ((BigDecimal.valueOf((long)((byte)-1)).toString()).equals("-1"), "val002"); |
|
2358 harness.check ((BigDecimal.valueOf((long)((byte)-0)).toString()).equals("0"), "val003"); |
|
2359 harness.check ((BigDecimal.valueOf((long)((byte)+1)).toString()).equals("1"), "val004"); |
|
2360 harness.check ((BigDecimal.valueOf((long)((byte)+2)).toString()).equals("2"), "val005"); |
|
2361 harness.check ((BigDecimal.valueOf((long)((byte)10)).toString()).equals("10"), "val006"); |
|
2362 harness.check ((BigDecimal.valueOf((long)((byte)11)).toString()).equals("11"), "val007"); |
|
2363 harness.check ((BigDecimal.valueOf(lmin).toString()).equals("-9223372036854775808"), "val008"); |
|
2364 harness.check ((BigDecimal.valueOf(lmax).toString()).equals("9223372036854775807"), "val009"); |
|
2365 harness.check ((BigDecimal.valueOf(lneg).toString()).equals("-1"), "val010"); |
|
2366 harness.check ((BigDecimal.valueOf(lzer).toString()).equals("0"), "val011"); |
|
2367 harness.check ((BigDecimal.valueOf(lpos).toString()).equals("1"), "val012"); |
|
2368 harness.check ((BigDecimal.valueOf(lmin,0).toString()).equals("-9223372036854775808"), "val013"); |
|
2369 harness.check ((BigDecimal.valueOf(lmax,0).toString()).equals("9223372036854775807"), "val014"); |
|
2370 harness.check ((BigDecimal.valueOf(lneg,0).toString()).equals("-1"), "val015"); |
|
2371 harness.check ((BigDecimal.valueOf(lpos,0).toString()).equals("1"), "val016"); |
|
2372 |
|
2373 harness.check ((BigDecimal.valueOf(lzer,0).toString()).equals("0"), "val017"); |
|
2374 harness.check ((BigDecimal.valueOf(lzer,1).toString()).equals("0.0"), "val018"); |
|
2375 harness.check ((BigDecimal.valueOf(lzer,2).toString()).equals("0.00"), "val019"); |
|
2376 harness.check ((BigDecimal.valueOf(lzer,3).toString()).equals("0.000"), "val020"); |
|
2377 harness.check ((BigDecimal.valueOf(lzer,10).toString()).equals("0E-10"), "val021"); |
|
2378 |
|
2379 harness.check ((BigDecimal.valueOf(lmin,7).toString()).equals("-922337203685.4775808"), "val022"); |
|
2380 harness.check ((BigDecimal.valueOf(lmax,11).toString()).equals("92233720.36854775807"), "val023"); |
|
2381 |
|
2382 return;} |
|
2383 |
|
2384 |
|
2385 /* ----------------------------------------------------------------- */ |
|
2386 /* right - Utility to do a 'right' on a Java String */ |
|
2387 /* ----------------------------------------------------------------- */ |
|
2388 /* Arg1 is string to right-justify */ |
|
2389 /* Arg2 is desired length */ |
|
2390 |
|
2391 private static java.lang.String right(java.lang.String s,int len){ |
|
2392 int slen; |
|
2393 slen=s.length(); |
|
2394 if (slen==len) |
|
2395 return s; // length just right |
|
2396 if (slen>len) |
|
2397 return s.substring(slen-len); // truncate on left |
|
2398 // too short |
|
2399 return (new java.lang.String(new char[len-slen])).replace('\000',' ').concat(s); |
|
2400 } |
|
2401 |
|
2402 /* ----------------------------------------------------------------- */ |
|
2403 /* left - Utility to do a 'left' on a Java String */ |
|
2404 /* ----------------------------------------------------------------- */ |
|
2405 /* Arg1 is string to left-justify */ |
|
2406 /* Arg2 is desired length */ |
|
2407 |
|
2408 private static java.lang.String left(java.lang.String s,int len){ |
|
2409 int slen; |
|
2410 slen=s.length(); |
|
2411 if (slen==len) |
|
2412 return s; // length just right |
|
2413 if (slen>len) |
|
2414 return s.substring(0,len); // truncate on right |
|
2415 // too short |
|
2416 return s.concat((new java.lang.String(new char[len-slen])).replace('\000',' ')); |
|
2417 } |
|
2418 |
|
2419 /* ----------------------------------------------------------------- */ |
|
2420 /* say - Utility to do a display */ |
|
2421 /* ----------------------------------------------------------------- */ |
|
2422 /* Arg1 is string to display, omitted if none */ |
|
2423 /* [null or omitted gives blank line] */ |
|
2424 // this version doesn't heed continuation final character |
|
2425 |
|
2426 private void say(TestHarness harness){ |
|
2427 say((java.lang.String)null, harness);return; |
|
2428 } |
|
2429 private void say(java.lang.String s, TestHarness harness){ |
|
2430 if (s==null) |
|
2431 s=" "; |
|
2432 harness.verbose(s); |
|
2433 return; |
|
2434 } |
|
2435 |
|
2436 private boolean checkMessage(Throwable ex, String msg){ |
|
2437 return !CHECK_EXCEPTION_MESSAGES || ex.getMessage().equals(msg); |
|
2438 } |
|
2439 |
|
2440 public void test (TestHarness harness){ |
|
2441 diagrun (harness); |
|
2442 } |
|
2443 } |
|