use of android.icu.text.AlphabeticIndex in project j2objc by google.
the class AlphabeticIndexTest method TestHaniFirst.
/**
* Test AlphabeticIndex vs. root with script reordering.
*/
@Test
public void TestHaniFirst() {
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(ULocale.ROOT);
coll.setReorderCodes(UScript.HAN);
AlphabeticIndex index = new AlphabeticIndex(coll);
// ... (underflow only)
assertEquals("getBucketCount()", 1, index.getBucketCount());
index.addLabels(Locale.ENGLISH);
// ... A-Z ...
assertEquals("getBucketCount()", 28, index.getBucketCount());
int bucketIndex = index.getBucketIndex("\u897f");
// underflow bucket
assertEquals("getBucketIndex(U+897F)", 0, bucketIndex);
bucketIndex = index.getBucketIndex("i");
assertEquals("getBucketIndex(i)", 9, bucketIndex);
bucketIndex = index.getBucketIndex("\u03B1");
assertEquals("getBucketIndex(Greek alpha)", 27, bucketIndex);
// U+50005 is an unassigned code point which sorts at the end, independent of the Hani group.
bucketIndex = index.getBucketIndex(UTF16.valueOf(0x50005));
assertEquals("getBucketIndex(U+50005)", 27, bucketIndex);
bucketIndex = index.getBucketIndex("\uFFFF");
assertEquals("getBucketIndex(U+FFFF)", 27, bucketIndex);
}
use of android.icu.text.AlphabeticIndex in project j2objc by google.
the class AlphabeticIndexTest method TestNoLabels.
/**
* With no real labels, there should be only the underflow label.
*/
@Test
public void TestNoLabels() {
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(ULocale.ROOT);
AlphabeticIndex<Integer> index = new AlphabeticIndex<Integer>(coll);
index.addRecord("\u897f", 0);
index.addRecord("i", 0);
index.addRecord("\u03B1", 0);
// code coverage
assertEquals("getRecordCount()", 3, index.getRecordCount());
// ...
assertEquals("getBucketCount()", 1, index.getBucketCount());
Bucket<Integer> bucket = index.iterator().next();
assertEquals("underflow label type", LabelType.UNDERFLOW, bucket.getLabelType());
assertEquals("all records in the underflow bucket", 3, bucket.size());
}
use of android.icu.text.AlphabeticIndex 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());
}
}
}
use of android.icu.text.AlphabeticIndex in project j2objc by google.
the class AlphabeticIndexTest method TestJapaneseKanji.
@Test
public void TestJapaneseKanji() {
AlphabeticIndex index = new AlphabeticIndex(ULocale.JAPANESE);
AlphabeticIndex.ImmutableIndex immIndex = index.buildImmutableIndex();
// There are no index characters for Kanji in the Japanese standard collator.
// They should all go into the overflow bucket.
final int[] kanji = { 0x4E9C, 0x95C7, 0x4E00, 0x58F1 };
int overflowIndex = immIndex.getBucketCount() - 1;
for (int i = 0; i < kanji.length; ++i) {
String msg = String.format("kanji[%d]=U+%04X in overflow bucket", i, kanji[i]);
assertEquals(msg, overflowIndex, immIndex.getBucketIndex(UTF16.valueOf(kanji[i])));
}
}
use of android.icu.text.AlphabeticIndex in project j2objc by google.
the class AlphabeticIndexTest method TestFirstScriptCharacters.
@Test
public void TestFirstScriptCharacters() {
Collection<String> firstCharacters = new AlphabeticIndex(ULocale.ENGLISH).getFirstCharactersInScripts();
Collection<String> expectedFirstCharacters = firstStringsInScript((RuleBasedCollator) Collator.getInstance(ULocale.ROOT));
Collection<String> diff = new TreeSet<String>(firstCharacters);
diff.removeAll(expectedFirstCharacters);
assertTrue("First Characters contains unexpected ones: " + diff, diff.isEmpty());
diff.clear();
diff.addAll(expectedFirstCharacters);
diff.removeAll(firstCharacters);
assertTrue("First Characters missing expected ones: " + diff, diff.isEmpty());
}
Aggregations