Search in sources :

Example 16 with MeasureUnit

use of android.icu.util.MeasureUnit in project j2objc by google.

the class PluralRangesTest method TestFormatting.

@Test
public void TestFormatting() {
    Object[][] tests = { { 0.0, 1.0, ULocale.FRANCE, FormatWidth.WIDE, MeasureUnit.FAHRENHEIT, "0–1 degré Fahrenheit" }, { 1.0, 2.0, ULocale.FRANCE, FormatWidth.WIDE, MeasureUnit.FAHRENHEIT, "1–2 degrés Fahrenheit" }, { 3.1, 4.25, ULocale.FRANCE, FormatWidth.SHORT, MeasureUnit.FAHRENHEIT, "3,1–4,25 °F" }, { 3.1, 4.25, ULocale.ENGLISH, FormatWidth.SHORT, MeasureUnit.FAHRENHEIT, "3.1–4.25°F" }, { 3.1, 4.25, ULocale.CHINESE, FormatWidth.WIDE, MeasureUnit.INCH, "3.1-4.25英寸" }, { 0.0, 1.0, ULocale.ENGLISH, FormatWidth.WIDE, MeasureUnit.INCH, "0–1 inches" }, { 0.0, 1.0, ULocale.ENGLISH, FormatWidth.NARROW, Currency.getInstance("EUR"), "€0.00–1.00" }, { 0.0, 1.0, ULocale.FRENCH, FormatWidth.NARROW, Currency.getInstance("EUR"), "0,00–1,00 €" }, { 0.0, 100.0, ULocale.FRENCH, FormatWidth.NARROW, Currency.getInstance("JPY"), "0–100\u00a0JPY" }, { 0.0, 1.0, ULocale.ENGLISH, FormatWidth.SHORT, Currency.getInstance("EUR"), "EUR0.00–1.00" }, { 0.0, 1.0, ULocale.FRENCH, FormatWidth.SHORT, Currency.getInstance("EUR"), "0,00–1,00\u00a0EUR" }, { 0.0, 100.0, ULocale.FRENCH, FormatWidth.SHORT, Currency.getInstance("JPY"), "0–100\u00a0JPY" }, { 0.0, 1.0, ULocale.ENGLISH, FormatWidth.WIDE, Currency.getInstance("EUR"), "0.00–1.00 euros" }, { 0.0, 1.0, ULocale.FRENCH, FormatWidth.WIDE, Currency.getInstance("EUR"), "0,00–1,00 euro" }, { 0.0, 2.0, ULocale.FRENCH, FormatWidth.WIDE, Currency.getInstance("EUR"), "0,00–2,00 euros" }, { 0.0, 100.0, ULocale.FRENCH, FormatWidth.WIDE, Currency.getInstance("JPY"), "0–100 yens japonais" } };
    int i = 0;
    for (Object[] test : tests) {
        ++i;
        double low = (Double) test[0];
        double high = (Double) test[1];
        final ULocale locale = (ULocale) test[2];
        final FormatWidth width = (FormatWidth) test[3];
        final MeasureUnit unit = (MeasureUnit) test[4];
        final Object expected = test[5];
        MeasureFormat mf = MeasureFormat.getInstance(locale, width);
        Object actual;
        try {
            actual = mf.formatMeasureRange(new Measure(low, unit), new Measure(high, unit));
        } catch (Exception e) {
            actual = e.getClass();
        }
        assertEquals(i + " Formatting unit", expected, actual);
    }
}
Also used : ULocale(android.icu.util.ULocale) MeasureUnit(android.icu.util.MeasureUnit) Measure(android.icu.util.Measure) FormatWidth(android.icu.text.MeasureFormat.FormatWidth) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Aggregations

MeasureUnit (android.icu.util.MeasureUnit)16 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 TreeMap (java.util.TreeMap)7 Test (org.junit.Test)6 MeasureFormat (android.icu.text.MeasureFormat)4 FormatWidth (android.icu.text.MeasureFormat.FormatWidth)4 Measure (android.icu.util.Measure)4 Pair (android.icu.impl.Pair)3 ULocale (android.icu.util.ULocale)3 StandardPlural (android.icu.impl.StandardPlural)2 Currency (android.icu.util.Currency)2 Field (java.lang.reflect.Field)2 FieldPosition (java.text.FieldPosition)2 DontCareFieldPosition (android.icu.impl.DontCareFieldPosition)1 NumberFormat (android.icu.text.NumberFormat)1 CurrencyAmount (android.icu.util.CurrencyAmount)1 HashSet (java.util.HashSet)1