use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method testDoubleZero.
@Test
public void testDoubleZero() {
ULocale en = new ULocale("en");
NumberFormat nf = NumberFormat.getInstance(en);
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
MeasureFormat mf = MeasureFormat.getInstance(en, FormatWidth.WIDE, nf);
assertEquals("Positive Rounding", "4 hours, 23 minutes, 16.00 seconds", mf.formatMeasures(new Measure(4.7, MeasureUnit.HOUR), new Measure(23, MeasureUnit.MINUTE), new Measure(16, MeasureUnit.SECOND)));
assertEquals("Negative Rounding", "-4 hours, 23 minutes, 16.00 seconds", mf.formatMeasures(new Measure(-4.7, MeasureUnit.HOUR), new Measure(23, MeasureUnit.MINUTE), new Measure(16, MeasureUnit.SECOND)));
}
use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method Test10219FractionalPlurals.
@Test
public void Test10219FractionalPlurals() {
double[] values = { 1.588, 1.011 };
String[][] expected = { { "1 minute", "1.5 minutes", "1.58 minutes" }, { "1 minute", "1.0 minutes", "1.01 minutes" } };
for (int j = 0; j < values.length; j++) {
for (int i = 0; i < expected[j].length; i++) {
NumberFormat nf = NumberFormat.getNumberInstance(ULocale.ENGLISH);
nf.setRoundingMode(BigDecimal.ROUND_DOWN);
nf.setMinimumFractionDigits(i);
nf.setMaximumFractionDigits(i);
MeasureFormat mf = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE, nf);
assertEquals("Test10219", expected[j][i], mf.format(new Measure(values[j], MeasureUnit.MINUTE)));
}
}
}
use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method TestExamplesInDocs.
@Test
public void TestExamplesInDocs() {
MeasureFormat fmtFr = MeasureFormat.getInstance(ULocale.FRENCH, FormatWidth.SHORT);
Measure measure = new Measure(23, MeasureUnit.CELSIUS);
assertEquals("23 °C", "23 °C", fmtFr.format(measure));
Measure measureF = new Measure(70, MeasureUnit.FAHRENHEIT);
assertEquals("70 °F", "70 °F", fmtFr.format(measureF));
MeasureFormat fmtFrFull = MeasureFormat.getInstance(ULocale.FRENCH, FormatWidth.WIDE);
assertEquals("70 pied et 5,3 pouces", "70 pieds et 5,3 pouces", fmtFrFull.formatMeasures(new Measure(70, MeasureUnit.FOOT), new Measure(5.3, MeasureUnit.INCH)));
assertEquals("1 pied et 1 pouce", "1 pied et 1 pouce", fmtFrFull.formatMeasures(new Measure(1, MeasureUnit.FOOT), new Measure(1, MeasureUnit.INCH)));
MeasureFormat fmtFrNarrow = MeasureFormat.getInstance(ULocale.FRENCH, FormatWidth.NARROW);
assertEquals("1′ 1″", "1′ 1″", fmtFrNarrow.formatMeasures(new Measure(1, MeasureUnit.FOOT), new Measure(1, MeasureUnit.INCH)));
MeasureFormat fmtEn = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
assertEquals("1 inch, 2 feet", "1 inch, 2 feet", fmtEn.formatMeasures(new Measure(1, MeasureUnit.INCH), new Measure(2, MeasureUnit.FOOT)));
}
use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method testFormatSingleArg.
@Test
public void testFormatSingleArg() {
MeasureFormat mf = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
assertEquals("", "5 meters", mf.format(new Measure(5, MeasureUnit.METER)));
}
use of android.icu.util.Measure in project j2objc by google.
the class MeasureUnitTest method testFormatMeasuresOneArg.
@Test
public void testFormatMeasuresOneArg() {
MeasureFormat mf = MeasureFormat.getInstance(ULocale.ENGLISH, FormatWidth.WIDE);
assertEquals("", "5 meters", mf.formatMeasures(new Measure(5, MeasureUnit.METER)));
}
Aggregations