Search in sources :

Example 6 with Measure

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)));
}
Also used : ULocale(android.icu.util.ULocale) Measure(android.icu.util.Measure) MeasureFormat(android.icu.text.MeasureFormat) NumberFormat(android.icu.text.NumberFormat) Test(org.junit.Test)

Example 7 with Measure

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)));
        }
    }
}
Also used : Measure(android.icu.util.Measure) MeasureFormat(android.icu.text.MeasureFormat) NumberFormat(android.icu.text.NumberFormat) Test(org.junit.Test)

Example 8 with Measure

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)));
}
Also used : Measure(android.icu.util.Measure) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 9 with Measure

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)));
}
Also used : Measure(android.icu.util.Measure) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 10 with Measure

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)));
}
Also used : Measure(android.icu.util.Measure) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Aggregations

Measure (android.icu.util.Measure)31 MeasureFormat (android.icu.text.MeasureFormat)26 Test (org.junit.Test)22 ULocale (android.icu.util.ULocale)7 FieldPosition (java.text.FieldPosition)7 ArrayList (java.util.ArrayList)7 SpannableStringBuilder (android.text.SpannableStringBuilder)6 TtsSpan (android.text.style.TtsSpan)6 Locale (java.util.Locale)6 FormatWidth (android.icu.text.MeasureFormat.FormatWidth)4 MeasureUnit (android.icu.util.MeasureUnit)4 NumberFormat (android.icu.text.NumberFormat)3 DontCareFieldPosition (android.icu.impl.DontCareFieldPosition)2 TimeUnitFormat (android.icu.text.TimeUnitFormat)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1