use of android.icu.text.CompactDecimalFormat in project j2objc by google.
the class CompactDecimalFormatTest method TestParsing.
@Test
public void TestParsing() {
CompactDecimalFormat cdf = CompactDecimalFormat.getInstance(ULocale.ENGLISH, CompactStyle.LONG);
try {
cdf.parse("Parse for failure", new ParsePosition(0));
} catch (UnsupportedOperationException e) {
// Exception expected, thus return.
return;
}
fail("Parsing currently unsupported, expected test to fail but passed");
}
use of android.icu.text.CompactDecimalFormat in project j2objc by google.
the class CompactDecimalFormatTest method TestBug12689.
@Test
public void TestBug12689() {
if (logKnownIssue("12689", "CDF fails for numbers less than 1 thousand in most locales")) {
return;
}
CompactDecimalFormat cdf;
String result;
cdf = CompactDecimalFormat.getInstance(ULocale.forLanguageTag("en"), CompactStyle.SHORT);
result = cdf.format(new CurrencyAmount(123, Currency.getInstance("USD")));
assertEquals("CDF should correctly format 123 with currency in 'en'", "$120", result);
cdf = CompactDecimalFormat.getInstance(ULocale.forLanguageTag("it"), CompactStyle.SHORT);
result = cdf.format(new CurrencyAmount(123, Currency.getInstance("EUR")));
assertEquals("CDF should correctly format 123 with currency in 'it'", "120 €", result);
}
use of android.icu.text.CompactDecimalFormat in project j2objc by google.
the class CompactDecimalFormatTest method TestWriteAndReadObject.
@Test
public void TestWriteAndReadObject() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream objoutstream = new ObjectOutputStream(baos);
CompactDecimalFormat cdf = CompactDecimalFormat.getInstance(ULocale.ENGLISH, CompactStyle.LONG);
try {
objoutstream.writeObject(cdf);
} catch (NotSerializableException e) {
if (logKnownIssue("10494", "PluralRules is not serializable")) {
logln("NotSerializableException thrown when serializing CopactDecimalFormat");
} else {
errln("NotSerializableException thrown when serializing CopactDecimalFormat");
}
} finally {
objoutstream.close();
}
// This test case relies on serialized byte stream which might be premature
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream objinstream = new ObjectInputStream(bais);
try {
cdf = (CompactDecimalFormat) objinstream.readObject();
} catch (NotSerializableException e) {
if (logKnownIssue("10494", "PluralRules is not de-serializable")) {
logln("NotSerializableException thrown when deserializing CopactDecimalFormat");
} else {
errln("NotSerializableException thrown when deserializing CopactDecimalFormat");
}
} catch (ClassNotFoundException e) {
errln("ClassNotFoundException: " + e.getMessage());
} finally {
objinstream.close();
}
}
use of android.icu.text.CompactDecimalFormat in project j2objc by google.
the class CompactDecimalFormatTest method getCDFInstance.
private static CompactDecimalFormat getCDFInstance(ULocale locale, CompactStyle style) {
CompactDecimalFormat result = CompactDecimalFormat.getInstance(locale, style);
// Our tests are written for two significant digits. We set explicitly here
// because default significant digits may change.
result.setMaximumSignificantDigits(2);
return result;
}
use of android.icu.text.CompactDecimalFormat in project j2objc by google.
the class CompactDecimalFormatTest method TestBig.
@Test
public void TestBig() {
CompactDecimalFormat cdf = CompactDecimalFormat.getInstance(ULocale.ENGLISH, CompactStyle.LONG);
BigInteger source_int = new BigInteger("31415926535897932384626433");
assertEquals("BigInteger format wrong: ", "31,000,000,000,000 trillion", cdf.format(source_int));
BigDecimal source_dec = new BigDecimal(source_int);
assertEquals("BigDecimal format wrong: ", "31,000,000,000,000 trillion", cdf.format(source_dec));
}
Aggregations