test/jdk/java/text/Format/CompactNumberFormat/TestSpecialValues.java
changeset 52869 c5c0db0b7c2f
equal deleted inserted replaced
52868:b4982a22926b 52869:c5c0db0b7c2f
       
     1 /*
       
     2  * Copyright (c) 2018, 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  * @test
       
    25  * @bug 8177552
       
    26  * @summary Checks the formatting and parsing of special values
       
    27  * @modules jdk.localedata
       
    28  * @run testng/othervm TestSpecialValues
       
    29  */
       
    30 import java.text.NumberFormat;
       
    31 import java.text.ParseException;
       
    32 import java.util.Locale;
       
    33 import org.testng.annotations.DataProvider;
       
    34 import org.testng.annotations.Test;
       
    35 
       
    36 public class TestSpecialValues {
       
    37 
       
    38     private static final NumberFormat FORMAT = NumberFormat
       
    39             .getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);
       
    40 
       
    41     @DataProvider(name = "formatSpecialValues")
       
    42     Object[][] formatSpecialValues() {
       
    43         return new Object[][]{
       
    44             // number , formatted ouput
       
    45             {+0.0, "0"},
       
    46             {-0.0, "-0"},
       
    47             {Double.MIN_VALUE, "0"},
       
    48             {Double.MIN_NORMAL, "0"},
       
    49             {Double.NaN, "NaN"},
       
    50             {Double.POSITIVE_INFINITY, "\u221E"},
       
    51             {Double.NEGATIVE_INFINITY, "-\u221E"},
       
    52             {Long.MIN_VALUE, "-9223372T"},
       
    53             {Long.MAX_VALUE, "9223372T"},};
       
    54     }
       
    55 
       
    56     @DataProvider(name = "parseSpecialValues")
       
    57     Object[][] parseSpecialValues() {
       
    58         return new Object[][]{
       
    59             // parse string, parsed number
       
    60             {"-0.0", -0.0},
       
    61             {"" + Long.MIN_VALUE, Long.MIN_VALUE},
       
    62             {"" + Long.MAX_VALUE, Long.MAX_VALUE},
       
    63             {"NaN", Double.NaN},
       
    64             {"\u221E", Double.POSITIVE_INFINITY},
       
    65             {"-\u221E", Double.NEGATIVE_INFINITY},};
       
    66     }
       
    67 
       
    68     @Test(dataProvider = "formatSpecialValues")
       
    69     public void testFormatSpecialValues(Object number, String expected) {
       
    70         CompactFormatAndParseHelper.testFormat(FORMAT, number, expected);
       
    71     }
       
    72 
       
    73     @Test(dataProvider = "parseSpecialValues")
       
    74     public void testParseSpecialValues(String parseString, Number expected)
       
    75             throws ParseException {
       
    76         CompactFormatAndParseHelper.testParse(FORMAT, parseString, expected, null, null);
       
    77     }
       
    78 }