use of android.icu.text.AlphabeticIndex.Bucket 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));
}
}
Aggregations