1 /*
   2  * Copyright (c) 2003, 2014, 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 /* Type-specific source code for unit test
  25  *
  26  * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
  27  * We check in the generated source files so that the test tree can be used
  28  * independently of the rest of the source tree.
  29  */
  30 
  31 // -- This file was mechanically generated: Do not edit! -- //
  32 
  33 import java.io.*;
  34 import java.math.BigDecimal;
  35 import java.math.BigInteger;
  36 import java.text.DateFormatSymbols;
  37 import java.util.*;
  38 
  39 import static java.util.Calendar.*;
  40 
  41 public class BasicFloat extends Basic {
  42 
  43     private static void test(String fs, String exp, Object ... args) {
  44         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  45         f.format(fs, args);
  46         ck(fs, exp, f.toString());
  47 
  48         f = new Formatter(new StringBuilder(), Locale.US);
  49         f.format("foo " + fs + " bar", args);
  50         ck(fs, "foo " + exp + " bar", f.toString());
  51     }
  52 
  53     private static void test(Locale l, String fs, String exp, Object ... args)
  54     {
  55         Formatter f = new Formatter(new StringBuilder(), l);
  56         f.format(fs, args);
  57         ck(fs, exp, f.toString());
  58 
  59         f = new Formatter(new StringBuilder(), l);
  60         f.format("foo " + fs + " bar", args);
  61         ck(fs, "foo " + exp + " bar", f.toString());
  62     }
  63 
  64     private static void test(String fs, Object ... args) {
  65         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  66         f.format(fs, args);
  67         ck(fs, "fail", f.toString());
  68     }
  69 
  70     private static void test(String fs) {
  71         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  72         f.format(fs, "fail");
  73         ck(fs, "fail", f.toString());
  74     }
  75 
  76     private static void testSysOut(String fs, String exp, Object ... args) {
  77         FileOutputStream fos = null;
  78         FileInputStream fis = null;
  79         try {
  80             PrintStream saveOut = System.out;
  81             fos = new FileOutputStream("testSysOut");
  82             System.setOut(new PrintStream(fos));
  83             System.out.format(Locale.US, fs, args);
  84             fos.close();
  85 
  86             fis = new FileInputStream("testSysOut");
  87             byte [] ba = new byte[exp.length()];
  88             int len = fis.read(ba);
  89             String got = new String(ba);
  90             if (len != ba.length)
  91                 fail(fs, exp, got);
  92             ck(fs, exp, got);
  93 
  94             System.setOut(saveOut);
  95         } catch (FileNotFoundException ex) {
  96             fail(fs, ex.getClass());
  97         } catch (IOException ex) {
  98             fail(fs, ex.getClass());
  99         } finally {
 100             try {
 101                 if (fos != null)
 102                     fos.close();
 103                 if (fis != null)
 104                     fis.close();
 105             } catch (IOException ex) {
 106                 fail(fs, ex.getClass());
 107             }
 108         }
 109     }
 110 
 111     private static void tryCatch(String fs, Class<?> ex) {
 112         boolean caught = false;
 113         try {
 114             test(fs);
 115         } catch (Throwable x) {
 116             if (ex.isAssignableFrom(x.getClass()))
 117                 caught = true;
 118         }
 119         if (!caught)
 120             fail(fs, ex);
 121         else
 122             pass();
 123     }
 124 
 125     private static void tryCatch(String fs, Class<?> ex, Object ... args) {
 126         boolean caught = false;
 127         try {
 128             test(fs, args);
 129         } catch (Throwable x) {
 130             if (ex.isAssignableFrom(x.getClass()))
 131                 caught = true;
 132         }
 133         if (!caught)
 134             fail(fs, ex);
 135         else
 136             pass();
 137     }
 138 
 139     private static float create(double v) {
 140         return (float) v;
 141     }
 142 
 143     private static float negate(double v) {
 144         return (float) -v;
 145     }
 146 
 147     private static float mult(float v, double mul) {
 148         return v * (float) mul;
 149     }
 150 
 151     private static float recip(float v) {
 152         return 1.0f / v;
 153     }
 154 
 155     public static void test() {
 156         TimeZone.setDefault(TimeZone.getTimeZone("GMT-0800"));
 157 
 158         // Any characters not explicitly defined as conversions, date/time
 159         // conversion suffixes, or flags are illegal and are reserved for
 160         // future extensions.  Use of such a character in a format string will
 161         // cause an UnknownFormatConversionException or
 162         // UnknownFormatFlagsException to be thrown.
 163         tryCatch("%q", UnknownFormatConversionException.class);
 164         tryCatch("%t&", UnknownFormatConversionException.class);
 165         tryCatch("%&d", UnknownFormatConversionException.class);
 166         tryCatch("%^b", UnknownFormatConversionException.class);
 167 
 168         //---------------------------------------------------------------------
 169         // Formatter.java class javadoc examples
 170         //---------------------------------------------------------------------
 171         test(Locale.FRANCE, "e = %+10.4f", "e =    +2,7183", Math.E);
 172         test("%4$2s %3$2s %2$2s %1$2s", " d  c  b  a", "a", "b", "c", "d");
 173         test("Amount gained or lost since last statement: $ %,(.2f",
 174              "Amount gained or lost since last statement: $ (6,217.58)",
 175              (new BigDecimal("-6217.58")));
 176         Calendar c = new GregorianCalendar(1969, JULY, 20, 16, 17, 0);
 177         testSysOut("Local time: %tT", "Local time: 16:17:00", c);
 178 
 179         test("Unable to open file '%1$s': %2$s",
 180              "Unable to open file 'food': No such file or directory",
 181              "food", "No such file or directory");
 182         Calendar duke = new GregorianCalendar(1995, MAY, 23, 19, 48, 34);
 183         duke.set(Calendar.MILLISECOND, 584);
 184         test("Duke's Birthday: %1$tB %1$te, %1$tY",
 185              "Duke's Birthday: May 23, 1995",
 186              duke);
 187         test("Duke's Birthday: %1$tB %1$te, %1$tY",
 188              "Duke's Birthday: May 23, 1995",
 189              duke.getTime());
 190         test("Duke's Birthday: %1$tB %1$te, %1$tY",
 191              "Duke's Birthday: May 23, 1995",
 192              duke.getTimeInMillis());
 193 
 194         test("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s",
 195              "d c b a d c b a", "a", "b", "c", "d");
 196         test("%s %s %<s %<s", "a b b b", "a", "b", "c", "d");
 197         test("%s %s %s %s", "a b c d", "a", "b", "c", "d");
 198         test("%2$s %s %<s %s", "b a a b", "a", "b", "c", "d");
 199 
 200         //---------------------------------------------------------------------
 201         // %b
 202         //
 203         // General conversion applicable to any argument.
 204         //---------------------------------------------------------------------
 205         test("%b", "true", true);
 206         test("%b", "false", false);
 207         test("%B", "TRUE", true);
 208         test("%B", "FALSE", false);
 209         test("%b", "true", Boolean.TRUE);
 210         test("%b", "false", Boolean.FALSE);
 211         test("%B", "TRUE", Boolean.TRUE);
 212         test("%B", "FALSE", Boolean.FALSE);
 213         test("%14b", "          true", true);
 214         test("%-14b", "true          ", true);
 215         test("%5.1b", "    f", false);
 216         test("%-5.1b", "f    ", false);
 217 
 218         test("%b", "true", "foo");
 219         test("%b", "false", (Object)null);
 220 
 221         // Boolean.java hardcodes the Strings for "true" and "false", so no
 222         // localization is possible.
 223         test(Locale.FRANCE, "%b", "true", true);
 224         test(Locale.FRANCE, "%b", "false", false);
 225 
 226         // If you pass in a single array to a varargs method, the compiler
 227         // uses it as the array of arguments rather than treating it as a
 228         // single array-type argument.
 229         test("%b", "false", (Object[])new String[2]);
 230         test("%b", "true", new String[2], new String[2]);
 231 
 232         int [] ia = { 1, 2, 3 };
 233         test("%b", "true", ia);
 234 
 235         //---------------------------------------------------------------------
 236         // %b - errors
 237         //---------------------------------------------------------------------
 238         tryCatch("%#b", FormatFlagsConversionMismatchException.class);
 239         tryCatch("%-b", MissingFormatWidthException.class);
 240         // correct or side-effect of implementation?
 241         tryCatch("%.b", UnknownFormatConversionException.class);
 242         tryCatch("%,b", FormatFlagsConversionMismatchException.class);
 243 
 244         //---------------------------------------------------------------------
 245         // %c
 246         //
 247         // General conversion applicable to any argument.
 248         //---------------------------------------------------------------------
 249         test("%c", "i", 'i');
 250         test("%C", "I", 'i');
 251         test("%4c",  "   i", 'i');
 252         test("%-4c", "i   ", 'i');
 253         test("%4C",  "   I", 'i');
 254         test("%-4C", "I   ", 'i');
 255         test("%c", "i", new Character('i'));
 256         test("%c", "H", (byte) 72);
 257         test("%c", "i", (short) 105);
 258         test("%c", "!", (int) 33);
 259         test("%c", "\u007F", Byte.MAX_VALUE);
 260         test("%c", new String(Character.toChars(Short.MAX_VALUE)),
 261              Short.MAX_VALUE);
 262         test("%c", "null", (Object) null);
 263 
 264         //---------------------------------------------------------------------
 265         // %c - errors
 266         //---------------------------------------------------------------------
 267         tryCatch("%c", IllegalFormatConversionException.class,
 268                  Boolean.TRUE);
 269         tryCatch("%c", IllegalFormatConversionException.class,
 270                  (float) 0.1);
 271         tryCatch("%c", IllegalFormatConversionException.class,
 272                  new Object());
 273         tryCatch("%c", IllegalFormatCodePointException.class,
 274                  Byte.MIN_VALUE);
 275         tryCatch("%c", IllegalFormatCodePointException.class,
 276                  Short.MIN_VALUE);
 277         tryCatch("%c", IllegalFormatCodePointException.class,
 278                  Integer.MIN_VALUE);
 279         tryCatch("%c", IllegalFormatCodePointException.class,
 280                  Integer.MAX_VALUE);
 281 
 282         tryCatch("%#c", FormatFlagsConversionMismatchException.class);
 283         tryCatch("%,c", FormatFlagsConversionMismatchException.class);
 284         tryCatch("%(c", FormatFlagsConversionMismatchException.class);
 285         tryCatch("%$c", UnknownFormatConversionException.class);
 286         tryCatch("%.2c", IllegalFormatPrecisionException.class);
 287 
 288         //---------------------------------------------------------------------
 289         // %s
 290         //
 291         // General conversion applicable to any argument.
 292         //---------------------------------------------------------------------
 293         test("%s", "Hello, Duke", "Hello, Duke");
 294         test("%S", "HELLO, DUKE", "Hello, Duke");
 295         test("%20S", "         HELLO, DUKE", "Hello, Duke");
 296         test("%20s", "         Hello, Duke", "Hello, Duke");
 297         test("%-20s", "Hello, Duke         ", "Hello, Duke");
 298         test("%-20.5s", "Hello               ", "Hello, Duke");
 299         test("%s", "null", (Object)null);
 300 
 301         StringBuffer sb = new StringBuffer("foo bar");
 302         test("%s", sb.toString(), sb);
 303         test("%S", sb.toString().toUpperCase(), sb);
 304 
 305         //---------------------------------------------------------------------
 306         // %s - errors
 307         //---------------------------------------------------------------------
 308         tryCatch("%-s", MissingFormatWidthException.class);
 309         tryCatch("%--s", DuplicateFormatFlagsException.class);
 310         tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
 311         tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
 312         tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
 313         tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
 314 
 315         //---------------------------------------------------------------------
 316         // %h
 317         //
 318         // General conversion applicable to any argument.
 319         //---------------------------------------------------------------------
 320         test("%h", Integer.toHexString("Hello, Duke".hashCode()),
 321              "Hello, Duke");
 322         test("%10h", "  ddf63471", "Hello, Duke");
 323         test("%-10h", "ddf63471  ", "Hello, Duke");
 324         test("%-10H", "DDF63471  ", "Hello, Duke");
 325         test("%10h", "  402e0000", 15.0);
 326         test("%10H", "  402E0000", 15.0);
 327 
 328         //---------------------------------------------------------------------
 329         // %h - errors
 330         //---------------------------------------------------------------------
 331         tryCatch("%#h", FormatFlagsConversionMismatchException.class);
 332 
 333         //---------------------------------------------------------------------
 334         // flag/conversion errors
 335         //---------------------------------------------------------------------
 336         tryCatch("%F", UnknownFormatConversionException.class);
 337 
 338         tryCatch("%#g", FormatFlagsConversionMismatchException.class);
 339 
 340         //---------------------------------------------------------------------
 341         // %s - float
 342         //---------------------------------------------------------------------
 343         float one = 1.0f;
 344         float ten = 10.0f;
 345         float pi  = (float) Math.PI;
 346 
 347         test("%s", "3.1415927", pi);
 348 
 349         //---------------------------------------------------------------------
 350         // flag/conversion errors
 351         //---------------------------------------------------------------------
 352         tryCatch("%d", IllegalFormatConversionException.class, one);
 353         tryCatch("%,.4e", FormatFlagsConversionMismatchException.class, one);
 354 
 355         //---------------------------------------------------------------------
 356         // %e
 357         //
 358         // Floating-point conversions applicable to float, double, and
 359         // BigDecimal.
 360         //---------------------------------------------------------------------
 361         test("%e", "null", (Object)null);
 362 
 363         //---------------------------------------------------------------------
 364         // %e - float and double
 365         //---------------------------------------------------------------------
 366         // double PI = 3.141 592 653 589 793 238 46;
 367         test("%e", "3.141593e+00", pi);
 368         test("%.0e", "1e+01", ten);
 369         test("%#.0e", "1.e+01", ten);
 370         test("%E", "3.141593E+00", pi);
 371         test("%10.3e", " 3.142e+00", pi);
 372         test("%10.3e", "-3.142e+00", negate(pi));
 373         test("%010.3e", "03.142e+00", pi);
 374         test("%010.3e", "-3.142e+00", negate(pi));
 375         test("%-12.3e", "3.142e+00   ", pi);
 376         test("%-12.3e", "-3.142e+00  ", negate(pi));
 377         test("%.3e", "3.142e+00", pi);
 378         test("%.3e", "-3.142e+00", negate(pi));
 379         test("%.3e", "3.142e+06", mult(pi, 1000000.0));
 380         test("%.3e", "-3.142e+06", mult(pi, -1000000.0));
 381 
 382         test(Locale.FRANCE, "%e", "3,141593e+00", pi);
 383 
 384         // double PI^300
 385         //    = 13962455701329742638131355433930076081862072808 ... e+149
 386 
 387         test("%10.3e", " 1.000e+00", one);
 388         test("%+.3e", "+3.142e+00", pi);
 389         test("%+.3e", "-3.142e+00", negate(pi));
 390         test("% .3e", " 3.142e+00", pi);
 391         test("% .3e", "-3.142e+00", negate(pi));
 392         test("%#.0e", "3.e+00", create(3.0));
 393         test("%#.0e", "-3.e+00", create(-3.0));
 394         test("%.0e", "3e+00", create(3.0));
 395         test("%.0e", "-3e+00", create(-3.0));
 396 
 397         test("%(.4e", "3.1416e+06", mult(pi, 1000000.0));
 398         test("%(.4e", "(3.1416e+06)", mult(pi, -1000000.0));
 399 
 400         //---------------------------------------------------------------------
 401         // %e - boundary problems
 402         //---------------------------------------------------------------------
 403         test("%3.0e", "1e-06", 0.000001);
 404         test("%3.0e", "1e-05", 0.00001);
 405         test("%3.0e", "1e-04", 0.0001);
 406         test("%3.0e", "1e-03", 0.001);
 407         test("%3.0e", "1e-02", 0.01);
 408         test("%3.0e", "1e-01", 0.1);
 409         test("%3.0e", "9e-01", 0.9);
 410         test("%3.1e", "9.0e-01", 0.9);
 411         test("%3.0e", "1e+00", 1.00);
 412         test("%3.0e", "1e+01", 10.00);
 413         test("%3.0e", "1e+02", 99.19);
 414         test("%3.1e", "9.9e+01", 99.19);
 415         test("%3.0e", "1e+02", 99.99);
 416         test("%3.0e", "1e+02", 100.00);
 417         test("%#3.0e", "1.e+03",     1000.00);
 418         test("%3.0e", "1e+04",     10000.00);
 419         test("%3.0e", "1e+05",    100000.00);
 420         test("%3.0e", "1e+06",   1000000.00);
 421         test("%3.0e", "1e+07",  10000000.00);
 422         test("%3.0e", "1e+08", 100000000.00);
 423 
 424         //---------------------------------------------------------------------
 425         // %f
 426         //
 427         // Floating-point conversions applicable to float, double, and
 428         // BigDecimal.
 429         //---------------------------------------------------------------------
 430         test("%f", "null", (Object)null);
 431         test("%f", "3.141593", pi);
 432         test(Locale.FRANCE, "%f", "3,141593", pi);
 433         test("%10.3f", "     3.142", pi);
 434         test("%10.3f", "    -3.142", negate(pi));
 435         test("%010.3f", "000003.142", pi);
 436         test("%010.3f", "-00003.142", negate(pi));
 437         test("%-10.3f", "3.142     ", pi);
 438         test("%-10.3f", "-3.142    ", negate(pi));
 439         test("%.3f", "3.142", pi);
 440         test("%.3f", "-3.142", negate(pi));
 441         test("%+.3f", "+3.142", pi);
 442         test("%+.3f", "-3.142", negate(pi));
 443         test("% .3f", " 3.142", pi);
 444         test("% .3f", "-3.142", negate(pi));
 445         test("%#.0f", "3.", create(3.0));
 446         test("%#.0f", "-3.", create(-3.0));
 447         test("%.0f", "3", create(3.0));
 448         test("%.0f", "-3", create(-3.0));
 449         test("%.3f", "10.000", ten);
 450         test("%.3f", "1.000", one);
 451         test("%10.3f", "     1.000", one);
 452 
 453         //---------------------------------------------------------------------
 454         // %f - boundary problems
 455         //---------------------------------------------------------------------
 456         test("%3.0f", "  0", 0.000001);
 457         test("%3.0f", "  0", 0.00001);
 458         test("%3.0f", "  0", 0.0001);
 459         test("%3.0f", "  0", 0.001);
 460         test("%3.0f", "  0", 0.01);
 461         test("%3.0f", "  0", 0.1);
 462         test("%3.0f", "  1", 0.9);
 463         test("%3.1f", "0.9", 0.9);
 464         test("%3.0f", "  1", 1.00);
 465         test("%3.0f", " 10", 10.00);
 466         test("%3.0f", " 99", 99.19);
 467         test("%3.1f", "99.2", 99.19);
 468         test("%3.0f", "100", 99.99);
 469         test("%3.0f", "100", 100.00);
 470         test("%#3.0f", "1000.",     1000.00);
 471         test("%3.0f", "10000",     10000.00);
 472         test("%3.0f", "100000",    100000.00);
 473         test("%3.0f", "1000000",   1000000.00);
 474         test("%3.0f", "10000000",  10000000.00);
 475         test("%3.0f", "100000000", 100000000.00);
 476         test("%10.0f", "   1000000",   1000000.00);
 477         test("%,10.0f", " 1,000,000",   1000000.00);
 478         test("%,10.1f", "1,000,000.0",   1000000.00);
 479         test("%,3.0f", "1,000,000",   1000000.00);
 480         test("%,3.0f", "10,000,000",  10000000.00);
 481         test("%,3.0f", "100,000,000", 100000000.00);
 482         test("%,3.0f", "10,000,000",  10000000.00);
 483         test("%,3.0f", "100,000,000", 100000000.00);
 484 
 485         //---------------------------------------------------------------------
 486         // %f - float
 487         //---------------------------------------------------------------------
 488         // Float can not accurately store 1e6 * PI.
 489         test("%.3f", "3141.593", mult(pi, 1000.0));
 490         test("%.3f", "-3141.593", mult(pi, -1000.0));
 491 
 492         test("%,.2f", "3,141.59", mult(pi, 1000.0));
 493         test(Locale.FRANCE, "%,.2f", "3\u00a0141,59", mult(pi, 1000.0));
 494         test("%,.2f", "-3,141.59", mult(pi, -1000.0));
 495         test("%(.2f", "3141.59", mult(pi, 1000.0));
 496         test("%(.2f", "(3141.59)", mult(pi, -1000.0));
 497         test("%(,.2f", "3,141.59", mult(pi, 1000.0));
 498         test("%(,.2f", "(3,141.59)", mult(pi, -1000.0));
 499 
 500         //---------------------------------------------------------------------
 501         // %g
 502         //
 503         // Floating-point conversions applicable to float, double, and
 504         // BigDecimal.
 505         //---------------------------------------------------------------------
 506         test("%g", "null", (Object)null);
 507         test("%g", "3.14159", pi);
 508         test(Locale.FRANCE, "%g", "3,14159", pi);
 509         test("%.0g", "1e+01", ten);
 510         test("%G", "3.14159", pi);
 511         test("%10.3g", "      3.14", pi);
 512         test("%10.3g", "     -3.14", negate(pi));
 513         test("%010.3g", "0000003.14", pi);
 514         test("%010.3g", "-000003.14", negate(pi));
 515         test("%-12.3g", "3.14        ", pi);
 516         test("%-12.3g", "-3.14       ", negate(pi));
 517         test("%.3g", "3.14", pi);
 518         test("%.3g", "-3.14", negate(pi));
 519         test("%.3g", "3.14e+08", mult(pi, 100000000.0));
 520         test("%.3g", "-3.14e+08", mult(pi, -100000000.0));
 521 
 522         test("%.3g", "1.00e-05", recip(create(100000.0)));
 523         test("%.3g", "-1.00e-05", recip(create(-100000.0)));
 524         test("%.0g", "-1e-05", recip(create(-100000.0)));
 525         test("%.0g", "1e+05", create(100000.0));
 526         test("%.3G", "1.00E-05", recip(create(100000.0)));
 527         test("%.3G", "-1.00E-05", recip(create(-100000.0)));
 528 
 529         test("%.1g", "-0", -0.0);
 530         test("%3.0g", " -0", -0.0);
 531         test("%.1g", "0", 0.0);
 532         test("%3.0g", "  0", 0.0);
 533         test("%.1g", "0", +0.0);
 534         test("%3.0g", "  0", +0.0);
 535 
 536         test("%3.0g", "1e-06", 0.000001);
 537         test("%3.0g", "1e-05", 0.00001);
 538         test("%3.0g", "1e-05", 0.0000099);
 539         test("%3.1g", "1e-05", 0.0000099);
 540         test("%3.2g", "9.9e-06", 0.0000099);
 541         test("%3.0g", "0.0001", 0.0001);
 542         test("%3.0g", "9e-05",  0.00009);
 543         test("%3.0g", "0.0001", 0.000099);
 544         test("%3.1g", "0.0001", 0.000099);
 545         test("%3.2g", "9.9e-05", 0.000099);
 546         test("%3.0g", "0.001", 0.001);
 547         test("%3.0g", "0.001", 0.00099);
 548         test("%3.1g", "0.001", 0.00099);
 549         test("%3.2g", "0.00099", 0.00099);
 550         test("%3.3g", "0.00100", 0.001);
 551         test("%3.4g", "0.001000", 0.001);
 552         test("%3.0g", "0.01", 0.01);
 553         test("%3.0g", "0.1", 0.1);
 554         test("%3.0g", "0.9", 0.9);
 555         test("%3.1g", "0.9", 0.9);
 556         test("%3.0g", "  1", 1.00);
 557         test("%3.2g", " 10", 10.00);
 558         test("%3.0g", "1e+01", 10.00);
 559         test("%3.0g", "1e+02", 99.19);
 560         test("%3.1g", "1e+02", 99.19);
 561         test("%3.2g", " 99", 99.19);
 562         test("%3.0g", "1e+02", 99.9);
 563         test("%3.1g", "1e+02", 99.9);
 564         test("%3.2g", "1.0e+02", 99.9);
 565         test("%3.0g", "1e+02", 99.99);
 566         test("%3.0g", "1e+02", 100.00);
 567         test("%3.0g", "1e+03", 999.9);
 568         test("%3.1g", "1e+03", 999.9);
 569         test("%3.2g", "1.0e+03", 999.9);
 570         test("%3.3g", "1.00e+03", 999.9);
 571         test("%3.4g", "999.9", 999.9);
 572         test("%3.4g", "1000", 999.99);
 573         test("%3.0g", "1e+03", 1000.00);
 574         test("%3.0g", "1e+04",     10000.00);
 575         test("%3.0g", "1e+05",    100000.00);
 576         test("%3.0g", "1e+06",   1000000.00);
 577         test("%3.0g", "1e+07",  10000000.00);
 578         test("%3.9g", "100000000",  100000000.00);
 579         test("%3.10g", "100000000.0", 100000000.00);
 580 
 581         tryCatch("%#3.0g", FormatFlagsConversionMismatchException.class, 1000.00);
 582 
 583         // double PI^300
 584         //    = 13962455701329742638131355433930076081862072808 ... e+149
 585 
 586         test("%.3g", "10.0", ten);
 587         test("%.3g", "1.00", one);
 588         test("%10.3g", "      1.00", one);
 589         test("%+10.3g", "     +3.14", pi);
 590         test("%+10.3g", "     -3.14", negate(pi));
 591         test("% .3g", " 3.14", pi);
 592         test("% .3g", "-3.14", negate(pi));
 593         test("%.0g", "3", create(3.0));
 594         test("%.0g", "-3", create(-3.0));
 595 
 596         test("%(.4g", "3.142e+08", mult(pi, 100000000.0));
 597         test("%(.4g", "(3.142e+08)", mult(pi, -100000000.0));
 598 
 599         // Float can not accurately store 1e6 * PI.
 600         test("%,.6g", "3,141.59", mult(pi, 1000.0));
 601         test("%(,.6g", "(3,141.59)", mult(pi, -1000.0));
 602 
 603         //---------------------------------------------------------------------
 604         // %f, %e, %g, %a - Boundaries
 605         //---------------------------------------------------------------------
 606 
 607         //---------------------------------------------------------------------
 608         // %f, %e, %g, %a - NaN
 609         //---------------------------------------------------------------------
 610         test("%f", "NaN", Float.NaN);
 611         // s
 612         test("%+f", "NaN", Float.NaN);
 613 //      test("%F", "NAN", Float.NaN);
 614         test("%e", "NaN", Float.NaN);
 615         test("%+e", "NaN", Float.NaN);
 616         test("%E", "NAN", Float.NaN);
 617         test("%g", "NaN", Float.NaN);
 618         test("%+g", "NaN", Float.NaN);
 619         test("%G", "NAN", Float.NaN);
 620         test("%a", "NaN", Float.NaN);
 621         test("%+a", "NaN", Float.NaN);
 622         test("%A", "NAN", Float.NaN);
 623 
 624         //---------------------------------------------------------------------
 625         // %f, %e, %g, %a - +0.0
 626         //---------------------------------------------------------------------
 627         test("%f", "0.000000", +0.0);
 628         test("%+f", "+0.000000", +0.0);
 629         test("% f", " 0.000000", +0.0);
 630 //      test("%F", "0.000000", +0.0);
 631         test("%e", "0.000000e+00", 0e0);
 632         test("%e", "0.000000e+00", +0.0);
 633         test("%+e", "+0.000000e+00", +0.0);
 634         test("% e", " 0.000000e+00", +0.0);
 635         test("%E", "0.000000E+00", 0e0);
 636         test("%E", "0.000000E+00", +0.0);
 637         test("%+E", "+0.000000E+00", +0.0);
 638         test("% E", " 0.000000E+00", +0.0);
 639         test("%g", "0.00000", +0.0);
 640         test("%+g", "+0.00000", +0.0);
 641         test("% g", " 0.00000", +0.0);
 642         test("%G", "0.00000", +0.0);
 643         test("% G", " 0.00000", +0.0);
 644         test("%a", "0x0.0p0", +0.0);
 645         test("%+a", "+0x0.0p0", +0.0);
 646         test("% a", " 0x0.0p0", +0.0);
 647         test("%A", "0X0.0P0", +0.0);
 648         test("% A", " 0X0.0P0", +0.0);
 649 
 650         //---------------------------------------------------------------------
 651         // %f, %e, %g, %a - -0.0
 652         //---------------------------------------------------------------------
 653         test("%f", "-0.000000", -0.0);
 654         test("%+f", "-0.000000", -0.0);
 655 //      test("%F", "-0.000000", -0.0);
 656         test("%e", "-0.000000e+00", -0.0);
 657         test("%+e", "-0.000000e+00", -0.0);
 658         test("%E", "-0.000000E+00", -0.0);
 659         test("%+E", "-0.000000E+00", -0.0);
 660         test("%g", "-0.00000", -0.0);
 661         test("%+g", "-0.00000", -0.0);
 662         test("%G", "-0.00000", -0.0);
 663         test("%a", "-0x0.0p0", -0.0);
 664         test("%+a", "-0x0.0p0", -0.0);
 665         test("%+A", "-0X0.0P0", -0.0);
 666 
 667         //---------------------------------------------------------------------
 668         // %f, %e, %g, %a - +Infinity
 669         //---------------------------------------------------------------------
 670         test("%f", "Infinity", Float.POSITIVE_INFINITY);
 671         test("%+f", "+Infinity", Float.POSITIVE_INFINITY);
 672         test("% f", " Infinity", Float.POSITIVE_INFINITY);
 673 //      test("%F", "INFINITY", Float.POSITIVE_INFINITY);
 674         test("%e", "Infinity", Float.POSITIVE_INFINITY);
 675         test("%+e", "+Infinity", Float.POSITIVE_INFINITY);
 676         test("% e", " Infinity", Float.POSITIVE_INFINITY);
 677         test("%E", "INFINITY", Float.POSITIVE_INFINITY);
 678         test("%+E", "+INFINITY", Float.POSITIVE_INFINITY);
 679         test("% E", " INFINITY", Float.POSITIVE_INFINITY);
 680         test("%g", "Infinity", Float.POSITIVE_INFINITY);
 681         test("%+g", "+Infinity", Float.POSITIVE_INFINITY);
 682         test("%G", "INFINITY", Float.POSITIVE_INFINITY);
 683         test("% G", " INFINITY", Float.POSITIVE_INFINITY);
 684         test("%+G", "+INFINITY", Float.POSITIVE_INFINITY);
 685         test("%a", "Infinity", Float.POSITIVE_INFINITY);
 686         test("%+a", "+Infinity", Float.POSITIVE_INFINITY);
 687         test("% a", " Infinity", Float.POSITIVE_INFINITY);
 688         test("%A", "INFINITY", Float.POSITIVE_INFINITY);
 689         test("%+A", "+INFINITY", Float.POSITIVE_INFINITY);
 690         test("% A", " INFINITY", Float.POSITIVE_INFINITY);
 691 
 692         //---------------------------------------------------------------------
 693         // %f, %e, %g, %a - -Infinity
 694         //---------------------------------------------------------------------
 695         test("%f", "-Infinity", Float.NEGATIVE_INFINITY);
 696         test("%+f", "-Infinity", Float.NEGATIVE_INFINITY);
 697         test("%(f", "(Infinity)", Float.NEGATIVE_INFINITY);
 698 //      test("%F", "-INFINITY", Float.NEGATIVE_INFINITY);
 699         test("%e", "-Infinity", Float.NEGATIVE_INFINITY);
 700         test("%+e", "-Infinity", Float.NEGATIVE_INFINITY);
 701         test("%E", "-INFINITY", Float.NEGATIVE_INFINITY);
 702         test("%+E", "-INFINITY", Float.NEGATIVE_INFINITY);
 703         test("%g", "-Infinity", Float.NEGATIVE_INFINITY);
 704         test("%+g", "-Infinity", Float.NEGATIVE_INFINITY);
 705         test("%G", "-INFINITY", Float.NEGATIVE_INFINITY);
 706         test("%+G", "-INFINITY", Float.NEGATIVE_INFINITY);
 707         test("%a", "-Infinity", Float.NEGATIVE_INFINITY);
 708         test("%+a", "-Infinity", Float.NEGATIVE_INFINITY);
 709         test("%A", "-INFINITY", Float.NEGATIVE_INFINITY);
 710         test("%+A", "-INFINITY", Float.NEGATIVE_INFINITY);
 711 
 712         //---------------------------------------------------------------------
 713         // %f, %e, %g, %a - Float.MIN_VALUE
 714         //---------------------------------------------------------------------
 715         test("%f", "0.000000", Float.MIN_VALUE);
 716         test("%,f", "0.000000", Float.MIN_VALUE);
 717         test("%(f", "(0.000000)", -Float.MIN_VALUE);
 718         test("%30.0f",  "                             0", Float.MIN_VALUE);
 719         test("%30.5f",  "                       0.00000", Float.MIN_VALUE);
 720         test("%30.13f", "               0.0000000000000", Float.MIN_VALUE);
 721         test("%30.20f", "        0.00000000000000000000", Float.MIN_VALUE);
 722         test("%e", "1.401298e-45", Float.MIN_VALUE);
 723         test("%E", "1.401298E-45", Float.MIN_VALUE);
 724         test("%(.1e", "1.4e-45", Float.MIN_VALUE);
 725         test("%(E", "(1.401298E-45)", -Float.MIN_VALUE);
 726         test("%30.5e",  "                   1.40130e-45", Float.MIN_VALUE);
 727         test("%30.13e", "           1.4012984643248e-45", Float.MIN_VALUE);
 728         test("%30.20e", "    1.40129846432481700000e-45", Float.MIN_VALUE);
 729         test("%g", "1.40130e-45", Float.MIN_VALUE);
 730         test("%G", "1.40130E-45", Float.MIN_VALUE);
 731         test("%(g", "1.40130e-45", Float.MIN_VALUE);
 732         test("%,g", "1.40130e-45", Float.MIN_VALUE);
 733         test("%(G", "(1.40130E-45)", -Float.MIN_VALUE);
 734         test("%30.5g",  "                    1.4013e-45", Float.MIN_VALUE);
 735         test("%30.13g", "            1.401298464325e-45", Float.MIN_VALUE);
 736         test("%30.20g", "     1.4012984643248170000e-45", Float.MIN_VALUE);
 737         test("%a", "0x1.0p-149", Float.MIN_VALUE);
 738         test("%A", "0X1.0P-149", Float.MIN_VALUE);
 739         test("%20a", "          0x1.0p-149", Float.MIN_VALUE);
 740 
 741         //---------------------------------------------------------------------
 742         // %f, %e, %g, %a - Float.MAX_VALUE
 743         //---------------------------------------------------------------------
 744         test("%f", "340282346638528860000000000000000000000.000000", Float.MAX_VALUE);
 745         test("%,f","340,282,346,638,528,860,000,000,000,000,000,000,000.000000",
 746              Float.MAX_VALUE);
 747         test("%(f", "(340282346638528860000000000000000000000.000000)", -Float.MAX_VALUE);
 748         test("%60.5f",  "               340282346638528860000000000000000000000.00000",
 749              Float.MAX_VALUE);
 750         test("%60.13f", "       340282346638528860000000000000000000000.0000000000000",
 751              Float.MAX_VALUE);
 752         test("%61.20f", " 340282346638528860000000000000000000000.00000000000000000000",
 753              Float.MAX_VALUE);
 754         test("%e", "3.402823e+38", Float.MAX_VALUE);
 755         test("%E", "3.402823E+38", Float.MAX_VALUE);
 756         test("%(e", "3.402823e+38", Float.MAX_VALUE);
 757         test("%(e", "(3.402823e+38)", -Float.MAX_VALUE);
 758         test("%30.5e",  "                   3.40282e+38", Float.MAX_VALUE);
 759         test("%30.13e", "           3.4028234663853e+38", Float.MAX_VALUE);
 760         test("%30.20e", "    3.40282346638528860000e+38", Float.MAX_VALUE);
 761         test("%g", "3.40282e+38", Float.MAX_VALUE);
 762         test("%G", "3.40282E+38", Float.MAX_VALUE);
 763         test("%,g", "3.40282e+38", Float.MAX_VALUE);
 764         test("%(g", "(3.40282e+38)", -Float.MAX_VALUE);
 765         test("%30.5g",  "                    3.4028e+38", Float.MAX_VALUE);
 766         test("%30.13g", "            3.402823466385e+38", Float.MAX_VALUE);
 767         test("%30.20G", "     3.4028234663852886000E+38", Float.MAX_VALUE);
 768         test("%a", "0x1.fffffep127", Float.MAX_VALUE);
 769         test("%A", "0X1.FFFFFEP127", Float.MAX_VALUE);
 770         test("%20a","      0x1.fffffep127", Float.MAX_VALUE);
 771 
 772         //---------------------------------------------------------------------
 773         // %t
 774         //
 775         // Date/Time conversions applicable to Calendar, Date, and long.
 776         //---------------------------------------------------------------------
 777         test("%tA", "null", (Object)null);
 778         test("%TA", "NULL", (Object)null);
 779 
 780         //---------------------------------------------------------------------
 781         // %t - errors
 782         //---------------------------------------------------------------------
 783         tryCatch("%t", UnknownFormatConversionException.class);
 784         tryCatch("%T", UnknownFormatConversionException.class);
 785         tryCatch("%tP", UnknownFormatConversionException.class);
 786         tryCatch("%TP", UnknownFormatConversionException.class);
 787         tryCatch("%.5tB", IllegalFormatPrecisionException.class);
 788         tryCatch("%#tB", FormatFlagsConversionMismatchException.class);
 789         tryCatch("%-tB", MissingFormatWidthException.class);
 790 
 791         //---------------------------------------------------------------------
 792         // %n
 793         //---------------------------------------------------------------------
 794         test("%n", System.getProperty("line.separator"), (Object)null);
 795         test("%n", System.getProperty("line.separator"), "");
 796 
 797         tryCatch("%,n", IllegalFormatFlagsException.class);
 798         tryCatch("%.n", UnknownFormatConversionException.class);
 799         tryCatch("%5.n", UnknownFormatConversionException.class);
 800         tryCatch("%5n", IllegalFormatWidthException.class);
 801         tryCatch("%.7n", IllegalFormatPrecisionException.class);
 802         tryCatch("%<n", IllegalFormatFlagsException.class);
 803 
 804         //---------------------------------------------------------------------
 805         // %%
 806         //---------------------------------------------------------------------
 807         test("%%", "%", (Object)null);
 808         test("%%", "%", "");
 809         tryCatch("%%%", UnknownFormatConversionException.class);
 810         // perhaps an IllegalFormatArgumentIndexException should be defined?
 811         tryCatch("%<%", IllegalFormatFlagsException.class);
 812     }
 813 }