use of android.icu.text.NumberFormat in project j2objc by google.
the class TestMessageFormat method TestDateFormatHashCode.
public void TestDateFormatHashCode() {
DateFormat testDF = DateFormat.getDateInstance(DateFormat.DEFAULT, ULocale.GERMAN);
NumberFormat testNF = testDF.getNumberFormat();
int expectedResult = testNF.getMaximumIntegerDigits() * 37 + testNF.getMaximumFractionDigits();
int actualHashResult = testDF.hashCode();
assertEquals("DateFormat hashCode", expectedResult, actualHashResult);
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class TimeUnitTest method TestGreekWithSanitization.
/**
* @bug9042
* Performs tests for Greek.
* This tests that if the plural count listed in time unit format does not
* match those in the plural rules for the locale, those plural count in
* time unit format will be ingored and subsequently, fall back will kick in
* which is tested above.
* Without data sanitization, setNumberFormat() would crash.
* As of CLDR shiped in ICU4.8, Greek is one such language.
*/
@Test
public void TestGreekWithSanitization() {
ULocale loc = new ULocale("el");
NumberFormat numfmt = NumberFormat.getInstance(loc);
TimeUnitFormat tuf = new TimeUnitFormat(loc);
tuf.parseObject("", new ParsePosition(0));
tuf.setNumberFormat(numfmt);
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class TimeUnitTest method Test10219FractionalPlurals.
@Test
public void Test10219FractionalPlurals() {
TimeUnitFormat tuf = new TimeUnitFormat(ULocale.ENGLISH, TimeUnitFormat.FULL_NAME);
String[] expected = { "1 minute", "1.5 minutes", "1.58 minutes" };
for (int i = 2; i >= 0; i--) {
NumberFormat nf = NumberFormat.getNumberInstance(ULocale.ENGLISH);
nf.setRoundingMode(BigDecimal.ROUND_DOWN);
nf.setMaximumFractionDigits(i);
tuf.setNumberFormat(nf);
assertEquals("Test10219", expected[i], tuf.format(new TimeUnitAmount(1.588, TimeUnit.MINUTE)));
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class WriteNumberFormatSerialTestData method main.
public static void main(String[] args) {
NumberFormat nf = NumberFormat.getInstance(Locale.US);
NumberFormat nfc = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat nfp = NumberFormat.getPercentInstance(Locale.US);
NumberFormat nfsp = NumberFormat.getScientificInstance(Locale.US);
try {
FileOutputStream file = new FileOutputStream("NumberFormatSerialTestData.java");
file.write(header.getBytes());
write(file, (Object) nf, "generalInstance", "//NumberFormat.getInstance(Locale.US)");
write(file, (Object) nfc, "currencyInstance", "//NumberFormat.getCurrencyInstance(Locale.US)");
write(file, (Object) nfp, "percentInstance", "//NumberFormat.getPercentInstance(Locale.US)");
write(file, (Object) nfsp, "scientificInstance", "//NumberFormat.getScientificInstance(Locale.US)");
file.write(footer.getBytes());
file.close();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class RelativeDateTimeFormatterTest method TestCustomNumberFormat.
@Test
public void TestCustomNumberFormat() {
ULocale loc = new ULocale("en_US");
NumberFormat nf = NumberFormat.getInstance(loc);
nf.setMinimumFractionDigits(1);
nf.setMaximumFractionDigits(1);
RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(loc, nf);
// Change nf after the fact to prove that we made a defensive copy
nf.setMinimumFractionDigits(3);
nf.setMaximumFractionDigits(3);
// Change getNumberFormat to prove we made defensive copy going out.
fmt.getNumberFormat().setMinimumFractionDigits(5);
assertEquals("TestCustomNumberformat", 1, fmt.getNumberFormat().getMinimumFractionDigits());
Object[][] data = { { 0.0, Direction.NEXT, RelativeUnit.SECONDS, "in 0.0 seconds" }, { 0.5, Direction.NEXT, RelativeUnit.SECONDS, "in 0.5 seconds" }, { 1.0, Direction.NEXT, RelativeUnit.SECONDS, "in 1.0 seconds" }, { 2.0, Direction.NEXT, RelativeUnit.SECONDS, "in 2.0 seconds" } };
for (Object[] row : data) {
String actual = fmt.format(((Double) row[0]).doubleValue(), (Direction) row[1], (RelativeUnit) row[2]);
assertEquals("Relative date with quantity special NumberFormat", row[3], actual);
}
}
Aggregations