Search in sources :

Example 91 with UnicodeSet

use of android.icu.text.UnicodeSet in project j2objc by google.

the class UnicodeSetTest method _testXor.

void _testXor(int a, int b) {
    UnicodeSet x = bitsToSet(a);
    UnicodeSet y = bitsToSet(b);
    UnicodeSet z = bitsToSet(a);
    z.complementAll(y);
    int c = setToBits(z);
    if (c != (a ^ b)) {
        errln("FAILED: complement: " + x + " ^ " + y + " != " + z);
        errln("FAILED: complement: " + a + " ^ " + b + " != " + c);
    }
    checkCanonicalRep(z, "complement " + a + "," + b);
}
Also used : UnicodeSet(android.icu.text.UnicodeSet)

Example 92 with UnicodeSet

use of android.icu.text.UnicodeSet in project j2objc by google.

the class UnicodeSetTest method expectRelation.

/**
 * Test function. Make sure that the sets have the right relation
 */
void expectRelation(Object relationObj, Object set1Obj, Object set2Obj, String message) {
    int relation = ((Integer) relationObj).intValue();
    UnicodeSet set1 = (UnicodeSet) set1Obj;
    UnicodeSet set2 = (UnicodeSet) set2Obj;
    // by-the-by, check the iterator
    checkRoundTrip(set1);
    checkRoundTrip(set2);
    boolean contains = set1.containsAll(set2);
    boolean isContained = set2.containsAll(set1);
    boolean disjoint = set1.containsNone(set2);
    boolean equals = set1.equals(set2);
    UnicodeSet intersection = new UnicodeSet(set1).retainAll(set2);
    UnicodeSet minus12 = new UnicodeSet(set1).removeAll(set2);
    UnicodeSet minus21 = new UnicodeSet(set2).removeAll(set1);
    if (contains != (intersection.size() == set2.size())) {
        errln("FAIL contains1" + set1.toPattern(true) + ", " + set2.toPattern(true));
    }
    if (contains != (intersection.equals(set2))) {
        errln("FAIL contains2" + set1.toPattern(true) + ", " + set2.toPattern(true));
    }
    if (isContained != (intersection.size() == set1.size())) {
        errln("FAIL isContained1" + set1.toPattern(true) + ", " + set2.toPattern(true));
    }
    if (isContained != (intersection.equals(set1))) {
        errln("FAIL isContained2" + set1.toPattern(true) + ", " + set2.toPattern(true));
    }
    if ((contains && isContained) != equals) {
        errln("FAIL equals" + set1.toPattern(true) + ", " + set2.toPattern(true));
    }
    if (disjoint != (intersection.size() == 0)) {
        errln("FAIL disjoint" + set1.toPattern(true) + ", " + set2.toPattern(true));
    }
    // Now see if the expected relation is true
    int status = (minus12.size() != 0 ? 4 : 0) | (intersection.size() != 0 ? 2 : 0) | (minus21.size() != 0 ? 1 : 0);
    if (status != relation) {
        errln("FAIL relation incorrect" + message + "; desired = " + RELATION_NAME[relation] + "; found = " + RELATION_NAME[status] + "; set1 = " + set1.toPattern(true) + "; set2 = " + set2.toPattern(true));
    }
}
Also used : UnicodeSet(android.icu.text.UnicodeSet)

Example 93 with UnicodeSet

use of android.icu.text.UnicodeSet in project j2objc by google.

the class UnicodeSetTest method TestGenerics.

/**
 * Test Generic support
 */
@Test
public void TestGenerics() {
    UnicodeSet set1 = new UnicodeSet("[a-b d-g {ch} {zh}]").freeze();
    UnicodeSet set2 = new UnicodeSet("[e-f {ch}]").freeze();
    UnicodeSet set3 = new UnicodeSet("[d m-n {dh}]").freeze();
    // A useful range of sets for testing, including both characters and strings
    // set 1 contains set2
    // set 1 is overlaps with set 3
    // set 2 is disjoint with set 3
    // public Iterator<String> iterator() {
    ArrayList<String> oldList = new ArrayList<String>();
    for (UnicodeSetIterator it = new UnicodeSetIterator(set1); it.next(); ) {
        oldList.add(it.getString());
    }
    ArrayList<String> list1 = new ArrayList<String>();
    for (String s : set1) {
        list1.add(s);
    }
    assertEquals("iteration test", oldList, list1);
    // addAllTo(Iterable<T>, U)
    list1.clear();
    set1.addAllTo(list1);
    assertEquals("iteration test", oldList, list1);
    list1 = set1.addAllTo(new ArrayList<String>());
    assertEquals("addAllTo", oldList, list1);
    ArrayList<String> list2 = set2.addAllTo(new ArrayList<String>());
    ArrayList<String> list3 = set3.addAllTo(new ArrayList<String>());
    // put them into different order, to check that order doesn't matter
    TreeSet sorted1 = set1.addAllTo(new TreeSet<String>());
    TreeSet sorted2 = set2.addAllTo(new TreeSet<String>());
    TreeSet sorted3 = set3.addAllTo(new TreeSet<String>());
    // containsAll(Collection<String> collection)
    assertTrue("containsAll", set1.containsAll(list1));
    assertTrue("containsAll", set1.containsAll(sorted1));
    assertTrue("containsAll", set1.containsAll(list2));
    assertTrue("containsAll", set1.containsAll(sorted2));
    assertFalse("containsAll", set1.containsAll(list3));
    assertFalse("containsAll", set1.containsAll(sorted3));
    assertFalse("containsAll", set2.containsAll(list3));
    assertFalse("containsAll", set2.containsAll(sorted3));
    // containsSome(Collection<String>)
    assertTrue("containsSome", set1.containsSome(list1));
    assertTrue("containsSome", set1.containsSome(sorted1));
    assertTrue("containsSome", set1.containsSome(list2));
    assertTrue("containsSome", set1.containsSome(sorted2));
    assertTrue("containsSome", set1.containsSome(list3));
    assertTrue("containsSome", set1.containsSome(sorted3));
    assertFalse("containsSome", set2.containsSome(list3));
    assertFalse("containsSome", set2.containsSome(sorted3));
    // containsNone(Collection<String>)
    assertFalse("containsNone", set1.containsNone(list1));
    assertFalse("containsNone", set1.containsNone(sorted1));
    assertFalse("containsNone", set1.containsNone(list2));
    assertFalse("containsNone", set1.containsNone(sorted2));
    assertFalse("containsNone", set1.containsNone(list3));
    assertFalse("containsNone", set1.containsNone(sorted3));
    assertTrue("containsNone", set2.containsNone(list3));
    assertTrue("containsNone", set2.containsNone(sorted3));
    // addAll(String...)
    UnicodeSet other3 = new UnicodeSet().addAll("d", "m", "n", "dh");
    assertEquals("addAll", set3, other3);
    // removeAll(Collection<String>)
    UnicodeSet mod1 = new UnicodeSet(set1).removeAll(set2);
    UnicodeSet mod2 = new UnicodeSet(set1).removeAll(list2);
    assertEquals("remove all", mod1, mod2);
    // retainAll(Collection<String>)
    mod1 = new UnicodeSet(set1).retainAll(set2);
    mod2 = new UnicodeSet(set1).retainAll(set2.addAllTo(new LinkedHashSet<String>()));
    assertEquals("remove all", mod1, mod2);
}
Also used : UnicodeSetIterator(android.icu.text.UnicodeSetIterator) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 94 with UnicodeSet

use of android.icu.text.UnicodeSet in project j2objc by google.

the class UnicodeSetTest method TestAddRemove.

@Test
public void TestAddRemove() {
    UnicodeSet set = new UnicodeSet();
    set.add('a', 'z');
    expectPairs(set, "az");
    set.remove('m', 'p');
    expectPairs(set, "alqz");
    set.remove('e', 'g');
    expectPairs(set, "adhlqz");
    set.remove('d', 'i');
    expectPairs(set, "acjlqz");
    set.remove('c', 'r');
    expectPairs(set, "absz");
    set.add('f', 'q');
    expectPairs(set, "abfqsz");
    set.remove('a', 'g');
    expectPairs(set, "hqsz");
    set.remove('a', 'z');
    expectPairs(set, "");
    // Try removing an entire set from another set
    expectPattern(set, "[c-x]", "cx");
    UnicodeSet set2 = new UnicodeSet();
    expectPattern(set2, "[f-ky-za-bc[vw]]", "acfkvwyz");
    set.removeAll(set2);
    expectPairs(set, "deluxx");
    // Try adding an entire set to another set
    expectPattern(set, "[jackiemclean]", "aacceein");
    expectPattern(set2, "[hitoshinamekatajamesanderson]", "aadehkmort");
    set.addAll(set2);
    expectPairs(set, "aacehort");
    // Test commutativity
    expectPattern(set, "[hitoshinamekatajamesanderson]", "aadehkmort");
    expectPattern(set2, "[jackiemclean]", "aacceein");
    set.addAll(set2);
    expectPairs(set, "aacehort");
}
Also used : UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 95 with UnicodeSet

use of android.icu.text.UnicodeSet in project j2objc by google.

the class UnicodeSetTest method TestCategories.

@Test
public void TestCategories() {
    int failures = 0;
    UnicodeSet set = new UnicodeSet("[:Lu:]");
    expectContainment(set, "ABC", "abc");
    // Make sure generation of L doesn't pollute cached Lu set
    // First generate L, then Lu
    // not used int TOP = 0x200; // Don't need to go over the whole range:
    set = new UnicodeSet("[:L:]");
    for (int i = 0; i < 0x200; ++i) {
        boolean l = UCharacter.isLetter(i);
        if (l != set.contains((char) i)) {
            errln("FAIL: L contains " + (char) i + " = " + set.contains((char) i));
            if (++failures == 10)
                break;
        }
    }
    set = new UnicodeSet("[:Lu:]");
    for (int i = 0; i < 0x200; ++i) {
        boolean lu = (UCharacter.getType(i) == ECharacterCategory.UPPERCASE_LETTER);
        if (lu != set.contains((char) i)) {
            errln("FAIL: Lu contains " + (char) i + " = " + set.contains((char) i));
            if (++failures == 20)
                break;
        }
    }
}
Also used : UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Aggregations

UnicodeSet (android.icu.text.UnicodeSet)158 Test (org.junit.Test)112 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)25 Transliterator (android.icu.text.Transliterator)19 ReplaceableString (android.icu.text.ReplaceableString)14 ULocale (android.icu.util.ULocale)13 CaseInsensitiveString (android.icu.util.CaseInsensitiveString)9 Normalizer2 (android.icu.text.Normalizer2)7 RuleBasedCollator (android.icu.text.RuleBasedCollator)7 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 FilteredNormalizer2 (android.icu.text.FilteredNormalizer2)4 SpoofChecker (android.icu.text.SpoofChecker)4 TreeSet (java.util.TreeSet)4 UnicodeMap (android.icu.dev.util.UnicodeMap)3 AlphabeticIndex (android.icu.text.AlphabeticIndex)3 CollationKey (android.icu.text.CollationKey)3 RawCollationKey (android.icu.text.RawCollationKey)3 CheckResult (android.icu.text.SpoofChecker.CheckResult)3 SpanCondition (android.icu.text.UnicodeSet.SpanCondition)3