Search in sources :

Example 1 with ImmutableIndex

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

the class AlphabeticIndexTest method TestSchSt.

/**
 * Test labels with multiple primary weights.
 */
@Test
public void TestSchSt() {
    AlphabeticIndex index = new AlphabeticIndex(ULocale.GERMAN);
    index.addLabels(new UnicodeSet("[Æ{Sch*}{St*}]"));
    // ... A Æ B-R S Sch St T-Z ...
    ImmutableIndex immIndex = index.buildImmutableIndex();
    assertEquals("getBucketCount()", 31, index.getBucketCount());
    assertEquals("immutable getBucketCount()", 31, immIndex.getBucketCount());
    String[][] testCases = new String[][] { // name, bucket index, bucket label
    { "Adelbert", "1", "A" }, { "Afrika", "1", "A" }, { "Æsculap", "2", "Æ" }, { "Aesthet", "2", "Æ" }, { "Berlin", "3", "B" }, { "Rilke", "19", "R" }, { "Sacher", "20", "S" }, { "Seiler", "20", "S" }, { "Sultan", "20", "S" }, { "Schiller", "21", "Sch" }, { "Steiff", "22", "St" }, { "Thomas", "23", "T" } };
    List<String> labels = index.getBucketLabels();
    for (String[] testCase : testCases) {
        String name = testCase[0];
        int bucketIndex = Integer.valueOf(testCase[1]);
        String label = testCase[2];
        String msg = "getBucketIndex(" + name + ")";
        assertEquals(msg, bucketIndex, index.getBucketIndex(name));
        msg = "immutable " + msg;
        assertEquals(msg, bucketIndex, immIndex.getBucketIndex(name));
        msg = "bucket label (" + name + ")";
        assertEquals(msg, label, labels.get(index.getBucketIndex(name)));
        msg = "immutable " + msg;
        assertEquals(msg, label, immIndex.getBucket(bucketIndex).getLabel());
    }
}
Also used : ImmutableIndex(android.icu.text.AlphabeticIndex.ImmutableIndex) AlphabeticIndex(android.icu.text.AlphabeticIndex) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 2 with ImmutableIndex

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

the class AlphabeticIndexTest method TestSetGetSpecialLabels.

@Test
public void TestSetGetSpecialLabels() {
    AlphabeticIndex index = new AlphabeticIndex(Locale.GERMAN).addLabels(new Locale("ru"));
    index.setUnderflowLabel("__");
    index.setInflowLabel("--");
    index.setOverflowLabel("^^");
    assertEquals("underflow label", "__", index.getUnderflowLabel());
    assertEquals("inflow label", "--", index.getInflowLabel());
    assertEquals("overflow label", "^^", index.getOverflowLabel());
    ImmutableIndex ii = index.buildImmutableIndex();
    assertEquals("0 -> underflow", "__", ii.getBucket(ii.getBucketIndex("0")).getLabel());
    assertEquals("Ω -> inflow", "--", ii.getBucket(ii.getBucketIndex("Ω")).getLabel());
    assertEquals("字 -> overflow", "^^", ii.getBucket(ii.getBucketIndex("字")).getLabel());
}
Also used : Locale(java.util.Locale) ULocale(android.icu.util.ULocale) ImmutableIndex(android.icu.text.AlphabeticIndex.ImmutableIndex) AlphabeticIndex(android.icu.text.AlphabeticIndex) Test(org.junit.Test)

Example 3 with ImmutableIndex

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

the class AlphabeticIndexTest method TestChineseZhuyin.

/**
 * Test with the Bopomofo-phonetic tailoring.
 */
@Test
public void TestChineseZhuyin() {
    AlphabeticIndex index = new AlphabeticIndex(ULocale.forLanguageTag("zh-u-co-zhuyin"));
    ImmutableIndex immIndex = index.buildImmutableIndex();
    // ... ㄅ ㄆ ㄇ ㄈ ㄉ -- ㄩ ...
    assertEquals("getBucketCount()", 38, immIndex.getBucketCount());
    assertEquals("label 1", "ㄅ", immIndex.getBucket(1).getLabel());
    assertEquals("label 2", "ㄆ", immIndex.getBucket(2).getLabel());
    assertEquals("label 3", "ㄇ", immIndex.getBucket(3).getLabel());
    assertEquals("label 4", "ㄈ", immIndex.getBucket(4).getLabel());
    assertEquals("label 5", "ㄉ", immIndex.getBucket(5).getLabel());
}
Also used : ImmutableIndex(android.icu.text.AlphabeticIndex.ImmutableIndex) AlphabeticIndex(android.icu.text.AlphabeticIndex) Test(org.junit.Test)

Aggregations

AlphabeticIndex (android.icu.text.AlphabeticIndex)3 ImmutableIndex (android.icu.text.AlphabeticIndex.ImmutableIndex)3 Test (org.junit.Test)3 UnicodeSet (android.icu.text.UnicodeSet)1 ULocale (android.icu.util.ULocale)1 Locale (java.util.Locale)1