Search in sources :

Example 1 with LabelType

use of android.icu.text.AlphabeticIndex.Bucket.LabelType in project j2objc by google.

the class AlphabeticIndexTest method TestEmpty.

@Test
public void TestEmpty() {
    // just verify that it doesn't blow up.
    Set<ULocale> locales = new LinkedHashSet<ULocale>();
    locales.add(ULocale.ROOT);
    locales.addAll(Arrays.asList(ULocale.getAvailableLocales()));
    for (ULocale locale : locales) {
        try {
            AlphabeticIndex<String> alphabeticIndex = new AlphabeticIndex(locale);
            alphabeticIndex.addRecord("hi", "HI");
            for (Bucket<String> bucket : alphabeticIndex) {
                @SuppressWarnings("unused") LabelType labelType = bucket.getLabelType();
            }
        } catch (Exception e) {
            errln("Exception when creating AlphabeticIndex for:\t" + locale.toLanguageTag());
            errln(e.toString());
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ULocale(android.icu.util.ULocale) LabelType(android.icu.text.AlphabeticIndex.Bucket.LabelType) AlphabeticIndex(android.icu.text.AlphabeticIndex) Test(org.junit.Test)

Example 2 with LabelType

use of android.icu.text.AlphabeticIndex.Bucket.LabelType in project j2objc by google.

the class AlphabeticIndexTest method TestInflow.

@Test
public void TestInflow() {
    Object[][] tests = { { 0, ULocale.ENGLISH }, { 0, ULocale.ENGLISH, new ULocale("el") }, { 1, ULocale.ENGLISH, new ULocale("ru") }, { 0, ULocale.ENGLISH, new ULocale("el"), new UnicodeSet("[\u2C80]"), new ULocale("ru") }, { 0, ULocale.ENGLISH }, { 2, ULocale.ENGLISH, new ULocale("ru"), ULocale.JAPANESE } };
    for (Object[] test : tests) {
        int expected = (Integer) test[0];
        AlphabeticIndex<Double> alphabeticIndex = new AlphabeticIndex((ULocale) test[1]);
        for (int i = 2; i < test.length; ++i) {
            if (test[i] instanceof ULocale) {
                alphabeticIndex.addLabels((ULocale) test[i]);
            } else {
                alphabeticIndex.addLabels((UnicodeSet) test[i]);
            }
        }
        Counter<AlphabeticIndex.Bucket.LabelType> counter = new Counter();
        for (Bucket<Double> bucket : alphabeticIndex) {
            LabelType labelType = bucket.getLabelType();
            counter.add(labelType, 1);
        }
        String printList = Arrays.asList(test).toString();
        assertEquals(LabelType.UNDERFLOW + "\t" + printList, 1, counter.get(LabelType.UNDERFLOW));
        assertEquals(LabelType.INFLOW + "\t" + printList, expected, counter.get(LabelType.INFLOW));
        if (expected != counter.get(LabelType.INFLOW)) {
            // for debugging
            AlphabeticIndex<Double> indexCharacters2 = new AlphabeticIndex((ULocale) test[1]);
            for (int i = 2; i < test.length; ++i) {
                if (test[i] instanceof ULocale) {
                    indexCharacters2.addLabels((ULocale) test[i]);
                } else {
                    indexCharacters2.addLabels((UnicodeSet) test[i]);
                }
            }
            List<Bucket<Double>> buckets = CollectionUtilities.addAll(alphabeticIndex.iterator(), new ArrayList<Bucket<Double>>());
            logln(buckets.toString());
        }
        assertEquals(LabelType.OVERFLOW + "\t" + printList, 1, counter.get(LabelType.OVERFLOW));
    }
}
Also used : ULocale(android.icu.util.ULocale) UnicodeSet(android.icu.text.UnicodeSet) AlphabeticIndex(android.icu.text.AlphabeticIndex) Bucket(android.icu.text.AlphabeticIndex.Bucket) LabelType(android.icu.text.AlphabeticIndex.Bucket.LabelType) Test(org.junit.Test)

Aggregations

AlphabeticIndex (android.icu.text.AlphabeticIndex)2 LabelType (android.icu.text.AlphabeticIndex.Bucket.LabelType)2 ULocale (android.icu.util.ULocale)2 Test (org.junit.Test)2 Bucket (android.icu.text.AlphabeticIndex.Bucket)1 UnicodeSet (android.icu.text.UnicodeSet)1 LinkedHashSet (java.util.LinkedHashSet)1