use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method testMultiples.
@Test
public void testMultiples() {
ULocale russia = new ULocale("ru");
Object[][] data = new Object[][] { { ULocale.ENGLISH, FormatWidth.WIDE, "2 miles, 1 foot, 2.3 inches" }, { ULocale.ENGLISH, FormatWidth.SHORT, "2 mi, 1 ft, 2.3 in" }, { ULocale.ENGLISH, FormatWidth.NARROW, "2mi 1\u2032 2.3\u2033" }, { russia, FormatWidth.WIDE, "2 \u043C\u0438\u043B\u0438 1 \u0444\u0443\u0442 \u0438 2,3 \u0434\u044E\u0439\u043C\u0430" }, { russia, FormatWidth.SHORT, "2 \u043C\u0438\u043B\u0438 1 \u0444\u0443\u0442 \u0438 2,3 \u0434\u044E\u0439\u043C." }, { russia, FormatWidth.NARROW, "2 \u043C\u0438\u043B\u044C 1 \u0444\u0443\u0442 2,3 \u0434\u044E\u0439\u043C\u0430" } };
for (Object[] row : data) {
MeasureFormat mf = MeasureFormat.getInstance((ULocale) row[0], (FormatWidth) row[1]);
assertEquals("testMultiples", row[2], mf.formatMeasures(new Measure(2, MeasureUnit.MILE), new Measure(1, MeasureUnit.FOOT), new Measure(2.3, MeasureUnit.INCH)));
}
}
use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method testIndividualPluralFallback.
@Test
public void testIndividualPluralFallback() {
// See ticket #11986 "incomplete fallback in MeasureFormat".
// In CLDR 28, fr_CA temperature-generic/short has only the "one" form,
// and falls back to fr for the "other" form.
MeasureFormat mf = MeasureFormat.getInstance(new ULocale("fr_CA"), FormatWidth.SHORT);
Measure twoDeg = new Measure(2, MeasureUnit.GENERIC_TEMPERATURE);
assertEquals("2 deg temp in fr_CA", "2°", mf.format(twoDeg));
}
use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method testCurrencyFormatStandInForMeasureFormat.
@Test
public void testCurrencyFormatStandInForMeasureFormat() {
MeasureFormat mf = MeasureFormat.getCurrencyFormat(ULocale.ENGLISH);
assertEquals("70 feet, 5.3 inches", "70 feet, 5.3 inches", mf.formatMeasures(new Measure(70, MeasureUnit.FOOT), new Measure(5.3, MeasureUnit.INCH)));
assertEquals("getLocale", ULocale.ENGLISH, mf.getLocale());
assertEquals("getNumberFormat", ULocale.ENGLISH, mf.getNumberFormat().getLocale(ULocale.VALID_LOCALE));
assertEquals("getWidth", MeasureFormat.FormatWidth.WIDE, mf.getWidth());
}
use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method testFieldPositionMultiple.
@Test
public void testFieldPositionMultiple() {
MeasureFormat fmt = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.SHORT);
FieldPosition pos = new FieldPosition(NumberFormat.Field.INTEGER);
String result = fmt.formatMeasures(new StringBuilder(), pos, new Measure(354, MeasureUnit.METER), new Measure(23, MeasureUnit.CENTIMETER)).toString();
assertEquals("result", "354 m, 23 cm", result);
// According to javadocs for {@link Format#format} FieldPosition is set to
// beginning and end of first such field encountered instead of the last
// such field encountered.
assertEquals("beginIndex", 0, pos.getBeginIndex());
assertEquals("endIndex", 3, pos.getEndIndex());
pos = new FieldPosition(NumberFormat.Field.DECIMAL_SEPARATOR);
result = fmt.formatMeasures(new StringBuilder("123456: "), pos, new Measure(354, MeasureUnit.METER), new Measure(23, MeasureUnit.CENTIMETER), new Measure(5.4, MeasureUnit.MILLIMETER)).toString();
assertEquals("result", "123456: 354 m, 23 cm, 5.4 mm", result);
assertEquals("beginIndex", 23, pos.getBeginIndex());
assertEquals("endIndex", 24, pos.getEndIndex());
result = fmt.formatMeasures(new StringBuilder(), pos, new Measure(3, MeasureUnit.METER), new Measure(23, MeasureUnit.CENTIMETER), new Measure(5.4, MeasureUnit.MILLIMETER)).toString();
assertEquals("result", "3 m, 23 cm, 5.4 mm", result);
assertEquals("beginIndex", 13, pos.getBeginIndex());
assertEquals("endIndex", 14, pos.getEndIndex());
pos = new FieldPosition(NumberFormat.Field.DECIMAL_SEPARATOR);
result = fmt.formatMeasures(new StringBuilder("123456: "), pos, new Measure(3, MeasureUnit.METER), new Measure(23, MeasureUnit.CENTIMETER), new Measure(5, MeasureUnit.MILLIMETER)).toString();
assertEquals("result", "123456: 3 m, 23 cm, 5 mm", result);
assertEquals("beginIndex", 0, pos.getBeginIndex());
assertEquals("endIndex", 0, pos.getEndIndex());
pos = new FieldPosition(NumberFormat.Field.INTEGER);
result = fmt.formatMeasures(new StringBuilder("123456: "), pos, new Measure(57, MeasureUnit.MILLIMETER)).toString();
assertEquals("result", "123456: 57 mm", result);
assertEquals("beginIndex", 8, pos.getBeginIndex());
assertEquals("endIndex", 10, pos.getEndIndex());
}
use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method testFieldPosition.
@Test
public void testFieldPosition() {
MeasureFormat fmt = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.SHORT);
FieldPosition pos = new FieldPosition(NumberFormat.Field.DECIMAL_SEPARATOR);
fmt.format(new Measure(43.5, MeasureUnit.FOOT), new StringBuffer("123456: "), pos);
assertEquals("beginIndex", 10, pos.getBeginIndex());
assertEquals("endIndex", 11, pos.getEndIndex());
pos = new FieldPosition(NumberFormat.Field.DECIMAL_SEPARATOR);
fmt.format(new Measure(43, MeasureUnit.FOOT), new StringBuffer(), pos);
assertEquals("beginIndex", 0, pos.getBeginIndex());
assertEquals("endIndex", 0, pos.getEndIndex());
}
Aggregations