< prev index next >

test/jdk/java/lang/Double/ParseDouble.java

Print this page

  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  */

539 
540         paddedGoodStrings = new String[goodStrings.length];
541         for(int i = 0 ; i <  goodStrings.length; i++)
542             paddedGoodStrings[i] = pad + goodStrings[i] + pad;
543 
544     }
545 
546 
547     /*
548      * Throws an exception if <code>Input</code> is
549      * <code>exceptionalInput</code> and {@link Double.parseDouble
550      * parseDouble} does <em>not</em> throw an exception or if
551      * <code>Input</code> is not <code>exceptionalInput</code> and
552      * <code>parseDouble</code> throws an exception.  This method does
553      * not attempt to test whether the string is converted to the
554      * proper value; just whether the input is accepted appropriately
555      * or not.
556      */
557     private static void testParsing(String [] input,
558                                     boolean exceptionalInput) {
559         for(int i = 0; i < input.length; i++) {
560             double d;
561 
562             try {
563                 d = Double.parseDouble(input[i]);
564                 check(input[i]);
565             }
566             catch (NumberFormatException e) {
567                 if (! exceptionalInput) {
568                     throw new RuntimeException("Double.parseDouble rejected " +
569                                                "good string `" + input[i] +
570                                                "'.");
571                 }
572                 break;
573             }
574             if (exceptionalInput) {
575                 throw new RuntimeException("Double.parseDouble accepted " +
576                                            "bad string `" + input[i] +
577                                            "'.");
578             }
579         }
580     }
581 
582     /*
583      * Throws an exception if <code>Input</code> is
584      * <code>exceptionalInput</code> and the regular expression
585      * matches one of the strings or if <code>Input</code> is not
586      * <code>exceptionalInput</code> and the regular expression fails
587      * to match an input string.
588      */
589     private static void testRegex(String [] input, boolean exceptionalInput) {
590         /*
591          * The regex below is taken from the JavaDoc for
592          * Double.valueOf.
593          */
594 
595         final String Digits     = "(\\p{Digit}+)";
596         final String HexDigits  = "(\\p{XDigit}+)";

  1 /*
  2  * Copyright (c) 2001, 2024, 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  */

539 
540         paddedGoodStrings = new String[goodStrings.length];
541         for(int i = 0 ; i <  goodStrings.length; i++)
542             paddedGoodStrings[i] = pad + goodStrings[i] + pad;
543 
544     }
545 
546 
547     /*
548      * Throws an exception if <code>Input</code> is
549      * <code>exceptionalInput</code> and {@link Double.parseDouble
550      * parseDouble} does <em>not</em> throw an exception or if
551      * <code>Input</code> is not <code>exceptionalInput</code> and
552      * <code>parseDouble</code> throws an exception.  This method does
553      * not attempt to test whether the string is converted to the
554      * proper value; just whether the input is accepted appropriately
555      * or not.
556      */
557     private static void testParsing(String [] input,
558                                     boolean exceptionalInput) {
559         for (String s : input) {


560             try {
561                 Double.parseDouble(s);
562                 check(s);
563             } catch (NumberFormatException e) {
564                 if (!exceptionalInput) {

565                     throw new RuntimeException("Double.parseDouble rejected " +
566                                                "good string `" + s +
567                                                "'.");
568                 }
569                 continue;
570             }
571             if (exceptionalInput) {
572                 throw new RuntimeException("Double.parseDouble accepted " +
573                                            "bad string `" + s +
574                                            "'.");
575             }
576         }
577     }
578 
579     /*
580      * Throws an exception if <code>Input</code> is
581      * <code>exceptionalInput</code> and the regular expression
582      * matches one of the strings or if <code>Input</code> is not
583      * <code>exceptionalInput</code> and the regular expression fails
584      * to match an input string.
585      */
586     private static void testRegex(String [] input, boolean exceptionalInput) {
587         /*
588          * The regex below is taken from the JavaDoc for
589          * Double.valueOf.
590          */
591 
592         final String Digits     = "(\\p{Digit}+)";
593         final String HexDigits  = "(\\p{XDigit}+)";
< prev index next >