Path: blob/master/test/jdk/java/text/Format/CompactNumberFormat/TestSpecialValues.java
41153 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 817755225* @summary Checks the formatting and parsing of special values26* @modules jdk.localedata27* @run testng/othervm TestSpecialValues28*/29import java.text.NumberFormat;30import java.text.ParseException;31import java.util.Locale;32import org.testng.annotations.DataProvider;33import org.testng.annotations.Test;3435public class TestSpecialValues {3637private static final NumberFormat FORMAT = NumberFormat38.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);3940@DataProvider(name = "formatSpecialValues")41Object[][] formatSpecialValues() {42return new Object[][]{43// number , formatted ouput44{+0.0, "0"},45{-0.0, "-0"},46{Double.MIN_VALUE, "0"},47{Double.MIN_NORMAL, "0"},48{Double.NaN, "NaN"},49{Double.POSITIVE_INFINITY, "\u221E"},50{Double.NEGATIVE_INFINITY, "-\u221E"},51{Long.MIN_VALUE, "-9223372T"},52{Long.MAX_VALUE, "9223372T"},};53}5455@DataProvider(name = "parseSpecialValues")56Object[][] parseSpecialValues() {57return new Object[][]{58// parse string, parsed number59{"-0.0", -0.0},60{"" + Long.MIN_VALUE, Long.MIN_VALUE},61{"" + Long.MAX_VALUE, Long.MAX_VALUE},62{"NaN", Double.NaN},63{"\u221E", Double.POSITIVE_INFINITY},64{"-\u221E", Double.NEGATIVE_INFINITY},};65}6667@Test(dataProvider = "formatSpecialValues")68public void testFormatSpecialValues(Object number, String expected) {69CompactFormatAndParseHelper.testFormat(FORMAT, number, expected);70}7172@Test(dataProvider = "parseSpecialValues")73public void testParseSpecialValues(String parseString, Number expected)74throws ParseException {75CompactFormatAndParseHelper.testParse(FORMAT, parseString, expected, null, null);76}77}787980