use of tests.support.Support_DecimalFormat in project robovm by robovm.
the class OldDecimalFormatTest method test_formatDLjava_lang_StringBufferLjava_text_FieldPosition.
public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition() {
new Support_DecimalFormat("test_formatDLjava_lang_StringBufferLjava_text_FieldPosition").t_format_with_FieldPosition();
int failCount = 0;
BitSet failures = new BitSet();
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
DecimalFormat df = new DecimalFormat("00.0#E0", dfs);
compare("00.0#E0: 0.0", df.format(0.0), "00.0E0");
compare("00.0#E0: 1.0", df.format(1.0), "10.0E-1");
compare("00.0#E0: 12.0", df.format(12.0), "12.0E0");
compare("00.0#E0: 123.0", df.format(123.0), "12.3E1");
compare("00.0#E0: 1234.0", df.format(1234.0), "12.34E2");
compare("00.0#E0: 12346.0", df.format(12346.0), "12.35E3");
compare("00.0#E0: 99999.0", df.format(99999.0), "10.0E4");
compare("00.0#E0: 1.2", df.format(1.2), "12.0E-1");
compare("00.0#E0: 12.3", df.format(12.3), "12.3E0");
compare("00.0#E0: 123.4", df.format(123.4), "12.34E1");
compare("00.0#E0: 1234.6", df.format(1234.6), "12.35E2");
compare("00.0#E0: 9999.9", df.format(9999.9), "10.0E3");
compare("00.0#E0: 0.1", df.format(0.1), "10.0E-2");
compare("00.0#E0: 0.12", df.format(0.12), "12.0E-2");
compare("00.0#E0: 0.123", df.format(0.123), "12.3E-2");
compare("00.0#E0: 0.1234", df.format(0.1234), "12.34E-2");
compare("00.0#E0: 0.12346", df.format(0.12346), "12.35E-2");
compare("00.0#E0: 0.99999", df.format(0.99999), "10.0E-1");
compare("00.0#E0: -0.0", df.format(-0.0), "-00.0E0");
compare("00.0#E0: -1.0", df.format(-1.0), "-10.0E-1");
compare("00.0#E0: -12.0", df.format(-12.0), "-12.0E0");
compare("00.0#E0: -123.0", df.format(-123.0), "-12.3E1");
compare("00.0#E0: -1234.0", df.format(-1234.0), "-12.34E2");
compare("00.0#E0: -12346.0", df.format(-12346.0), "-12.35E3");
compare("00.0#E0: -99999.0", df.format(-99999.0), "-10.0E4");
df = new DecimalFormat("##0.0E0", dfs);
compare("##0.0E0: -0.0", df.format(-0.0), "-0.0E0");
compare("##0.0E0: 0.0", df.format(0.0), "0.0E0");
compare("##0.0E0: 1.0", df.format(1.0), "1.0E0");
compare("##0.0E0: 12.0", df.format(12.0), "12E0");
// Android fails, here!
compare("##0.0E0: 123.0", df.format(123.0), "123E0");
compare("##0.0E0: 1234.0", df.format(1234.0), "1.234E3");
compare("##0.0E0: 12346.0", df.format(12346.0), "12.35E3");
// Fails in JDK 1.2.2
if (!compare(failCount, df.format(99999.0), "100E3"))
failures.set(failCount);
failCount++;
compare("##0.0E0: 999999.0", df.format(999999.0), "1.0E6");
df = new DecimalFormat("#00.0##E0", dfs);
compare("#00.0##E0: 0.1", df.format(0.1), "100E-3");
compare("#00.0##E0: 0.12", df.format(0.12), "120E-3");
compare("#00.0##E0: 0.123", df.format(0.123), "123E-3");
compare("#00.0##E0: 0.1234", df.format(0.1234), "123.4E-3");
compare("#00.0##E0: 0.1234567", df.format(0.1234567), "123.457E-3");
compare("#00.0##E0: 0.01", df.format(0.01), "10.0E-3");
compare("#00.0##E0: 0.012", df.format(0.012), "12.0E-3");
compare("#00.0##E0: 0.0123", df.format(0.0123), "12.3E-3");
compare("#00.0##E0: 0.01234", df.format(0.01234), "12.34E-3");
compare("#00.0##E0: 0.01234567", df.format(0.01234567), "12.3457E-3");
compare("#00.0##E0: 0.001", df.format(0.001), "1.00E-3");
compare("#00.0##E0: 0.0012", df.format(0.0012), "1.20E-3");
compare("#00.0##E0: 0.00123", df.format(0.00123), "1.23E-3");
compare("#00.0##E0: 0.001234", df.format(0.001234), "1.234E-3");
compare("#00.0##E0: 0.001234567", df.format(0.001234567), "1.23457E-3");
compare("#00.0##E0: 0.0001", df.format(0.0001), "100E-6");
compare("#00.0##E0: 0.00012", df.format(0.00012), "120E-6");
compare("#00.0##E0: 0.000123", df.format(0.000123), "123E-6");
compare("#00.0##E0: 0.0001234", df.format(0.0001234), "123.4E-6");
compare("#00.0##E0: 0.0001234567", df.format(0.0001234567), "123.457E-6");
// Fails in JDK 1.2.2
if (!compare(failCount, df.format(0.0), "0.00E0"))
failures.set(failCount);
failCount++;
compare("#00.0##E0: 1.0", df.format(1.0), "1.00E0");
compare("#00.0##E0: 12.0", df.format(12.0), "12.0E0");
compare("#00.0##E0: 123.0", df.format(123.0), "123E0");
compare("#00.0##E0: 1234.0", df.format(1234.0), "1.234E3");
compare("#00.0##E0: 12345.0", df.format(12345.0), "12.345E3");
compare("#00.0##E0: 123456.0", df.format(123456.0), "123.456E3");
compare("#00.0##E0: 1234567.0", df.format(1234567.0), "1.23457E6");
compare("#00.0##E0: 12345678.0", df.format(12345678.0), "12.3457E6");
compare("#00.0##E0: 99999999.0", df.format(99999999.0), "100E6");
df = new DecimalFormat("#.0E0", dfs);
compare("#.0E0: -0.0", df.format(-0.0), "-.0E0");
compare("#.0E0: 0.0", df.format(0.0), ".0E0");
compare("#.0E0: 1.0", df.format(1.0), ".1E1");
compare("#.0E0: 12.0", df.format(12.0), ".12E2");
compare("#.0E0: 123.0", df.format(123.0), ".12E3");
compare("#.0E0: 1234.0", df.format(1234.0), ".12E4");
compare("#.0E0: 9999.0", df.format(9999.0), ".1E5");
df = new DecimalFormat("0.#E0", dfs);
compare("0.#E0: -0.0", df.format(-0.0), "-0E0");
compare("0.#E0: 0.0", df.format(0.0), "0E0");
compare("0.#E0: 1.0", df.format(1.0), "1E0");
compare("0.#E0: 12.0", df.format(12.0), "1.2E1");
compare("0.#E0: 123.0", df.format(123.0), "1.2E2");
compare("0.#E0: 1234.0", df.format(1234.0), "1.2E3");
compare("0.#E0: 9999.0", df.format(9999.0), "1E4");
df = new DecimalFormat(".0E0", dfs);
compare(".0E0: -0.0", df.format(-0.0), "-.0E0");
compare(".0E0: 0.0", df.format(0.0), ".0E0");
compare(".0E0: 1.0", df.format(1.0), ".1E1");
compare(".0E0: 12.0", df.format(12.0), ".1E2");
compare(".0E0: 123.0", df.format(123.0), ".1E3");
compare(".0E0: 1234.0", df.format(1234.0), ".1E4");
compare(".0E0: 9999.0", df.format(9999.0), ".1E5");
df = new DecimalFormat("0.E0", dfs);
// Fails in JDK 1.2.2
if (!compare(failCount, df.format(0.0), "0.E0"))
failures.set(failCount);
failCount++;
if (!compare(failCount, df.format(1.0), "1.E0"))
failures.set(failCount);
failCount++;
if (!compare(failCount, df.format(12.0), "1.E1"))
failures.set(failCount);
failCount++;
if (!compare(failCount, df.format(123.0), "1.E2"))
failures.set(failCount);
failCount++;
if (!compare(failCount, df.format(1234.0), "1.E3"))
failures.set(failCount);
failCount++;
if (!compare(failCount, df.format(9999.0), "1.E4"))
failures.set(failCount);
failCount++;
df = new DecimalFormat("##0.00#E0", dfs);
compare("##0.00#E0: 0.1", df.format(0.1), "100E-3");
compare("##0.00#E0: 0.1234567", df.format(0.1234567), "123.457E-3");
compare("##0.00#E0: 0.9999999", df.format(0.9999999), "1.00E0");
compare("##0.00#E0: 0.01", df.format(0.01), "10.0E-3");
compare("##0.00#E0: 0.01234567", df.format(0.01234567), "12.3457E-3");
compare("##0.00#E0: 0.09999999", df.format(0.09999999), "100E-3");
compare("##0.00#E0: 0.001", df.format(0.001), "1.00E-3");
compare("##0.00#E0: 0.001234567", df.format(0.001234567), "1.23457E-3");
compare("##0.00#E0: 0.009999999", df.format(0.009999999), "10.0E-3");
compare("##0.00#E0: 0.0001", df.format(0.0001), "100E-6");
compare("##0.00#E0: 0.0001234567", df.format(0.0001234567), "123.457E-6");
compare("##0.00#E0: 0.0009999999", df.format(0.0009999999), "1.00E-3");
df = new DecimalFormat("###0.00#E0", dfs);
compare("###0.00#E0: 0.1", df.format(0.1), "1000E-4");
compare("###0.00#E0: 0.12345678", df.format(0.12345678), "1234.568E-4");
compare("###0.00#E0: 0.99999999", df.format(0.99999999), "1.00E0");
compare("###0.00#E0: 0.01", df.format(0.01), "100E-4");
compare("###0.00#E0: 0.012345678", df.format(0.012345678), "123.4568E-4");
compare("###0.00#E0: 0.099999999", df.format(0.099999999), "1000E-4");
compare("###0.00#E0: 0.001", df.format(0.001), "10.0E-4");
compare("###0.00#E0: 0.0012345678", df.format(0.0012345678), "12.34568E-4");
compare("###0.00#E0: 0.0099999999", df.format(0.0099999999), "100E-4");
compare("###0.00#E0: 0.0001", df.format(0.0001), "1.00E-4");
compare("###0.00#E0: 0.00012345678", df.format(0.00012345678), "1.234568E-4");
compare("###0.00#E0: 0.00099999999", df.format(0.00099999999), "10.0E-4");
// Fails in JDK 1.2.2
if (!compare(failCount, df.format(0.00001), "1000E-8"))
failures.set(failCount);
failCount++;
compare("###0.00#E0: 0.000012345678", df.format(0.000012345678), "1234.568E-8");
compare("###0.00#E0: 0.000099999999", df.format(0.000099999999), "1.00E-4");
df = new DecimalFormat("###0.0#E0", dfs);
compare("###0.0#E0: 0.1", df.format(0.1), "1000E-4");
compare("###0.0#E0: 0.1234567", df.format(0.1234567), "1234.57E-4");
compare("###0.0#E0: 0.9999999", df.format(0.9999999), "1.0E0");
// Fails in JDK 1.2.2
if (!compare(failCount, df.format(0.01), "100E-4"))
failures.set(failCount);
failCount++;
compare("###0.0#E0: 0.01234567", df.format(0.01234567), "123.457E-4");
compare("###0.0#E0: 0.09999999", df.format(0.09999999), "1000E-4");
compare("###0.0#E0: 0.001", df.format(0.001), "10E-4");
compare("###0.0#E0: 0.001234567", df.format(0.001234567), "12.3457E-4");
// Fails in JDK 1.2.2
if (!compare(failCount, df.format(0.009999999), "100E-4"))
failures.set(failCount);
failCount++;
compare("###0.0#E0: 0.0001", df.format(0.0001), "1.0E-4");
compare("###0.0#E0: 0.0001234567", df.format(0.0001234567), "1.23457E-4");
compare("###0.0#E0: 0.0009999999", df.format(0.0009999999), "10E-4");
// Fails in JDK 1.2.2
if (!compare(failCount, df.format(0.00001), "1000E-8"))
failures.set(failCount);
failCount++;
compare("###0.0#E0: 0.00001234567", df.format(0.00001234567), "1234.57E-8");
compare("###0.0#E0: 0.00009999999", df.format(0.00009999999), "1.0E-4");
assertTrue("Failed " + failures + " of " + failCount, failures.length() == 0);
String formatString = "##0.#";
df = new DecimalFormat(formatString, dfs);
df.setMinimumFractionDigits(30);
compare(formatString + ": 0.000000000000000000000000000000", df.format(0.0), "0.000000000000000000000000000000");
compare(formatString + ": -0.000000000000000000000000000000", df.format(-0.0), "-0.000000000000000000000000000000");
compare(formatString + ": 1.000000000000000000000000000000", df.format(1.0), "1.000000000000000000000000000000");
compare(formatString + ": -1.000000000000000000000000000000", df.format(-1.0), "-1.000000000000000000000000000000");
df = new DecimalFormat(formatString);
df.setMaximumFractionDigits(30);
compare(formatString + ": 0", df.format(0.0), "0");
compare(formatString + ": -0", df.format(-0.0), "-0");
compare(formatString + ": 1", df.format(1.0), "1");
compare(formatString + ": -1", df.format(-1.0), "-1");
}
Aggregations