//******************************************************************************
/// Test program.

import com.informagen.F;

public class Ftest {

	public static void main( String[] args) {
		
		System.out.println("\nString:");
		String str = new String("Hello there.");
		show(F.f(str),                                 "Hello there.");
		show(F.f(str, 20),                             "        Hello there.");
		show(F.f(str, 20, F.LJ),                       "Hello there.        ");
		show(F.f(str, 20, F.CJ),                       "    Hello there.    ");
		show(F.f(str, 20, (short)(F.LJ|F.UC)),         "HELLO THERE.        ");
		show(F.f(str, 20, (short)(F.LJ|F.LC)),         "hello there.        ");
		show(F.f((String)null, 20, (short)(F.LJ|F.UC)),"NULL                ");
		show(F.f(str, 8),                              "********");
		show(F.f(str, 8, F.XC),                        "Hello there.");
		show(F.f(str, 8, F.TR),                        "Hello th");

		System.out.println("\nStringBuffer:");
		StringBuffer buf = new StringBuffer(str);
		show(F.f(buf),                                 "Hello there.");
		show(F.f(buf, 20),                             "        Hello there.");
		show(F.f(buf, 20, F.LJ),                       "Hello there.        ");
		show(F.f(buf, 20, F.CJ),                       "    Hello there.    ");
		show(F.f((StringBuffer)null, F.UC),            "NULL");
	
		System.out.println("\nRepeat fill:");
		show(F.f("=", 21, F.RF),                       "=====================");
		show(F.f("+-", 21, F.RF),                      "+-+-+-+-+-+-+-+-+-+-+");
		show(F.f("123", 21, F.RF),                     "123123123123123123123");
		show(F.f("-", 0, F.RF),                        "");
		show(F.f('c', 21, F.RF),                       "ccccccccccccccccccccc");
		show(F.f(new Character('c'), 21, F.RF),        "ccccccccccccccccccccc");
		show(F.f(-123, 21, F.RF),                      "-123-123-123-123-123-" );
		show(F.f((String)null, 21, F.RF),              "nullnullnullnullnulln");
		
		System.out.println("\nboolean:");
		show(F.f(true),                                 "true");
		show(F.f(false, 10, F.LJ),                      "false     ");
		show(F.f(true, 10, F.HX),                       "       0x1");
		show(F.f(true, 10, F.OC),                       "        01");
		show(F.f(true, 10, F.BN),                       "         1");
		show(F.f(false, 10, F.HX),                      "       0x0");
		show(F.f(false, 10, F.OC),                      "        00");
		show(F.f(false, 10, F.BN),                      "         0");
		show(F.f(Boolean.TRUE, 10, F.HX),               "       0x1");

		System.out.println("\nbyte:");
		show(F.f((byte)55),                              "55");
		show(F.f((byte)55, F.BN),                        "110111");
		show(F.f(new Byte((byte)55), F.HX),              "0x37");
		show(F.f((byte)55, 10),                          "        55");
		show(F.f((byte)55, 10, F.LJ),                    "55        ");
		show(F.f((byte)55, 10, F.HX),                    "      0x37");
		show(F.f((byte)55, 10, F.OC),                    "       067");
		show(F.f((byte)55, 10, F.BN),                    "    110111");
		show(F.f(new Byte((byte)55), 10, F.HX),          "      0x37");

		System.out.println("\nchar:");
		show(F.f('c'),                                    "c");
		show(F.f('c', 10),                                "         c");
		show(F.f('c', 10, F.LJ),                          "c         ");
		show(F.f('c', 10, F.HX),                          "    0x0063");
		show(F.f('c', 10, F.OC),                          "      0143");
		show(F.f('c', 10, F.BN),                          "   1100011");
		show(F.f(new Character('c'), 10, F.HX),           "    0x0063");

		System.out.println("\nshort:");
		show(F.f((short)123),                             "123");
		show(F.f((short)123, 10),                         "       123");
		show(F.f((short)123, 10, F.ZF),                   "0000000123");
		show(F.f((short)123, 10, F.LJ),                   "123       " );
		show(F.f((short)-123),                            "-123");
		show(F.f((short)-123, 10),                        "      -123");
		show(F.f((short)-123, 10, F.ZF),                  "-000000123");
		show(F.f((short)-123, 10, F.LJ),                  "-123      " );
		show(F.f(new Short((short)-123), 10, F.HX),       "    0xFF85");

		System.out.println("\nint:");
		show(F.f(123),                                    "123");
		show(F.f(123, 10),                                "       123");
		show(F.f(123, 10, F.ZF),                          "0000000123");
		show(F.f(123, 10, F.LJ),                          "123       " );
		show(F.f(-123),                                   "-123");
		show(F.f(-123, 10),                               "      -123");
		show(F.f(-123, 10, F.ZF),                         "-000000123");
		show(F.f(-123, 10, F.LJ),                         "-123      " );
		show(F.f(new Integer(-123), 10, F.HX),            "0xffffff85");

		System.out.println("\nlong:");
		show(F.f(123L),                                    "123");
		show(F.f(123L, 10),                                "       123");
		show(F.f(123L, 10, F.ZF),                          "0000000123");
		show(F.f(123L, 10, F.LJ),                          "123       " );
		show(F.f(-123L),                                   "-123");
		show(F.f(-123L, 10),                               "      -123");
		show(F.f(-123L, 10, F.ZF),                         "-000000123");
		show(F.f(-123L, 10, F.LJ),                         "-123      " );
		show(F.f(new Long(-123), F.HX),                    "0xffffffffffffff85");
		show(F.f(new Long(-123), (short)(F.HX|F.UC)),      "0xFFFFFFFFFFFFFF85");
		show(F.f(0xdeadbeefcafebabeL),                     "-2401053089206453570");

		System.out.println("\nHexadecimal notation:");
		show(F.f((byte)190, 20, F.HX ),                    "                0xbe");
		show(F.f((short)47806, 20, F.HX ),                 "              0xbabe");
		show(F.f(-889275714, 20, F.HX ),                   "          0xcafebabe");
		show(F.f(-889275714, 20, (short)(F.HX|F.LJ|F.UC)), "0xCAFEBABE          ");
		show(F.f(0xdeadbeefcafebabeL, 20, F.HX),           "  0xdeadbeefcafebabe");
		show(F.f(123.45f, F.HX),                           "0x42f6e666");
		show(F.f(123.45, F.HX),                            "0x405edccccccccccd");

		System.out.println("\nOctal notation:");
		show(F.f((byte)0xbe, 25, F.OC),              "                     0276");
		show(F.f((short)0xcafe, 25, F.OC),           "                  0145376");
		show(F.f(0xcafebabe, 25, F.OC ),             "             031277535276");
		show(F.f(0xdeadbeefcafebabeL, 25, F.OC ),    "  01572555756771277535276");
		show(F.f(123.45f, F.OC),                     "010275563146");
		show(F.f(123.45, F.OC),                      "0401366714631463146315");
		
		System.out.println("\nBinary notation:");
		show(F.f((byte)0xbe, 20, F.BN),              "            10111110");
		show(F.f((short)0xcafe, 20, F.BN),           "    1100101011111110");
		show(F.f((short)0xcafe, (short)(F.BN|F.ZF)), "00001100101011111110");
		show(F.f(123, 32, F.BN),                     "                         1111011");
		show(F.f(-123, 32, F.BN),                    "11111111111111111111111110000101");
		show(F.f(0xcafebabe, F.BN),                  "11001010111111101011101010111110");
		show(F.f(0xdeadbeefcafebabeL, F.BN),         "1101111010101101101111101110111111001010111111101011101010111110");
		show(F.f(123.45f, F.BN),                     "1000010111101101110011001100110");
		show(F.f(123.45, F.BN),                      "100000001011110110111001100110011001100110011001100110011001101");

		System.out.println("\njava.util.Date:");
		java.util.Date date = new java.util.Date();
		show(F.f(date),                            new java.util.Date().toString());		
		show(F.f(date, "dd-MMM HH:mm"),            "dd-MMM HH:mm");
		show(F.f(date, "dd-MMM HH:mm", 20),        "        dd-MMM HH:mm");
		show(F.f(date, "dd-MMM HH:mm", 20, F.LJ),  "dd-MMM HH:mm        ");
		show(F.f(date,  F.SYBASEDATE),             F.SYBASEDATE);
		show(F.f(date,  F.DATE),                   F.DATE);
		show(F.f(date,  F.TIME),                   F.TIME);
		show(F.f(date,  F.TIME, F.LC),             F.TIME);
		show(F.f(date,  F.MILTIME),                F.MILTIME);
		show(F.f(date,  F.MONTH),                  F.MONTH);
		show(F.f(date,  F.WEEKDAY),                F.WEEKDAY);
		show(F.f((java.util.Date)null),            "null");
		
		System.out.println("\njava.awt.Color:");
		show(F.f(java.awt.Color.white),               "255,255,255");
		show(F.f(java.awt.Color.white, F.HX),         "0xff,0xff,0xff");
		show(F.f(java.awt.Color.red),                 "255,0,0");
		show(F.f(java.awt.Color.green),               "0,255,0");
		show(F.f(java.awt.Color.blue),                "0,0,255");
		show(F.f(java.awt.Color.white, 20),           "         255,255,255");
		show(F.f(java.awt.Color.white, 20, F.ZF),     "000000000255,255,255");
		show(F.f(java.awt.Color.white, 20, F.RF),     "255,255,255255,255,2");
		show(F.f(java.awt.Color.white, 20, F.LJ),     "255,255,255         ");
		show(F.f(java.awt.Color.white, 20, F.CJ),     "    255,255,255     ");
		show(F.f(new java.awt.Color(55,55,55), F.HX), "0x37,0x37,0x37");
		show(F.f(new java.awt.Color(55,55,55), F.OC), "067,067,067");
		show(F.f(new java.awt.Color(55,55,55), F.BN), "110111,110111,110111");
		show(F.f((java.awt.Color)null),   "null");
	
		System.out.println("\nobjects:");
		show(F.f(new Boolean(true) ),                 "true");
		show(F.f(new Boolean(false), 10, F.LJ ),      "false     ");
		show(F.f(new Byte((byte)123) ),               "123");
		show(F.f(new Byte((byte)123), 10, F.LJ ),     "123       ");
		show(F.f(new Character('c')),                 "c");
		show(F.f(new Character('c'), 10),             "         c");
		show(F.f(new Character('c'), 10, F.LJ),       "c         ");
		show(F.f(new Integer(123) ),                  "123");
		show(F.f(new Integer(123), 10, F.LJ),         "123       ");
		show(F.f(new Float(123.4) ),                  "123.4");
		show(F.f(new Float(123.4f), 10, F.LJ),        "123.4     ");
		show(F.f(new Double(123.4) ),                 "123.4");
		show(F.f(new Double(123.4), 10, F.LJ),        "123.4     ");
		
		show(F.f((Object)null),                       "null");
		show(F.f((java.util.Vector)null),             "null");
		show(F.f((Float)null),                        "null");
		show(F.f((Double)null),                       "null");

		System.out.println("\nSimilar to fprintf's \"%f\" number of decimals:");		
		show(F.f(22.31, 6, 2),                        " 22.31");
		show(F.f(1.1001, 6, 2),                       "  1.10");
		show(F.f(0.3, 6, 2),                          "  0.30");
		show(F.f((byte)100, 6, 2),                    "100.00");
		show(F.f((short)100, 6, 2),                   "100.00");
		show(F.f(100, 6, 2),                          "100.00");
		show(F.f(100L, 6, 2),                         "100.00");
		    
		show(F.f(123.45, 12, 0),                      "        123.");
		show(F.f(123.45, 12, 1),                      "       123.4");
		show(F.f(123.45, 12, 2),                      "      123.45");
		show(F.f(123.45, 12, 3),                      "     123.450");
		show(F.f(123.45, 12, 4),                      "    123.4500");
		show(F.f(123.45, 12, 5),                      "   123.45000");
		show(F.f(123.45, 12, 6),                      "  123.450000");
		show(F.f(123.45, 12, 7),                      " 123.4500000");
		show(F.f(123, 12, 2),                         "      123.00");
		show(F.f(123L, 12, 2),                        "      123.00");

		show(F.f(0.1, 12, 5),                         "     0.10000");
		show(F.f(0.01, 12, 5),                        "     0.01000");
		show(F.f(0.001, 12, 5),                       "     0.00100");
		show(F.f(0.0001, 12, 5),                      "     0.00010");
		show(F.f(0.00001, 12, 5),                     "     0.00001");
		show(F.f(0.000001, 12, 5),                    "     0.00000");
		show(F.f(0.000001, 12, 10),                   "0.0000010000");
		show(F.f(0.000001, F.DEFAULT, 10),            "0.0000010000");


		System.out.println("\nfloats using significant figures:");
		
		show(F.f(123.456F),                           "123.456" );
		show(F.f(123456000000000000.0F),              "1.23456E17" );

		show(F.f(123.456F, F.DEFAULT, -8),            "123.45600" );
		show(F.f(123.456F, F.DEFAULT, -7),            "123.4560" );
		show(F.f(123.456F, F.DEFAULT, -6),            "123.456" );
		show(F.f(123.456F, F.DEFAULT, -5),            "123.45" );
		show(F.f(123.456F, F.DEFAULT, -4),            "123.4" );
		show(F.f(123.456F, F.DEFAULT, -3),            "123" );
		show(F.f(123.456F, F.DEFAULT, -2),            "120" );
		show(F.f(123.456F, F.DEFAULT, -1),            "100" );

		show(F.f(123.456F, 10, -8),                   " 123.45600" );
		show(F.f(123.456F, 10, -7),                   "  123.4560" );
		show(F.f(123.456F, 10, -6),                   "   123.456" );
		show(F.f(123.456F, 10, -5),                   "    123.45" );
		show(F.f(123.456F, 10, -4),                   "     123.4" );
		show(F.f(123.456F, 10, -3),                   "       123" );
		show(F.f(123.456F, 10, -2),                   "       120" );
		show(F.f(123.456F, 10, -1),                   "       100" );
		show(F.f(123.456F, 10, -1, F.CJ),             "   100    " );
		show(F.f(-123.456F, 10, -1, F.CJ),            "   -100   " );
		

		System.out.println("\nfloats & doubles using significant figures:");		
		show(F.f(123456000000000000.0F, F.DEFAULT, -4), "1.234E17");
		show(F.f(1.23456e17F, F.DEFAULT, -4),           "1.234E17");
		show(F.f(1.23456E17F, F.DEFAULT, -4, F.LC),     "1.234e17");
		show(F.f(1.23456E17F, F.DEFAULT, 0, F.LC),      "1.e17");
		
		show(F.f(-123.456F, F.DEFAULT, -4),             "-123.4");
		show(F.f(-1.23456e2F, F.DEFAULT, -4),           "-123.4");


		
		System.out.println("\nfloats & doubles using default precisions:");		
		show(F.f(1.234567890123456789F),                      "1.2345679");
		show(F.f(1.234567890123456789D),                      "1.2345678901234567");
		
		show(F.f(1234567890123456789F),                       "1.23456794E18");
		show(F.f(1234567890123456789D),                       "1.23456789012345677E18");
		
		show(F.f(0.000000000000000000001234567890123456789F), "1.2345679E-21");
		show(F.f(0.000000000000000000001234567890123456789D), "1.2345678901234568E-21");
		



		// Unable to create an overloaded signature for (Double, int, int) because it is
		//   ambiguous with (Object, int, short). 
		// So just use the full signature with the flags set to RJ (right justify)
		
		show(F.f(new Double("1.2e0"),  F.DEFAULT, 5, F.RJ), "1.20000");
		show(F.f(new Double("1.2e-0"), F.DEFAULT, 5, F.RJ), "1.20000");
		show(F.f(new Double("1.2e-1"), F.DEFAULT, 5, F.RJ), "0.12000");


		System.out.println("\nNaN, positive and negative infinity:");		
		show(F.f(1F/0),                           "Infinity");		
		show(F.f(-1D/0),                          "-Infinity");
		show(F.f(-1D/0, F.UC),                    "-INFINITY");
		show(F.f(-1D/0, F.LC),                    "-infinity");
		
		show(F.f(0F/0),                           "NaN");	
		show(F.f(0F/0),                           "NaN");
		  
		show(F.f(Math.sqrt(-1)),                  "NaN");
		
		show(F.f(Float.NaN, F.HX),                "0x7fc00000");
		show(F.f(Float.POSITIVE_INFINITY, F.HX),  "0x7f800000");
		show(F.f(Float.NEGATIVE_INFINITY, F.HX),  "0xff800000");

		show(F.f(Double.NaN, F.HX),               "0x7ff8000000000000");
		show(F.f(Double.POSITIVE_INFINITY, F.HX), "0x7ff0000000000000");
		show(F.f(Double.NEGATIVE_INFINITY, F.HX), "0xfff0000000000000");
				

		System.out.println("\nFormatted table");
		
		int firstColumn = 6;
		int otherColumns = 12;
		int decimals = 4;
		
		System.out.println(F.f("Angle", firstColumn, F.LJ) + F.f("Sine", otherColumns) + 
		                   F.f("Cosine", otherColumns) + F.f("Tangent", otherColumns));
		                   
		System.out.println(F.f("-", firstColumn + 3*otherColumns, F.RF));
		
		for (int a=0; a<=360.; a+=15.)
			System.out.println(F.f(a, firstColumn, F.LJ) +
			                   F.f(Math.sin((a/180.)*Math.PI), otherColumns, decimals) +
			                   F.f(Math.cos((a/180.)*Math.PI), otherColumns, decimals) +
		                       F.f(Math.tan((a/180.)*Math.PI), otherColumns, decimals));

	}

	// "Should be" and "is" display
	
	private static void show(String is, String sb) {
		System.out.println( "S/B: >" + sb + "<" );
		System.out.println( " Is: >" + is + "<" );
	}
	
}