Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Formatter/BasicDouble.java
38811 views
/*1* Copyright (c) 2003, 2013, 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*/2223/* Type-specific source code for unit test24*25* Regenerate the BasicX classes via genBasic.sh whenever this file changes.26* We check in the generated source files so that the test tree can be used27* independently of the rest of the source tree.28*/2930// -- This file was mechanically generated: Do not edit! -- //3132import java.io.*;33import java.math.BigDecimal;34import java.math.BigInteger;35import java.text.DateFormatSymbols;36import java.util.*;3738import sun.misc.DoubleConsts;394041import static java.util.Calendar.*;424344454647public class BasicDouble extends Basic {4849private static void test(String fs, String exp, Object ... args) {50Formatter f = new Formatter(new StringBuilder(), Locale.US);51f.format(fs, args);52ck(fs, exp, f.toString());53}5455private static void test(Locale l, String fs, String exp, Object ... args)56{57Formatter f = new Formatter(new StringBuilder(), l);58f.format(fs, args);59ck(fs, exp, f.toString());60}6162private static void test(String fs, Object ... args) {63Formatter f = new Formatter(new StringBuilder(), Locale.US);64f.format(fs, args);65ck(fs, "fail", f.toString());66}6768private static void test(String fs) {69Formatter f = new Formatter(new StringBuilder(), Locale.US);70f.format(fs, "fail");71ck(fs, "fail", f.toString());72}7374private static void testSysOut(String fs, String exp, Object ... args) {75FileOutputStream fos = null;76FileInputStream fis = null;77try {78PrintStream saveOut = System.out;79fos = new FileOutputStream("testSysOut");80System.setOut(new PrintStream(fos));81System.out.format(Locale.US, fs, args);82fos.close();8384fis = new FileInputStream("testSysOut");85byte [] ba = new byte[exp.length()];86int len = fis.read(ba);87String got = new String(ba);88if (len != ba.length)89fail(fs, exp, got);90ck(fs, exp, got);9192System.setOut(saveOut);93} catch (FileNotFoundException ex) {94fail(fs, ex.getClass());95} catch (IOException ex) {96fail(fs, ex.getClass());97} finally {98try {99if (fos != null)100fos.close();101if (fis != null)102fis.close();103} catch (IOException ex) {104fail(fs, ex.getClass());105}106}107}108109private static void tryCatch(String fs, Class<?> ex) {110boolean caught = false;111try {112test(fs);113} catch (Throwable x) {114if (ex.isAssignableFrom(x.getClass()))115caught = true;116}117if (!caught)118fail(fs, ex);119else120pass();121}122123private static void tryCatch(String fs, Class<?> ex, Object ... args) {124boolean caught = false;125try {126test(fs, args);127} catch (Throwable x) {128if (ex.isAssignableFrom(x.getClass()))129caught = true;130}131if (!caught)132fail(fs, ex);133else134pass();135}136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297private static double create(double v) {298return (double) v;299}300301302private static double negate(double v) {303return -v;304}305306private static double mult(double v, double mul) {307return v * mul;308}309310private static double recip(double v) {311return 1.0 / v;312}313314315316317318319320321322323324325326327328329330331332public static void test() {333TimeZone.setDefault(TimeZone.getTimeZone("GMT-0800"));334335// Any characters not explicitly defined as conversions, date/time336// conversion suffixes, or flags are illegal and are reserved for337// future extensions. Use of such a character in a format string will338// cause an UnknownFormatConversionException or339// UnknownFormatFlagsException to be thrown.340tryCatch("%q", UnknownFormatConversionException.class);341tryCatch("%t&", UnknownFormatConversionException.class);342tryCatch("%&d", UnknownFormatConversionException.class);343tryCatch("%^b", UnknownFormatConversionException.class);344345//---------------------------------------------------------------------346// Formatter.java class javadoc examples347//---------------------------------------------------------------------348test(Locale.FRANCE, "e = %+10.4f", "e = +2,7183", Math.E);349test("%4$2s %3$2s %2$2s %1$2s", " d c b a", "a", "b", "c", "d");350test("Amount gained or lost since last statement: $ %,(.2f",351"Amount gained or lost since last statement: $ (6,217.58)",352(new BigDecimal("-6217.58")));353Calendar c = new GregorianCalendar(1969, JULY, 20, 16, 17, 0);354testSysOut("Local time: %tT", "Local time: 16:17:00", c);355356test("Unable to open file '%1$s': %2$s",357"Unable to open file 'food': No such file or directory",358"food", "No such file or directory");359Calendar duke = new GregorianCalendar(1995, MAY, 23, 19, 48, 34);360duke.set(Calendar.MILLISECOND, 584);361test("Duke's Birthday: %1$tB %1$te, %1$tY",362"Duke's Birthday: May 23, 1995",363duke);364test("Duke's Birthday: %1$tB %1$te, %1$tY",365"Duke's Birthday: May 23, 1995",366duke.getTime());367test("Duke's Birthday: %1$tB %1$te, %1$tY",368"Duke's Birthday: May 23, 1995",369duke.getTimeInMillis());370371test("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s",372"d c b a d c b a", "a", "b", "c", "d");373test("%s %s %<s %<s", "a b b b", "a", "b", "c", "d");374test("%s %s %s %s", "a b c d", "a", "b", "c", "d");375test("%2$s %s %<s %s", "b a a b", "a", "b", "c", "d");376377//---------------------------------------------------------------------378// %b379//380// General conversion applicable to any argument.381//---------------------------------------------------------------------382test("%b", "true", true);383test("%b", "false", false);384test("%B", "TRUE", true);385test("%B", "FALSE", false);386test("%b", "true", Boolean.TRUE);387test("%b", "false", Boolean.FALSE);388test("%B", "TRUE", Boolean.TRUE);389test("%B", "FALSE", Boolean.FALSE);390test("%14b", " true", true);391test("%-14b", "true ", true);392test("%5.1b", " f", false);393test("%-5.1b", "f ", false);394395test("%b", "true", "foo");396test("%b", "false", (Object)null);397398// Boolean.java hardcodes the Strings for "true" and "false", so no399// localization is possible.400test(Locale.FRANCE, "%b", "true", true);401test(Locale.FRANCE, "%b", "false", false);402403// If you pass in a single array to a varargs method, the compiler404// uses it as the array of arguments rather than treating it as a405// single array-type argument.406test("%b", "false", (Object[])new String[2]);407test("%b", "true", new String[2], new String[2]);408409int [] ia = { 1, 2, 3 };410test("%b", "true", ia);411412//---------------------------------------------------------------------413// %b - errors414//---------------------------------------------------------------------415tryCatch("%#b", FormatFlagsConversionMismatchException.class);416tryCatch("%-b", MissingFormatWidthException.class);417// correct or side-effect of implementation?418tryCatch("%.b", UnknownFormatConversionException.class);419tryCatch("%,b", FormatFlagsConversionMismatchException.class);420421//---------------------------------------------------------------------422// %c423//424// General conversion applicable to any argument.425//---------------------------------------------------------------------426test("%c", "i", 'i');427test("%C", "I", 'i');428test("%4c", " i", 'i');429test("%-4c", "i ", 'i');430test("%4C", " I", 'i');431test("%-4C", "I ", 'i');432test("%c", "i", new Character('i'));433test("%c", "H", (byte) 72);434test("%c", "i", (short) 105);435test("%c", "!", (int) 33);436test("%c", "\u007F", Byte.MAX_VALUE);437test("%c", new String(Character.toChars(Short.MAX_VALUE)),438Short.MAX_VALUE);439test("%c", "null", (Object) null);440441//---------------------------------------------------------------------442// %c - errors443//---------------------------------------------------------------------444tryCatch("%c", IllegalFormatConversionException.class,445Boolean.TRUE);446tryCatch("%c", IllegalFormatConversionException.class,447(float) 0.1);448tryCatch("%c", IllegalFormatConversionException.class,449new Object());450tryCatch("%c", IllegalFormatCodePointException.class,451Byte.MIN_VALUE);452tryCatch("%c", IllegalFormatCodePointException.class,453Short.MIN_VALUE);454tryCatch("%c", IllegalFormatCodePointException.class,455Integer.MIN_VALUE);456tryCatch("%c", IllegalFormatCodePointException.class,457Integer.MAX_VALUE);458459tryCatch("%#c", FormatFlagsConversionMismatchException.class);460tryCatch("%,c", FormatFlagsConversionMismatchException.class);461tryCatch("%(c", FormatFlagsConversionMismatchException.class);462tryCatch("%$c", UnknownFormatConversionException.class);463tryCatch("%.2c", IllegalFormatPrecisionException.class);464465//---------------------------------------------------------------------466// %s467//468// General conversion applicable to any argument.469//---------------------------------------------------------------------470test("%s", "Hello, Duke", "Hello, Duke");471test("%S", "HELLO, DUKE", "Hello, Duke");472test("%20S", " HELLO, DUKE", "Hello, Duke");473test("%20s", " Hello, Duke", "Hello, Duke");474test("%-20s", "Hello, Duke ", "Hello, Duke");475test("%-20.5s", "Hello ", "Hello, Duke");476test("%s", "null", (Object)null);477478StringBuffer sb = new StringBuffer("foo bar");479test("%s", sb.toString(), sb);480test("%S", sb.toString().toUpperCase(), sb);481482//---------------------------------------------------------------------483// %s - errors484//---------------------------------------------------------------------485tryCatch("%-s", MissingFormatWidthException.class);486tryCatch("%--s", DuplicateFormatFlagsException.class);487tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);488tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);489tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");490tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);491492//---------------------------------------------------------------------493// %h494//495// General conversion applicable to any argument.496//---------------------------------------------------------------------497test("%h", Integer.toHexString("Hello, Duke".hashCode()),498"Hello, Duke");499test("%10h", " ddf63471", "Hello, Duke");500test("%-10h", "ddf63471 ", "Hello, Duke");501test("%-10H", "DDF63471 ", "Hello, Duke");502test("%10h", " 402e0000", 15.0);503test("%10H", " 402E0000", 15.0);504505//---------------------------------------------------------------------506// %h - errors507//---------------------------------------------------------------------508tryCatch("%#h", FormatFlagsConversionMismatchException.class);509510//---------------------------------------------------------------------511// flag/conversion errors512//---------------------------------------------------------------------513tryCatch("%F", UnknownFormatConversionException.class);514515tryCatch("%#g", FormatFlagsConversionMismatchException.class);516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864//---------------------------------------------------------------------865// %s - double866//---------------------------------------------------------------------867double one = 1.0;868double ten = 10.0;869double pi = Math.PI;870871test("%s", "3.141592653589793", pi);872873874875876877878879880881882883884//---------------------------------------------------------------------885// flag/conversion errors886//---------------------------------------------------------------------887tryCatch("%d", IllegalFormatConversionException.class, one);888tryCatch("%,.4e", FormatFlagsConversionMismatchException.class, one);889890//---------------------------------------------------------------------891// %e892//893// Floating-point conversions applicable to float, double, and894// BigDecimal.895//---------------------------------------------------------------------896test("%e", "null", (Object)null);897898//---------------------------------------------------------------------899// %e - float and double900//---------------------------------------------------------------------901// double PI = 3.141 592 653 589 793 238 46;902test("%e", "3.141593e+00", pi);903test("%.0e", "1e+01", ten);904test("%#.0e", "1.e+01", ten);905test("%E", "3.141593E+00", pi);906test("%10.3e", " 3.142e+00", pi);907test("%10.3e", "-3.142e+00", negate(pi));908test("%010.3e", "03.142e+00", pi);909test("%010.3e", "-3.142e+00", negate(pi));910test("%-12.3e", "3.142e+00 ", pi);911test("%-12.3e", "-3.142e+00 ", negate(pi));912test("%.3e", "3.142e+00", pi);913test("%.3e", "-3.142e+00", negate(pi));914test("%.3e", "3.142e+06", mult(pi, 1000000.0));915test("%.3e", "-3.142e+06", mult(pi, -1000000.0));916917test(Locale.FRANCE, "%e", "3,141593e+00", pi);918919// double PI^300920// = 13962455701329742638131355433930076081862072808 ... e+149921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952test("%10.3e", " 1.000e+00", one);953test("%+.3e", "+3.142e+00", pi);954test("%+.3e", "-3.142e+00", negate(pi));955test("% .3e", " 3.142e+00", pi);956test("% .3e", "-3.142e+00", negate(pi));957test("%#.0e", "3.e+00", create(3.0));958test("%#.0e", "-3.e+00", create(-3.0));959test("%.0e", "3e+00", create(3.0));960test("%.0e", "-3e+00", create(-3.0));961962test("%(.4e", "3.1416e+06", mult(pi, 1000000.0));963test("%(.4e", "(3.1416e+06)", mult(pi, -1000000.0));964965//---------------------------------------------------------------------966// %e - boundary problems967//---------------------------------------------------------------------968test("%3.0e", "1e-06", 0.000001);969test("%3.0e", "1e-05", 0.00001);970test("%3.0e", "1e-04", 0.0001);971test("%3.0e", "1e-03", 0.001);972test("%3.0e", "1e-02", 0.01);973test("%3.0e", "1e-01", 0.1);974test("%3.0e", "9e-01", 0.9);975test("%3.1e", "9.0e-01", 0.9);976test("%3.0e", "1e+00", 1.00);977test("%3.0e", "1e+01", 10.00);978test("%3.0e", "1e+02", 99.19);979test("%3.1e", "9.9e+01", 99.19);980test("%3.0e", "1e+02", 99.99);981test("%3.0e", "1e+02", 100.00);982test("%#3.0e", "1.e+03", 1000.00);983test("%3.0e", "1e+04", 10000.00);984test("%3.0e", "1e+05", 100000.00);985test("%3.0e", "1e+06", 1000000.00);986test("%3.0e", "1e+07", 10000000.00);987test("%3.0e", "1e+08", 100000000.00);988989//---------------------------------------------------------------------990// %f991//992// Floating-point conversions applicable to float, double, and993// BigDecimal.994//---------------------------------------------------------------------995test("%f", "null", (Object)null);996test("%f", "3.141593", pi);997test(Locale.FRANCE, "%f", "3,141593", pi);998test("%10.3f", " 3.142", pi);999test("%10.3f", " -3.142", negate(pi));1000test("%010.3f", "000003.142", pi);1001test("%010.3f", "-00003.142", negate(pi));1002test("%-10.3f", "3.142 ", pi);1003test("%-10.3f", "-3.142 ", negate(pi));1004test("%.3f", "3.142", pi);1005test("%.3f", "-3.142", negate(pi));1006test("%+.3f", "+3.142", pi);1007test("%+.3f", "-3.142", negate(pi));1008test("% .3f", " 3.142", pi);1009test("% .3f", "-3.142", negate(pi));1010test("%#.0f", "3.", create(3.0));1011test("%#.0f", "-3.", create(-3.0));1012test("%.0f", "3", create(3.0));1013test("%.0f", "-3", create(-3.0));1014test("%.3f", "10.000", ten);1015test("%.3f", "1.000", one);1016test("%10.3f", " 1.000", one);10171018//---------------------------------------------------------------------1019// %f - boundary problems1020//---------------------------------------------------------------------1021test("%3.0f", " 0", 0.000001);1022test("%3.0f", " 0", 0.00001);1023test("%3.0f", " 0", 0.0001);1024test("%3.0f", " 0", 0.001);1025test("%3.0f", " 0", 0.01);1026test("%3.0f", " 0", 0.1);1027test("%3.0f", " 1", 0.9);1028test("%3.1f", "0.9", 0.9);1029test("%3.0f", " 1", 1.00);1030test("%3.0f", " 10", 10.00);1031test("%3.0f", " 99", 99.19);1032test("%3.1f", "99.2", 99.19);1033test("%3.0f", "100", 99.99);1034test("%3.0f", "100", 100.00);1035test("%#3.0f", "1000.", 1000.00);1036test("%3.0f", "10000", 10000.00);1037test("%3.0f", "100000", 100000.00);1038test("%3.0f", "1000000", 1000000.00);1039test("%3.0f", "10000000", 10000000.00);1040test("%3.0f", "100000000", 100000000.00);1041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134//---------------------------------------------------------------------1135// %f - float, double, Double, BigDecimal1136//---------------------------------------------------------------------1137test("%.3f", "3141592.654", mult(pi, 1000000.0));1138test("%.3f", "-3141592.654", mult(pi, -1000000.0));1139test("%,.4f", "3,141,592.6536", mult(pi, 1000000.0));1140test(Locale.FRANCE, "%,.4f", "3\u00a0141\u00a0592,6536", mult(pi, 1000000.0));1141test("%,.4f", "-3,141,592.6536", mult(pi, -1000000.0));1142test("%(.4f", "3141592.6536", mult(pi, 1000000.0));1143test("%(.4f", "(3141592.6536)", mult(pi, -1000000.0));1144test("%(,.4f", "3,141,592.6536", mult(pi, 1000000.0));1145test("%(,.4f", "(3,141,592.6536)", mult(pi, -1000000.0));11461147114811491150//---------------------------------------------------------------------1151// %g1152//1153// Floating-point conversions applicable to float, double, and1154// BigDecimal.1155//---------------------------------------------------------------------1156test("%g", "null", (Object)null);1157test("%g", "3.14159", pi);1158test(Locale.FRANCE, "%g", "3,14159", pi);1159test("%.0g", "1e+01", ten);1160test("%G", "3.14159", pi);1161test("%10.3g", " 3.14", pi);1162test("%10.3g", " -3.14", negate(pi));1163test("%010.3g", "0000003.14", pi);1164test("%010.3g", "-000003.14", negate(pi));1165test("%-12.3g", "3.14 ", pi);1166test("%-12.3g", "-3.14 ", negate(pi));1167test("%.3g", "3.14", pi);1168test("%.3g", "-3.14", negate(pi));1169test("%.3g", "3.14e+08", mult(pi, 100000000.0));1170test("%.3g", "-3.14e+08", mult(pi, -100000000.0));11711172test("%.3g", "1.00e-05", recip(create(100000.0)));1173test("%.3g", "-1.00e-05", recip(create(-100000.0)));1174test("%.0g", "-1e-05", recip(create(-100000.0)));1175test("%.0g", "1e+05", create(100000.0));1176test("%.3G", "1.00E-05", recip(create(100000.0)));1177test("%.3G", "-1.00E-05", recip(create(-100000.0)));11781179test("%.1g", "-0", -0.0);1180test("%3.0g", " -0", -0.0);1181test("%.1g", "0", 0.0);1182test("%3.0g", " 0", 0.0);1183test("%.1g", "0", +0.0);1184test("%3.0g", " 0", +0.0);11851186test("%3.0g", "1e-06", 0.000001);1187test("%3.0g", "1e-05", 0.00001);1188test("%3.0g", "1e-05", 0.0000099);1189test("%3.1g", "1e-05", 0.0000099);1190test("%3.2g", "9.9e-06", 0.0000099);1191test("%3.0g", "0.0001", 0.0001);1192test("%3.0g", "9e-05", 0.00009);1193test("%3.0g", "0.0001", 0.000099);1194test("%3.1g", "0.0001", 0.000099);1195test("%3.2g", "9.9e-05", 0.000099);1196test("%3.0g", "0.001", 0.001);1197test("%3.0g", "0.001", 0.00099);1198test("%3.1g", "0.001", 0.00099);1199test("%3.2g", "0.00099", 0.00099);1200test("%3.3g", "0.00100", 0.001);1201test("%3.4g", "0.001000", 0.001);1202test("%3.0g", "0.01", 0.01);1203test("%3.0g", "0.1", 0.1);1204test("%3.0g", "0.9", 0.9);1205test("%3.1g", "0.9", 0.9);1206test("%3.0g", " 1", 1.00);1207test("%3.2g", " 10", 10.00);1208test("%3.0g", "1e+01", 10.00);1209test("%3.0g", "1e+02", 99.19);1210test("%3.1g", "1e+02", 99.19);1211test("%3.2g", " 99", 99.19);1212test("%3.0g", "1e+02", 99.9);1213test("%3.1g", "1e+02", 99.9);1214test("%3.2g", "1.0e+02", 99.9);1215test("%3.0g", "1e+02", 99.99);1216test("%3.0g", "1e+02", 100.00);1217test("%3.0g", "1e+03", 999.9);1218test("%3.1g", "1e+03", 999.9);1219test("%3.2g", "1.0e+03", 999.9);1220test("%3.3g", "1.00e+03", 999.9);1221test("%3.4g", "999.9", 999.9);1222test("%3.4g", "1000", 999.99);1223test("%3.0g", "1e+03", 1000.00);1224test("%3.0g", "1e+04", 10000.00);1225test("%3.0g", "1e+05", 100000.00);1226test("%3.0g", "1e+06", 1000000.00);1227test("%3.0g", "1e+07", 10000000.00);1228test("%3.9g", "100000000", 100000000.00);1229test("%3.10g", "100000000.0", 100000000.00);12301231tryCatch("%#3.0g", FormatFlagsConversionMismatchException.class, 1000.00);12321233// double PI^3001234// = 13962455701329742638131355433930076081862072808 ... e+14912351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272test("%.3g", "10.0", ten);1273test("%.3g", "1.00", one);1274test("%10.3g", " 1.00", one);1275test("%+10.3g", " +3.14", pi);1276test("%+10.3g", " -3.14", negate(pi));1277test("% .3g", " 3.14", pi);1278test("% .3g", "-3.14", negate(pi));1279test("%.0g", "3", create(3.0));1280test("%.0g", "-3", create(-3.0));12811282test("%(.4g", "3.142e+08", mult(pi, 100000000.0));1283test("%(.4g", "(3.142e+08)", mult(pi, -100000000.0));12841285128612871288128912901291test("%,.11g", "3,141,592.6536", mult(pi, 1000000.0));1292test("%(,.11g", "(3,141,592.6536)", mult(pi, -1000000.0));12931294129512961297//---------------------------------------------------------------------1298// %a1299//1300// Floating-point conversions applicable to float, double, and1301// BigDecimal.1302//---------------------------------------------------------------------1303test("%a", "null", (Object)null);1304test("%.11a", "0x0.00000000000p0", 0.0);1305test(Locale.FRANCE, "%.11a", "0x0.00000000000p0", 0.0); // no localization1306test("%.1a", "0x0.0p0", 0.0);1307test("%.11a", "-0x0.00000000000p0", -0.0);1308test("%.1a", "-0x0.0p0", -0.0);1309test("%.11a", "0x1.00000000000p0", 1.0);1310test("%.1a", "0x1.0p0", 1.0);1311test("%.11a", "-0x1.00000000000p0", -1.0);1312test("%.1a", "-0x1.0p0", -1.0);1313test("%.11a", "0x1.80000000000p1", 3.0);1314test("%.1a", "0x1.8p1", 3.0);1315test("%.11a", "0x1.00000000000p-1022", DoubleConsts.MIN_NORMAL);1316test("%.1a", "0x1.0p-1022", DoubleConsts.MIN_NORMAL);1317test("%.11a", "0x1.00000000000p-1022",1318Math.nextDown(DoubleConsts.MIN_NORMAL));1319test("%.1a", "0x1.0p-1022",1320Math.nextDown(DoubleConsts.MIN_NORMAL));1321test("%.11a", "0x1.ffffffffffep-1023", 0x0.fffffffffffp-1022);1322test("%.1a", "0x1.0p-1022", 0x0.fffffffffffp-1022);1323test("%.30a", "0x0.000000000000100000000000000000p-1022", Double.MIN_VALUE);1324test("%.13a", "0x0.0000000000001p-1022", Double.MIN_VALUE);1325test("%.11a", "0x1.00000000000p-1074", Double.MIN_VALUE);1326test("%.1a", "0x1.0p-1074", Double.MIN_VALUE);13271328test("%.11a", "0x1.08000000000p-1069",1329Double.MIN_VALUE + Double.MIN_VALUE*32);1330test("%.1a", "0x1.0p-1069",1331Double.MIN_VALUE + Double.MIN_VALUE*32);1332test("%.30a", "0x1.fffffffffffff00000000000000000p1023", Double.MAX_VALUE);1333test("%.13a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);1334test("%.11a", "0x1.00000000000p1024", Double.MAX_VALUE);1335test("%.1a", "0x1.0p1024", Double.MAX_VALUE);1336test("%.11a", "0x1.18000000000p0", 0x1.18p0);1337test("%.1a", "0x1.2p0", 0x1.18p0);13381339test("%.11a", "0x1.18000000000p0", 0x1.180000000001p0);1340test("%.1a", "0x1.2p0", 0x1.180000000001p0);1341test("%.11a", "0x1.28000000000p0", 0x1.28p0);1342test("%.1a", "0x1.2p0", 0x1.28p0);13431344test("%.11a", "0x1.28000000000p0", 0x1.280000000001p0);1345test("%.1a", "0x1.3p0", 0x1.280000000001p0);13461347test("%a", "0x0.123p-1022", 0x0.123p-1022);1348test("%1.3a", "0x1.230p-1026", 0x0.123p-1022);1349test("%1.12a", "0x1.230000000000p-1026", 0x0.123p-1022);1350test("%1.15a", "0x0.123000000000000p-1022", 0x0.123p-1022);1351test("%1.5a", "0x1.00000p-1074", 0x0.0000000000001p-1022);1352test("%1.7a", "0x1.0000000p-1022", 0x0.fffffffffffffp-1022);13531354test("%1.6a", "0x1.230000p-1026", 0x0.123000057p-1022);1355test("%1.7a", "0x1.2300005p-1026", 0x0.123000057p-1022);1356test("%1.8a", "0x1.23000057p-1026", 0x0.123000057p-1022);1357test("%1.9a", "0x1.230000570p-1026", 0x0.123000057p-1022);13581359test("%1.6a", "0x1.230000p-1026", 0x0.123000058p-1022);1360test("%1.7a", "0x1.2300006p-1026", 0x0.123000058p-1022);1361test("%1.8a", "0x1.23000058p-1026", 0x0.123000058p-1022);1362test("%1.9a", "0x1.230000580p-1026", 0x0.123000058p-1022);13631364test("%1.6a", "0x1.230000p-1026", 0x0.123000059p-1022);1365test("%1.7a", "0x1.2300006p-1026", 0x0.123000059p-1022);1366test("%1.8a", "0x1.23000059p-1026", 0x0.123000059p-1022);1367test("%1.9a", "0x1.230000590p-1026", 0x0.123000059p-1022);13681369test("%1.4a", "0x1.0000p-1022", Math.nextDown(Double.MIN_NORMAL));13701371test("%a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);1372test("%1.1a", "0x1.0p1024", Double.MAX_VALUE);1373test("%1.2a", "0x1.00p1024", Double.MAX_VALUE);1374test("%1.6a", "0x1.000000p1024", Double.MAX_VALUE);1375test("%1.9a", "0x1.000000000p1024", Double.MAX_VALUE);1376test("%1.11a", "0x1.00000000000p1024", Double.MAX_VALUE);1377test("%1.12a", "0x1.000000000000p1024", Double.MAX_VALUE);1378test("%1.13a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);1379138013811382//---------------------------------------------------------------------1383// %f, %e, %g, %a - Boundaries1384//---------------------------------------------------------------------13851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554//---------------------------------------------------------------------1555// %f, %e, %g, %a - Double.MIN_VALUE1556//---------------------------------------------------------------------1557test("%f", "0.000000", Double.MIN_VALUE);1558test("%,f", "0.000000", Double.MIN_VALUE);1559test("%(f", "(0.000000)", -Double.MIN_VALUE);1560test("%30.0f", " 0", Double.MIN_VALUE);1561test("%30.5f", " 0.00000", Double.MIN_VALUE);1562test("%30.13f", " 0.0000000000000", Double.MIN_VALUE);1563test("%30.20f", " 0.00000000000000000000", Double.MIN_VALUE);1564test("%30.350f","0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000490000000000000000000000000",1565Double.MIN_VALUE);1566test("%e", "4.900000e-324", Double.MIN_VALUE);1567test("%E", "4.900000E-324", Double.MIN_VALUE);1568test("%(.1e", "4.9e-324", Double.MIN_VALUE);1569test("%(E", "(4.900000E-324)", -Double.MIN_VALUE);1570test("%30.5e", " 4.90000e-324", Double.MIN_VALUE);1571test("%30.13e", " 4.9000000000000e-324", Double.MIN_VALUE);1572test("%30.20e", " 4.90000000000000000000e-324", Double.MIN_VALUE);1573test("%g", "4.90000e-324", Double.MIN_VALUE);1574test("%G", "4.90000E-324", Double.MIN_VALUE);1575test("%(g", "4.90000e-324", Double.MIN_VALUE);1576test("%,g", "4.90000e-324", Double.MIN_VALUE);1577test("%30.5g", " 4.9000e-324", Double.MIN_VALUE);1578test("%30.13g", " 4.900000000000e-324", Double.MIN_VALUE);1579test("%30.20g", " 4.9000000000000000000e-324", Double.MIN_VALUE);1580test("%a", "0x0.0000000000001p-1022", Double.MIN_VALUE);1581test("%A", "0X0.0000000000001P-1022", Double.MIN_VALUE);1582test("%30a", " 0x0.0000000000001p-1022", Double.MIN_VALUE);15831584//---------------------------------------------------------------------1585// %f, %e, %g, %a - Double.MAX_VALUE1586//---------------------------------------------------------------------1587test("%f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000",1588Double.MAX_VALUE);1589test("%,f", "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.000000",1590Double.MAX_VALUE);1591test("%,(f", "(179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.000000)",1592-Double.MAX_VALUE);1593test("%,30.5f", "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.00000",1594Double.MAX_VALUE);1595test("%30.13f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000",1596Double.MAX_VALUE);1597test("%30.20f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000",1598Double.MAX_VALUE);1599test("%e", "1.797693e+308", Double.MAX_VALUE);1600test("%E", "1.797693E+308", Double.MAX_VALUE);1601test("%(e", "1.797693e+308", Double.MAX_VALUE);1602test("%(e", "(1.797693e+308)", -Double.MAX_VALUE);1603test("%30.5e", " 1.79769e+308", Double.MAX_VALUE);1604test("%30.13e", " 1.7976931348623e+308", Double.MAX_VALUE);1605test("%30.20e", " 1.79769313486231570000e+308", Double.MAX_VALUE);1606test("%g", "1.79769e+308", Double.MAX_VALUE);1607test("%G", "1.79769E+308", Double.MAX_VALUE);1608test("%,g", "1.79769e+308", Double.MAX_VALUE);1609test("%(g", "(1.79769e+308)", -Double.MAX_VALUE);1610test("%30.5g", " 1.7977e+308", Double.MAX_VALUE);1611test("%30.13g", " 1.797693134862e+308", Double.MAX_VALUE);1612test("%30.20g", " 1.7976931348623157000e+308", Double.MAX_VALUE);1613test("%a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);1614test("%A", "0X1.FFFFFFFFFFFFFP1023", Double.MAX_VALUE);1615test("%30a", " 0x1.fffffffffffffp1023", Double.MAX_VALUE);16161617161816191620//---------------------------------------------------------------------1621// %t1622//1623// Date/Time conversions applicable to Calendar, Date, and long.1624//---------------------------------------------------------------------1625test("%tA", "null", (Object)null);1626test("%TA", "NULL", (Object)null);16271628//---------------------------------------------------------------------1629// %t - errors1630//---------------------------------------------------------------------1631tryCatch("%t", UnknownFormatConversionException.class);1632tryCatch("%T", UnknownFormatConversionException.class);1633tryCatch("%tP", UnknownFormatConversionException.class);1634tryCatch("%TP", UnknownFormatConversionException.class);1635tryCatch("%.5tB", IllegalFormatPrecisionException.class);1636tryCatch("%#tB", FormatFlagsConversionMismatchException.class);1637tryCatch("%-tB", MissingFormatWidthException.class);163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733//---------------------------------------------------------------------1734// %n1735//---------------------------------------------------------------------1736test("%n", System.getProperty("line.separator"), (Object)null);1737test("%n", System.getProperty("line.separator"), "");17381739tryCatch("%,n", IllegalFormatFlagsException.class);1740tryCatch("%.n", UnknownFormatConversionException.class);1741tryCatch("%5.n", UnknownFormatConversionException.class);1742tryCatch("%5n", IllegalFormatWidthException.class);1743tryCatch("%.7n", IllegalFormatPrecisionException.class);1744tryCatch("%<n", IllegalFormatFlagsException.class);17451746//---------------------------------------------------------------------1747// %%1748//---------------------------------------------------------------------1749test("%%", "%", (Object)null);1750test("%%", "%", "");1751tryCatch("%%%", UnknownFormatConversionException.class);1752// perhaps an IllegalFormatArgumentIndexException should be defined?1753tryCatch("%<%", IllegalFormatFlagsException.class);1754}1755}175617571758