expectPairs(set, "aw");
}
public void TestAPI() {
// default ct
UnicodeSet set = new UnicodeSet();
if (!set.isEmpty() || set.getRangeCount() != 0) {
errln("FAIL, set should be empty but isn't: " +
set);
}
// clear(), isEmpty()
set.add('a');
if (set.isEmpty()) {
errln("FAIL, set shouldn't be empty but is: " +
set);
}
set.clear();
if (!set.isEmpty()) {
errln("FAIL, set should be empty but isn't: " +
set);
}
// size()
set.clear();
if (set.size() != 0) {
errln("FAIL, size should be 0, but is " + set.size() +
": " + set);
}
set.add('a');
if (set.size() != 1) {
errln("FAIL, size should be 1, but is " + set.size() +
": " + set);
}
set.add('1', '9');
if (set.size() != 10) {
errln("FAIL, size should be 10, but is " + set.size() +
": " + set);
}
set.clear();
set.complement();
if (set.size() != 0x110000) {
errln("FAIL, size should be 0x110000, but is" + set.size());
}
// contains(first, last)
set.clear();
set.applyPattern("[A-Y 1-8 b-d l-y]");
for (int i = 0; i<set.getRangeCount(); ++i) {
int a = set.getRangeStart(i);
int b = set.getRangeEnd(i);
if (!set.contains(a, b)) {
errln("FAIL, should contain " + (char)a + '-' + (char)b +
" but doesn't: " + set);
}
if (set.contains((char)(a-1), b)) {
errln("FAIL, shouldn't contain " +
(char)(a-1) + '-' + (char)b +
" but does: " + set);
}
if (set.contains(a, (char)(b+1))) {
errln("FAIL, shouldn't contain " +
(char)a + '-' + (char)(b+1) +
" but does: " + set);
}
}
// Ported InversionList test.
UnicodeSet a = new UnicodeSet((char)3,(char)10);
UnicodeSet b = new UnicodeSet((char)7,(char)15);
UnicodeSet c = new UnicodeSet();
logln("a [3-10]: " + a);
logln("b [7-15]: " + b);
c.set(a); c.addAll(b);
UnicodeSet exp = new UnicodeSet((char)3,(char)15);
if (c.equals(exp)) {
logln("c.set(a).add(b): " + c);
} else {
errln("FAIL: c.set(a).add(b) = " + c + ", expect " + exp);
}
c.complement();
exp.set((char)0, (char)2);
exp.add((char)16, UnicodeSet.MAX_VALUE);
if (c.equals(exp)) {
logln("c.complement(): " + c);
} else {
errln(Utility.escape("FAIL: c.complement() = " + c + ", expect " + exp));
}
c.complement();
exp.set((char)3, (char)15);
if (c.equals(exp)) {
logln("c.complement(): " + c);
} else {
errln("FAIL: c.complement() = " + c + ", expect " + exp);
}
c.set(a); c.complementAll(b);
exp.set((char)3,(char)6);
exp.add((char)11,(char) 15);
if (c.equals(exp)) {
logln("c.set(a).complement(b): " + c);
} else {
errln("FAIL: c.set(a).complement(b) = " + c + ", expect " + exp);
}
exp.set(c);
c = bitsToSet(setToBits(c));
if (c.equals(exp)) {
logln("bitsToSet(setToBits(c)): " + c);
} else {
errln("FAIL: bitsToSet(setToBits(c)) = " + c + ", expect " + exp);
}
// Additional tests for coverage JB#2118
//UnicodeSet::complement(class UnicodeString const &)
//UnicodeSet::complementAll(class UnicodeString const &)
//UnicodeSet::containsNone(class UnicodeSet const &)
//UnicodeSet::containsNone(long,long)
//UnicodeSet::containsSome(class UnicodeSet const &)
//UnicodeSet::containsSome(long,long)
//UnicodeSet::removeAll(class UnicodeString const &)
//UnicodeSet::retain(long)
//UnicodeSet::retainAll(class UnicodeString const &)
//UnicodeSet::serialize(unsigned short *,long,enum UErrorCode &)
//UnicodeSetIterator::getString(void)
set.clear();
set.complement("ab");
exp.applyPattern("[{ab}]");
if (!set.equals(exp)) { errln("FAIL: complement(\"ab\")"); return; }
UnicodeSetIterator iset = new UnicodeSetIterator(set);
if (!iset.next() || iset.codepoint != UnicodeSetIterator.IS_STRING) {
errln("FAIL: UnicodeSetIterator.next/IS_STRING");
} else if (!iset.string.equals("ab")) {
errln("FAIL: UnicodeSetIterator.string");
}
set.add((char)0x61, (char)0x7A);
set.complementAll("alan");
exp.applyPattern("[{ab}b-kmo-z]");
if (!set.equals(exp)) { errln("FAIL: complementAll(\"alan\")"); return; }
exp.applyPattern("[a-z]");
if (set.containsNone(exp)) { errln("FAIL: containsNone(UnicodeSet)"); }
if (!set.containsSome(exp)) { errln("FAIL: containsSome(UnicodeSet)"); }
exp.applyPattern("[aln]");
if (!set.containsNone(exp)) { errln("FAIL: containsNone(UnicodeSet)"); }
if (set.containsSome(exp)) { errln("FAIL: containsSome(UnicodeSet)"); }
if (set.containsNone((char)0x61, (char)0x7A)) {
errln("FAIL: containsNone(char, char)");
}
if (!set.containsSome((char)0x61, (char)0x7A)) {
errln("FAIL: containsSome(char, char)");
}
if (!set.containsNone((char)0x41, (char)0x5A)) {
errln("FAIL: containsNone(char, char)");
}
if (set.containsSome((char)0x41, (char)0x5A)) {
errln("FAIL: containsSome(char, char)");
}
set.removeAll("liu");
exp.applyPattern("[{ab}b-hj-kmo-tv-z]");
if (!set.equals(exp)) { errln("FAIL: removeAll(\"liu\")"); return; }
set.retainAll("star");
exp.applyPattern("[rst]");
if (!set.equals(exp)) { errln("FAIL: retainAll(\"star\")"); return; }
set.retain((char)0x73);
exp.applyPattern("[s]");
if (!set.equals(exp)) { errln("FAIL: retain('s')"); return; }
// ICU 2.6 coverage tests
// public final UnicodeSet retain(String s);
// public final UnicodeSet remove(int c);
// public final UnicodeSet remove(String s);
// public int hashCode();
set.applyPattern("[a-z{ab}{cd}]");
set.retain("cd");
exp.applyPattern("[{cd}]");
if (!set.equals(exp)) { errln("FAIL: retain(\"cd\")"); return; }
set.applyPattern("[a-z{ab}{cd}]");
set.remove((char)0x63);
exp.applyPattern("[abd-z{ab}{cd}]");
if (!set.equals(exp)) { errln("FAIL: remove('c')"); return; }
set.remove("cd");
exp.applyPattern("[abd-z{ab}]");
if (!set.equals(exp)) { errln("FAIL: remove(\"cd\")"); return; }
if (set.hashCode() != exp.hashCode()) {
errln("FAIL: hashCode() unequal");
}
exp.clear();
if (set.hashCode() == exp.hashCode()) {
errln("FAIL: hashCode() equal");
}
{
//Cover addAll(Collection) and addAllTo(Collection)