1 /* 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4160406 4705734 4707389 4826774 4895911 4421494 6358355 7021568 7039369 4396272 27 * @summary Test for Double.parseDouble method and acceptance regex 28 */ 29 package test.java.lang.Double; 30 31 import java.math.BigDecimal; 32 import java.math.BigInteger; 33 import java.util.regex.*; 34 35 import org.testng.annotations.Test; 36 import org.testng.Assert; 37 38 // Android-changed: remove pass/fail counting; migrate to org.testng assertions instead of throws 39 public class ParseDoubleTest { 40 41 private static final BigDecimal HALF = BigDecimal.valueOf(0.5); 42 fail(String val, double n)43 private static void fail(String val, double n) { 44 Assert.fail("Double.parseDouble failed. String:" + val + " Result:" + n); 45 } 46 check(String val)47 private static void check(String val) { 48 double n = Double.parseDouble(val); 49 boolean isNegativeN = n < 0 || n == 0 && 1/n < 0; 50 double na = Math.abs(n); 51 String s = val.trim().toLowerCase(); 52 switch (s.charAt(s.length() - 1)) { 53 case 'd': 54 case 'f': 55 s = s.substring(0, s.length() - 1); 56 break; 57 } 58 boolean isNegative = false; 59 if (s.charAt(0) == '+') { 60 s = s.substring(1); 61 } else if (s.charAt(0) == '-') { 62 s = s.substring(1); 63 isNegative = true; 64 } 65 if (s.equals("nan")) { 66 if (!Double.isNaN(n)) { 67 fail(val, n); 68 } 69 return; 70 } 71 if (Double.isNaN(n)) { 72 fail(val, n); 73 } 74 if (isNegativeN != isNegative) 75 fail(val, n); 76 if (s.equals("infinity")) { 77 if (na != Double.POSITIVE_INFINITY) { 78 fail(val, n); 79 } 80 return; 81 } 82 BigDecimal bd; 83 if (s.startsWith("0x")) { 84 s = s.substring(2); 85 int indP = s.indexOf('p'); 86 long exp = Long.parseLong(s.substring(indP + 1)); 87 int indD = s.indexOf('.'); 88 String significand; 89 if (indD >= 0) { 90 significand = s.substring(0, indD) + s.substring(indD + 1, indP); 91 exp -= 4*(indP - indD - 1); 92 } else { 93 significand = s.substring(0, indP); 94 } 95 bd = new BigDecimal(new BigInteger(significand, 16)); 96 if (exp >= 0) { 97 bd = bd.multiply(BigDecimal.valueOf(2).pow((int)exp)); 98 } else { 99 bd = bd.divide(BigDecimal.valueOf(2).pow((int)-exp)); 100 } 101 } else { 102 bd = new BigDecimal(s); 103 } 104 BigDecimal l, u; 105 if (Double.isInfinite(na)) { 106 l = new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(Math.ulp(Double.MAX_VALUE)).multiply(HALF)); 107 u = null; 108 } else { 109 l = new BigDecimal(na).subtract(new BigDecimal(Math.ulp(Math.nextUp(-na))).multiply(HALF)); 110 u = new BigDecimal(na).add(new BigDecimal(Math.ulp(n)).multiply(HALF)); 111 } 112 int cmpL = bd.compareTo(l); 113 int cmpU = u != null ? bd.compareTo(u) : -1; 114 if ((Double.doubleToLongBits(n) & 1) != 0) { 115 if (cmpL <= 0 || cmpU >= 0) { 116 fail(val, n); 117 } 118 } else { 119 if (cmpL < 0 || cmpU > 0) { 120 fail(val, n); 121 } 122 } 123 } 124 check(String val, double expected)125 private static void check(String val, double expected) { 126 double n = Double.parseDouble(val); 127 if (n != expected) 128 fail(val, n); 129 check(val); 130 } 131 132 @Test rudimentaryTest()133 public void rudimentaryTest() { 134 check(new String(""+Double.MIN_VALUE), Double.MIN_VALUE); 135 check(new String(""+Double.MAX_VALUE), Double.MAX_VALUE); 136 137 check("10", (double) 10.0); 138 check("10.0", (double) 10.0); 139 check("10.01", (double) 10.01); 140 141 check("-10", (double) -10.0); 142 check("-10.00", (double) -10.0); 143 check("-10.01", (double) -10.01); 144 } 145 146 147 static String[] badStrings = { 148 "", 149 "+", 150 "-", 151 "+e", 152 "-e", 153 "+e170", 154 "-e170", 155 156 // Make sure intermediate white space is not deleted. 157 "1234 e10", 158 "-1234 e10", 159 160 // Control characters in the interior of a string are not legal 161 "1\u0007e1", 162 "1e\u00071", 163 164 // NaN and infinity can't have trailing type suffices or exponents 165 "NaNf", 166 "NaNF", 167 "NaNd", 168 "NaND", 169 "-NaNf", 170 "-NaNF", 171 "-NaNd", 172 "-NaND", 173 "+NaNf", 174 "+NaNF", 175 "+NaNd", 176 "+NaND", 177 "Infinityf", 178 "InfinityF", 179 "Infinityd", 180 "InfinityD", 181 "-Infinityf", 182 "-InfinityF", 183 "-Infinityd", 184 "-InfinityD", 185 "+Infinityf", 186 "+InfinityF", 187 "+Infinityd", 188 "+InfinityD", 189 190 "NaNe10", 191 "-NaNe10", 192 "+NaNe10", 193 "Infinitye10", 194 "-Infinitye10", 195 "+Infinitye10", 196 197 // Non-ASCII digits are not recognized 198 // Android-removed: non-ASCII digits tests 199 // "\u0661e\u0661", // 1e1 in Arabic-Indic digits 200 // "\u06F1e\u06F1", // 1e1 in Extended Arabic-Indic digits 201 // "\u0967e\u0967", // 1e1 in Devanagari digits 202 203 // JCK test lex03592m3 204 ".", 205 206 // JCK test lex03592m4 207 "e42", 208 209 // JCK test lex03592m5 210 ".e42", 211 212 // JCK test lex03592m6 213 "d", 214 215 // JCK test lex03592m7 216 ".d", 217 218 // JCK test lex03592m8 219 "e42d", 220 221 // JCK test lex03592m9 222 ".e42d", 223 224 // JCK test lex03593m10 225 "1A01.01125e-10d", 226 227 // JCK test lex03593m11 228 "2;3.01125e-10d", 229 230 // JCK test lex03593m12 231 "1_34.01125e-10d", 232 233 // JCK test lex03593m14 234 "202..01125e-10d", 235 236 // JCK test lex03593m15 237 "202,01125e-10d", 238 239 // JCK test lex03593m16 240 "202.03b4e-10d", 241 242 // JCK test lex03593m18 243 "202.06_3e-10d", 244 245 // JCK test lex03593m20 246 "202.01125e-f0d", 247 248 // JCK test lex03593m21 249 "202.01125e_3d", 250 251 // JCK test lex03593m22 252 "202.01125e -5d", 253 254 // JCK test lex03593m24 255 "202.01125e-10r", 256 257 // JCK test lex03593m25 258 "202.01125e-10ff", 259 260 // JCK test lex03593m26 261 "1234L.01", 262 263 // JCK test lex03593m27 264 "12ee-2", 265 266 // JCK test lex03593m28 267 "12e-2.2.2", 268 269 // JCK test lex03593m29 270 "12.01e+", 271 272 // JCK test lex03593m30 273 "12.01E", 274 275 // Bad hexadecimal-style strings 276 277 // Two leading zeros 278 "00x1.0p1", 279 280 // Must have hex specifier 281 "1.0p1", 282 "00010p1", 283 "deadbeefp1", 284 285 // Need an explicit fully-formed exponent 286 "0x1.0p", 287 "0x1.0", 288 289 // Exponent must be in decimal 290 "0x1.0pa", 291 "0x1.0pf", 292 293 // Exponent separated by "p" 294 "0x1.0e22", 295 "0x1.0e22", 296 297 // Need a signifcand 298 "0xp22" 299 }; 300 301 static String[] goodStrings = { 302 "NaN", 303 "+NaN", 304 "-NaN", 305 "Infinity", 306 "+Infinity", 307 "-Infinity", 308 "1.1e-23f", 309 ".1e-23f", 310 "1e-23", 311 "1f", 312 "0", 313 "-0", 314 "+0", 315 "00", 316 "00", 317 "-00", 318 "+00", 319 "0000000000", 320 "-0000000000", 321 "+0000000000", 322 "1", 323 "2", 324 "1234", 325 "-1234", 326 "+1234", 327 "2147483647", // Integer.MAX_VALUE 328 "2147483648", 329 "-2147483648", // Integer.MIN_VALUE 330 "-2147483649", 331 332 "16777215", 333 "16777216", // 2^24 334 "16777217", 335 336 "-16777215", 337 "-16777216", // -2^24 338 "-16777217", 339 340 "9007199254740991", 341 "9007199254740992", // 2^53 342 "9007199254740993", 343 344 "-9007199254740991", 345 "-9007199254740992", // -2^53 346 "-9007199254740993", 347 348 "9223372036854775807", 349 "9223372036854775808", // Long.MAX_VALUE 350 "9223372036854775809", 351 352 "-9223372036854775808", 353 "-9223372036854775809", // Long.MIN_VALUE 354 "-9223372036854775810", 355 356 // Culled from JCK test lex03591m1 357 "54.07140d", 358 "7.01e-324d", 359 "2147483647.01d", 360 "1.2147483647f", 361 "000000000000000000000000001.F", 362 "1.00000000000000000000000000e-2F", 363 364 // Culled from JCK test lex03592m2 365 "2.", 366 ".0909", 367 "122112217090.0", 368 "7090e-5", 369 "2.E-20", 370 ".0909e42", 371 "122112217090.0E+100", 372 "7090f", 373 "2.F", 374 ".0909d", 375 "122112217090.0D", 376 "7090e-5f", 377 "2.E-20F", 378 ".0909e42d", 379 "122112217090.0E+100D", 380 381 // Culled from JCK test lex03594m31 -- unicode escapes 382 "\u0035\u0031\u0034\u0039\u0032\u0033\u0036\u0037\u0038\u0030.1102E-209D", 383 "1290873\u002E12301e100", 384 "1.1E-10\u0066", 385 386 // Culled from JCK test lex03595m1 387 "0.0E-10", 388 "1E10", 389 390 // Culled from JCK test lex03691m1 391 "0.f", 392 "1f", 393 "0.F", 394 "1F", 395 "0.12d", 396 "1e-0d", 397 "12.e+1D", 398 "0e-0D", 399 "12.e+01", 400 "1e-01", 401 402 // Good hex strings 403 // Vary capitalization of separators. 404 405 "0x1p1", 406 "0X1p1", 407 "0x1P1", 408 "0X1P1", 409 "0x1p1f", 410 "0X1p1f", 411 "0x1P1f", 412 "0X1P1f", 413 "0x1p1F", 414 "0X1p1F", 415 "0x1P1F", 416 "0X1P1F", 417 "0x1p1d", 418 "0X1p1d", 419 "0x1P1d", 420 "0X1P1d", 421 "0x1p1D", 422 "0X1p1D", 423 "0x1P1D", 424 "0X1P1D", 425 426 "-0x1p1", 427 "-0X1p1", 428 "-0x1P1", 429 "-0X1P1", 430 "-0x1p1f", 431 "-0X1p1f", 432 "-0x1P1f", 433 "-0X1P1f", 434 "-0x1p1F", 435 "-0X1p1F", 436 "-0x1P1F", 437 "-0X1P1F", 438 "-0x1p1d", 439 "-0X1p1d", 440 "-0x1P1d", 441 "-0X1P1d", 442 "-0x1p1D", 443 "-0X1p1D", 444 "-0x1P1D", 445 "-0X1P1D", 446 447 "0x1p-1", 448 "0X1p-1", 449 "0x1P-1", 450 "0X1P-1", 451 "0x1p-1f", 452 "0X1p-1f", 453 "0x1P-1f", 454 "0X1P-1f", 455 "0x1p-1F", 456 "0X1p-1F", 457 "0x1P-1F", 458 "0X1P-1F", 459 "0x1p-1d", 460 "0X1p-1d", 461 "0x1P-1d", 462 "0X1P-1d", 463 "0x1p-1D", 464 "0X1p-1D", 465 "0x1P-1D", 466 "0X1P-1D", 467 468 "-0x1p-1", 469 "-0X1p-1", 470 "-0x1P-1", 471 "-0X1P-1", 472 "-0x1p-1f", 473 "-0X1p-1f", 474 "-0x1P-1f", 475 "-0X1P-1f", 476 "-0x1p-1F", 477 "-0X1p-1F", 478 "-0x1P-1F", 479 "-0X1P-1F", 480 "-0x1p-1d", 481 "-0X1p-1d", 482 "-0x1P-1d", 483 "-0X1P-1d", 484 "-0x1p-1D", 485 "-0X1p-1D", 486 "-0x1P-1D", 487 "-0X1P-1D", 488 489 490 // Try different significand combinations 491 "0xap1", 492 "0xbp1", 493 "0xcp1", 494 "0xdp1", 495 "0xep1", 496 "0xfp1", 497 498 "0x1p1", 499 "0x.1p1", 500 "0x1.1p1", 501 502 "0x001p23", 503 "0x00.1p1", 504 "0x001.1p1", 505 506 "0x100p1", 507 "0x.100p1", 508 "0x1.100p1", 509 510 "0x00100p1", 511 "0x00.100p1", 512 "0x001.100p1", 513 514 // Limits 515 516 "1.7976931348623157E308", // Double.MAX_VALUE 517 "4.9e-324", // Double.MIN_VALUE 518 "2.2250738585072014e-308", // Double.MIN_NORMAL 519 520 "2.2250738585072012e-308", // near Double.MIN_NORMAL 521 522 "1.7976931348623158e+308", // near MAX_VALUE + ulp(MAX_VALUE)/2 523 "1.7976931348623159e+308", // near MAX_VALUE + ulp(MAX_VALUE) 524 525 "2.4703282292062329e-324", // above MIN_VALUE/2 526 "2.4703282292062327e-324", // MIN_VALUE/2 527 "2.4703282292062325e-324", // below MIN_VALUE/2 528 529 // 1e308 with leading zeros 530 531 "0.0000000000001e321", 532 "00.000000000000000001e326", 533 "00000.000000000000000001e326", 534 "000.0000000000000000001e327", 535 "0.00000000000000000001e328", 536 }; 537 538 static String[] paddedBadStrings; 539 static String[] paddedGoodStrings; 540 static { 541 String pad = " \t\n\r\f\u0001\u000b\u001f"; 542 paddedBadStrings = new String[badStrings.length]; 543 for(int i = 0 ; i < badStrings.length; i++) 544 paddedBadStrings[i] = pad + badStrings[i] + pad; 545 546 paddedGoodStrings = new String[goodStrings.length]; 547 for(int i = 0 ; i < goodStrings.length; i++) 548 paddedGoodStrings[i] = pad + goodStrings[i] + pad; 549 550 } 551 552 553 /* 554 * Throws an exception if <code>Input</code> is 555 * <code>exceptionalInput</code> and {@link Double.parseDouble 556 * parseDouble} does <em>not</em> throw an exception or if 557 * <code>Input</code> is not <code>exceptionalInput</code> and 558 * <code>parseDouble</code> throws an exception. This method does 559 * not attempt to test whether the string is converted to the 560 * proper value; just whether the input is accepted appropriately 561 * or not. 562 */ testParsing(String [] input, boolean exceptionalInput)563 private static void testParsing(String [] input, boolean exceptionalInput) { 564 for(int i = 0; i < input.length; i++) { 565 double d; 566 567 try { 568 d = Double.parseDouble(input[i]); 569 check(input[i]); 570 } 571 catch (NumberFormatException e) { 572 if (! exceptionalInput) { 573 Assert.fail("Double.parseDouble rejected good string `" + input[i] + "'."); 574 } 575 break; 576 } 577 if (exceptionalInput) { 578 Assert.fail("Double.parseDouble accepted bad string `" + input[i] + "'."); 579 } 580 } 581 } 582 583 /* 584 * Throws an exception if <code>Input</code> is 585 * <code>exceptionalInput</code> and the regular expression 586 * matches one of the strings or if <code>Input</code> is not 587 * <code>exceptionalInput</code> and the regular expression fails 588 * to match an input string. 589 */ testRegex(String [] input, boolean exceptionalInput)590 private static void testRegex(String [] input, boolean exceptionalInput) { 591 /* 592 * The regex below is taken from the JavaDoc for 593 * Double.valueOf. 594 */ 595 596 final String Digits = "(\\p{Digit}+)"; 597 final String HexDigits = "(\\p{XDigit}+)"; 598 // an exponent is 'e' or 'E' followed by an optionally 599 // signed decimal integer. 600 final String Exp = "[eE][+-]?"+Digits; 601 final String fpRegex = 602 ("[\\x00-\\x20]*"+ // Optional leading "whitespace" 603 "[+-]?(" + // Optional sign character 604 "NaN|" + // "NaN" string 605 "Infinity|" + // "Infinity" string 606 607 // A floating-point string representing a finite positive 608 // number without a leading sign has at most five basic pieces: 609 // Digits . Digits ExponentPart FloatTypeSuffix 610 // 611 // Since this method allows integer-only strings as input 612 // in addition to strings of floating-point literals, the 613 // two sub-patterns below are simplifications of the grammar 614 // productions from the Java Language Specification, 2nd 615 // edition, section 3.10.2. 616 617 618 // A decimal floating-point string representing a finite positive 619 // number without a leading sign has at most five basic pieces: 620 // Digits . Digits ExponentPart FloatTypeSuffix 621 // 622 // Since this method allows integer-only strings as input 623 // in addition to strings of floating-point literals, the 624 // two sub-patterns below are simplifications of the grammar 625 // productions from the Java Language Specification, 2nd 626 // edition, section 3.10.2. 627 628 // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt 629 "(((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+ 630 631 // . Digits ExponentPart_opt FloatTypeSuffix_opt 632 "(\\.("+Digits+")("+Exp+")?))|"+ 633 634 // Hexadecimal strings 635 "((" + 636 // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt 637 "(0[xX]" + HexDigits + "(\\.)?)|" + 638 639 // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt 640 "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" + 641 642 ")[pP][+-]?" + Digits + "))" + 643 "[fFdD]?))" + 644 "[\\x00-\\x20]*");// Optional trailing "whitespace" 645 Pattern fpPattern = Pattern.compile(fpRegex); 646 647 for(int i = 0; i < input.length; i++) { 648 Matcher m = fpPattern.matcher(input[i]); 649 Assert.assertEquals(m.matches(), ! exceptionalInput, "Regular expression " + 650 (exceptionalInput? 651 "accepted bad": 652 "rejected good") + 653 " string `" + 654 input[i] + "'."); 655 } 656 657 } 658 659 /** 660 * For each subnormal power of two, test at boundaries of 661 * region that should convert to that value. 662 */ 663 @Test testSubnormalPowers()664 public void testSubnormalPowers() { 665 BigDecimal TWO = BigDecimal.valueOf(2); 666 // An ulp is the same for all subnormal values 667 BigDecimal ulp_BD = new BigDecimal(Double.MIN_VALUE); 668 669 // Test subnormal powers of two (except Double.MIN_VALUE) 670 for(int i = -1073; i <= -1022; i++) { 671 double d = Math.scalb(1.0, i); 672 673 /* 674 * The region [d - ulp/2, d + ulp/2] should round to d. 675 */ 676 BigDecimal d_BD = new BigDecimal(d); 677 678 BigDecimal lowerBound = d_BD.subtract(ulp_BD.divide(TWO)); 679 BigDecimal upperBound = d_BD.add(ulp_BD.divide(TWO)); 680 681 double convertedLowerBound = Double.parseDouble(lowerBound.toString()); 682 double convertedUpperBound = Double.parseDouble(upperBound.toString()); 683 Assert.assertEquals(convertedLowerBound, d, 684 String.format("2^%d lowerBound converts as %a %s%n", i, 685 convertedLowerBound, lowerBound)); 686 Assert.assertEquals(convertedUpperBound, d, 687 String.format("2^%d upperBound converts as %a %s%n", 688 i, convertedUpperBound, upperBound)); 689 } 690 /* 691 * Double.MIN_VALUE 692 * The region ]0.5*Double.MIN_VALUE, 1.5*Double.MIN_VALUE[ should round to Double.MIN_VALUE . 693 */ 694 BigDecimal minValue = new BigDecimal(Double.MIN_VALUE); 695 Assert.assertEquals(Double.parseDouble(minValue.multiply(new BigDecimal(0.5)).toString()), 0.0, 696 "0.5*MIN_VALUE doesn't convert 0"); 697 Assert.assertEquals(Double.parseDouble(minValue.multiply(new BigDecimal(0.50000000001)).toString()), Double.MIN_VALUE, 698 "0.50000000001*MIN_VALUE doesn't convert to MIN_VALUE"); 699 Assert.assertEquals(Double.parseDouble(minValue.multiply(new BigDecimal(1.49999999999)).toString()), Double.MIN_VALUE, 700 "1.49999999999*MIN_VALUE doesn't convert to MIN_VALUE"); 701 Assert.assertEquals(Double.parseDouble(minValue.multiply(new BigDecimal(1.5)).toString()), 2*Double.MIN_VALUE, 702 "1.5*MIN_VALUE doesn't convert to 2*MIN_VALUE"); 703 } 704 705 /** 706 * For each power of two, test at boundaries of 707 * region that should convert to that value. 708 */ 709 @Test testPowers()710 public void testPowers() { 711 for(int i = -1074; i <= +1023; i++) { 712 double d = Math.scalb(1.0, i); 713 BigDecimal d_BD = new BigDecimal(d); 714 715 BigDecimal lowerBound = d_BD.subtract(new BigDecimal(Math.ulp(Math.nextUp(-d))).multiply(HALF)); 716 BigDecimal upperBound = d_BD.add(new BigDecimal(Math.ulp(d)).multiply(HALF)); 717 718 check(lowerBound.toString()); 719 check(upperBound.toString()); 720 } 721 check(new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(Math.ulp(Double.MAX_VALUE)).multiply(HALF)).toString()); 722 } 723 724 @Test testStrictness()725 public void testStrictness() { 726 final double expected = 0x0.0000008000000p-1022; 727 // final double expected = 0x0.0000008000001p-1022; 728 double conversion = 0.0; 729 double sum = 0.0; // Prevent conversion from being optimized away 730 731 //2^-1047 + 2^-1075 rounds to 2^-1047 732 String decimal = "6.631236871469758276785396630275967243399099947355303144249971758736286630139265439618068200788048744105960420552601852889715006376325666595539603330361800519107591783233358492337208057849499360899425128640718856616503093444922854759159988160304439909868291973931426625698663157749836252274523485312442358651207051292453083278116143932569727918709786004497872322193856150225415211997283078496319412124640111777216148110752815101775295719811974338451936095907419622417538473679495148632480391435931767981122396703443803335529756003353209830071832230689201383015598792184172909927924176339315507402234836120730914783168400715462440053817592702766213559042115986763819482654128770595766806872783349146967171293949598850675682115696218943412532098591327667236328125E-316"; 733 734 for(int i = 0; i <= 12_000; i++) { 735 conversion = Double.parseDouble(decimal); 736 sum += conversion; 737 // BEGIN Android-changed: replace printf with assert 738 /* 739 if (conversion != expected) { 740 failed = true; 741 System.out.printf("Iteration %d converts as %a%n", 742 i, conversion); 743 } 744 */ 745 Assert.assertEquals(conversion, expected, 746 String.format("Iteration %d converts as %a%n", i, conversion)); 747 } 748 /* 749 System.out.println("Sum = " + sum); 750 if (failed) 751 throw new RuntimeException("Inconsistent conversion"); 752 */ 753 // END Android-changed: replace printf with assert 754 } 755 756 @Test testParsing()757 public void testParsing() { 758 testParsing(goodStrings, false); 759 testParsing(paddedGoodStrings, false); 760 testParsing(badStrings, true); 761 testParsing(paddedBadStrings, true); 762 } 763 764 @Test testRegex()765 public void testRegex() { 766 testRegex(goodStrings, false); 767 testRegex(paddedGoodStrings, false); 768 testRegex(badStrings, true); 769 testRegex(paddedBadStrings, true); 770 } 771 } 772