use of android.icu.text.UnicodeSetIterator in project j2objc by google.
the class CollationMiscTest method TestImport.
@Test
public void TestImport() {
try {
RuleBasedCollator vicoll = (RuleBasedCollator) Collator.getInstance(new ULocale("vi"));
RuleBasedCollator escoll = (RuleBasedCollator) Collator.getInstance(new ULocale("es"));
RuleBasedCollator viescoll = new RuleBasedCollator(vicoll.getRules() + escoll.getRules());
RuleBasedCollator importviescoll = new RuleBasedCollator("[import vi][import es]");
UnicodeSet tailoredSet = viescoll.getTailoredSet();
UnicodeSet importTailoredSet = importviescoll.getTailoredSet();
if (!tailoredSet.equals(importTailoredSet)) {
warnln("Tailored set not equal");
}
for (UnicodeSetIterator it = new UnicodeSetIterator(tailoredSet); it.next(); ) {
String t = it.getString();
CollationKey sk1 = viescoll.getCollationKey(t);
CollationKey sk2 = importviescoll.getCollationKey(t);
if (!sk1.equals(sk2)) {
warnln("Collation key's not equal for " + t);
}
}
} catch (Exception e) {
// Android patch: Add --omitCollationRules to genrb.
logln("ERROR: in creation of rule based collator");
// Android patch end.
}
}
use of android.icu.text.UnicodeSetIterator in project j2objc by google.
the class UCharacterTest method TestMirror.
/**
* Test mirroring
*/
@Test
public void TestMirror() {
if (!(UCharacter.isMirrored(0x28) && UCharacter.isMirrored(0xbb) && UCharacter.isMirrored(0x2045) && UCharacter.isMirrored(0x232a) && !UCharacter.isMirrored(0x27) && !UCharacter.isMirrored(0x61) && !UCharacter.isMirrored(0x284) && !UCharacter.isMirrored(0x3400))) {
errln("isMirrored() does not work correctly");
}
if (!(UCharacter.getMirror(0x3c) == 0x3e && UCharacter.getMirror(0x5d) == 0x5b && UCharacter.getMirror(0x208d) == 0x208e && UCharacter.getMirror(0x3017) == 0x3016 && UCharacter.getMirror(0xbb) == 0xab && UCharacter.getMirror(0x2215) == 0x29F5 && UCharacter.getMirror(0x29F5) == 0x2215 && UCharacter.getMirror(0x2e) == 0x2e && UCharacter.getMirror(0x6f3) == 0x6f3 && UCharacter.getMirror(0x301c) == 0x301c && UCharacter.getMirror(0xa4ab) == 0xa4ab && /* see Unicode Corrigendum #6 at http://www.unicode.org/versions/corrigendum6.html */
UCharacter.getMirror(0x2018) == 0x2018 && UCharacter.getMirror(0x201b) == 0x201b && UCharacter.getMirror(0x301d) == 0x301d)) {
errln("getMirror() does not work correctly");
}
/* verify that Bidi_Mirroring_Glyph roundtrips */
UnicodeSet set = new UnicodeSet("[:Bidi_Mirrored:]");
UnicodeSetIterator iter = new UnicodeSetIterator(set);
int start, end, c2, c3;
while (iter.nextRange() && (start = iter.codepoint) >= 0) {
end = iter.codepointEnd;
do {
c2 = UCharacter.getMirror(start);
c3 = UCharacter.getMirror(c2);
if (c3 != start) {
errln("getMirror() does not roundtrip: U+" + hex(start) + "->U+" + hex(c2) + "->U+" + hex(c3));
}
c3 = UCharacter.getBidiPairedBracket(start);
if (UCharacter.getIntPropertyValue(start, UProperty.BIDI_PAIRED_BRACKET_TYPE) == UCharacter.BidiPairedBracketType.NONE) {
if (c3 != start) {
errln("u_getBidiPairedBracket(U+" + hex(start) + ") != self for bpt(c)==None");
}
} else {
if (c3 != c2) {
errln("u_getBidiPairedBracket(U+" + hex(start) + ") != U+" + hex(c2) + " = bmg(c)'");
}
}
} while (++start <= end);
}
// verify that Unicode Corrigendum #6 reverts mirrored status of the following
if (UCharacter.isMirrored(0x2018) || UCharacter.isMirrored(0x201d) || UCharacter.isMirrored(0x201f) || UCharacter.isMirrored(0x301e)) {
errln("Unicode Corrigendum #6 conflict, one or more of 2018/201d/201f/301e has mirrored property");
}
}
use of android.icu.text.UnicodeSetIterator in project j2objc by google.
the class UnicodeSetTest method TestPropertyAccess.
@Test
public void TestPropertyAccess() {
int count = 0;
// test to see that all of the names work
for (int propNum = UProperty.BINARY_START; propNum < UProperty.INT_LIMIT; ++propNum) {
count++;
// Skipping tests in the non-exhaustive mode to shorten the test time ticket#6475
if (TestFmwk.getExhaustiveness() <= 5 && count % 5 != 0) {
continue;
}
if (propNum >= UProperty.BINARY_LIMIT && propNum < UProperty.INT_START) {
// skip the gap
propNum = UProperty.INT_START;
}
for (int nameChoice = UProperty.NameChoice.SHORT; nameChoice <= UProperty.NameChoice.LONG; ++nameChoice) {
String propName;
try {
propName = UCharacter.getPropertyName(propNum, nameChoice);
if (propName == null) {
// allow non-existent short names
if (nameChoice == UProperty.NameChoice.SHORT)
continue;
throw new NullPointerException();
}
} catch (RuntimeException e1) {
errln("Can't get property name for: " + "Property (" + propNum + ")" + ", NameChoice: " + nameChoice + ", " + e1.getClass().getName());
continue;
}
logln("Property (" + propNum + "): " + propName);
for (int valueNum = UCharacter.getIntPropertyMinValue(propNum); valueNum <= UCharacter.getIntPropertyMaxValue(propNum); ++valueNum) {
String valueName;
try {
valueName = UCharacter.getPropertyValueName(propNum, valueNum, nameChoice);
if (valueName == null) {
// allow non-existent short names
if (nameChoice == UProperty.NameChoice.SHORT)
continue;
if ((propNum == UProperty.CANONICAL_COMBINING_CLASS || propNum == UProperty.LEAD_CANONICAL_COMBINING_CLASS || propNum == UProperty.TRAIL_CANONICAL_COMBINING_CLASS) && !isCccValue(valueNum)) {
// Otherwise they are just integer values.
continue;
} else {
throw new NullPointerException();
}
}
} catch (RuntimeException e1) {
errln("Can't get property value name for: " + "Property (" + propNum + "): " + propName + ", " + "Value (" + valueNum + ") " + ", NameChoice: " + nameChoice + ", " + e1.getClass().getName());
continue;
}
logln("Value (" + valueNum + "): " + valueName);
UnicodeSet testSet;
try {
testSet = new UnicodeSet("[:" + propName + "=" + valueName + ":]");
} catch (RuntimeException e) {
errln("Can't create UnicodeSet for: " + "Property (" + propNum + "): " + propName + ", " + "Value (" + valueNum + "): " + valueName + ", " + e.getClass().getName());
continue;
}
UnicodeSet collectedErrors = new UnicodeSet();
for (UnicodeSetIterator it = new UnicodeSetIterator(testSet); it.next(); ) {
int value = UCharacter.getIntPropertyValue(it.codepoint, propNum);
if (value != valueNum) {
collectedErrors.add(it.codepoint);
}
}
if (collectedErrors.size() != 0) {
errln("Property Value Differs: " + "Property (" + propNum + "): " + propName + ", " + "Value (" + valueNum + "): " + valueName + ", " + "Differing values: " + collectedErrors.toPattern(true));
}
}
}
}
}
use of android.icu.text.UnicodeSetIterator 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);
}
use of android.icu.text.UnicodeSetIterator in project j2objc by google.
the class UnicodeSetTest method CheckRangeSpeed.
/**
* @param iterations
* @param testSet
*/
private void CheckRangeSpeed(int iterations, UnicodeSet testSet) {
testSet.complement().complement();
String testPattern = testSet.toString();
// fill a set of pairs from the pattern
int[] pairs = new int[testSet.getRangeCount() * 2];
int j = 0;
for (UnicodeSetIterator it = new UnicodeSetIterator(testSet); it.nextRange(); ) {
pairs[j++] = it.codepoint;
pairs[j++] = it.codepointEnd;
}
UnicodeSet fromRange = new UnicodeSet(testSet);
assertEquals("from range vs pattern", testSet, fromRange);
double start = System.currentTimeMillis();
for (int i = 0; i < iterations; ++i) {
fromRange = new UnicodeSet(testSet);
}
double middle = System.currentTimeMillis();
for (int i = 0; i < iterations; ++i) {
new UnicodeSet(testPattern);
}
double end = System.currentTimeMillis();
double rangeConstructorTime = (middle - start) / iterations;
double patternConstructorTime = (end - middle) / iterations;
String message = "Range constructor:\t" + rangeConstructorTime + ";\tPattern constructor:\t" + patternConstructorTime + "\t\t" + percent.format(rangeConstructorTime / patternConstructorTime - 1);
if (rangeConstructorTime < 2 * patternConstructorTime) {
logln(message);
} else {
errln(message);
}
}
Aggregations