use of android.icu.text.Collator in project j2objc by google.
the class G7CollationTest method TestDemo1.
// perform test with added rules " & Z < p, P"
@Test
public void TestDemo1() {
logln("Demo Test 1 : Create a new table collation with rules \"& Z < p, P\"");
Collator col = Collator.getInstance(Locale.ENGLISH);
String baseRules = ((RuleBasedCollator) col).getRules();
String newRules = " & Z < p, P";
newRules = baseRules + newRules;
RuleBasedCollator myCollation = null;
try {
myCollation = new RuleBasedCollator(newRules);
} catch (Exception e) {
errln("Fail to create RuleBasedCollator with rules:" + newRules);
return;
}
int j, n;
for (j = 0; j < FIXEDTESTSET; j++) {
for (n = j + 1; n < FIXEDTESTSET; n++) {
doTest(myCollation, testCases[results[8][j]], testCases[results[8][n]], -1);
}
}
}
use of android.icu.text.Collator in project j2objc by google.
the class G7CollationTest method TestDemo3.
// perform test with added rules
// "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'"
@Test
public void TestDemo3() {
// logln("Demo Test 3 : Create a new table collation with rules \"& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'\"");
Collator col = Collator.getInstance(Locale.ENGLISH);
String baseRules = ((RuleBasedCollator) col).getRules();
String newRules = "& Question'-'mark ; '?' & Hash'-'mark ; '#' & Ampersand ; '&'";
newRules = baseRules + newRules;
RuleBasedCollator myCollation = null;
try {
myCollation = new RuleBasedCollator(newRules);
} catch (Exception e) {
errln("Fail to create RuleBasedCollator with rules:" + newRules);
return;
}
int j, n;
for (j = 0; j < TOTALTESTSET; j++) {
for (n = j + 1; n < TOTALTESTSET; n++) {
doTest(myCollation, testCases[results[10][j]], testCases[results[10][n]], -1);
}
}
}
use of android.icu.text.Collator in project j2objc by google.
the class G7CollationTest method TestDemo4.
// perform test with added rules
// " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' "
@Test
public void TestDemo4() {
logln("Demo Test 4 : Create a new table collation with rules \" & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' \"");
Collator col = Collator.getInstance(Locale.ENGLISH);
String baseRules = ((RuleBasedCollator) col).getRules();
String newRules = " & aa ; a'-' & ee ; e'-' & ii ; i'-' & oo ; o'-' & uu ; u'-' ";
newRules = baseRules + newRules;
RuleBasedCollator myCollation = null;
try {
myCollation = new RuleBasedCollator(newRules);
} catch (Exception e) {
errln("Fail to create RuleBasedCollator with rules:" + newRules);
return;
}
int j, n;
for (j = 0; j < TOTALTESTSET; j++) {
for (n = j + 1; n < TOTALTESTSET; n++) {
doTest(myCollation, testCases[results[11][j]], testCases[results[11][n]], -1);
}
}
}
use of android.icu.text.Collator in project j2objc by google.
the class G7CollationTest method TestG7Data.
@Test
public void TestG7Data() {
Locale[] locales = { Locale.US, Locale.UK, Locale.CANADA, Locale.FRANCE, Locale.CANADA_FRENCH, Locale.GERMANY, Locale.JAPAN, Locale.ITALY };
int i = 0, j = 0;
for (i = 0; i < locales.length; i++) {
Collator myCollation = null;
RuleBasedCollator tblColl1 = null;
try {
myCollation = Collator.getInstance(locales[i]);
tblColl1 = new RuleBasedCollator(((RuleBasedCollator) myCollation).getRules());
} catch (Exception foo) {
warnln("Exception: " + foo.getMessage() + "; Locale : " + locales[i].getDisplayName() + " getRules failed");
continue;
}
for (j = 0; j < FIXEDTESTSET; j++) {
for (int n = j + 1; n < FIXEDTESTSET; n++) {
doTest(tblColl1, testCases[results[i][j]], testCases[results[i][n]], -1);
}
}
myCollation = null;
}
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMonkeyTest method TestCompare.
// perform monkey tests using Collator.compare
@Test
public void TestCompare() {
if (source.length() == 0) {
errln("CollationMonkeyTest.TestCompare(): source is empty - ICU_DATA not set or data missing?");
return;
}
Collator myCollator;
try {
myCollator = Collator.getInstance(new Locale("en", "US"));
} catch (Exception e) {
warnln("ERROR: in creation of collator of ENGLISH locale");
return;
}
/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
// use test framework's random seed
Random rand = createRandom();
int s = rand.nextInt(0x7fff) % source.length();
int t = rand.nextInt(0x7fff) % source.length();
int slen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
int tlen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
String subs = source.substring(Math.min(s, slen), Math.min(s + slen, source.length()));
String subt = source.substring(Math.min(t, tlen), Math.min(t + tlen, source.length()));
myCollator.setStrength(Collator.TERTIARY);
// Tertiary
int result = myCollator.compare(subs, subt);
// Tertiary
int revResult = myCollator.compare(subt, subs);
report(subs, subt, result, revResult);
myCollator.setStrength(Collator.SECONDARY);
// Secondary
result = myCollator.compare(subs, subt);
// Secondary
revResult = myCollator.compare(subt, subs);
report(subs, subt, result, revResult);
myCollator.setStrength(Collator.PRIMARY);
// Primary
result = myCollator.compare(subs, subt);
// Primary
revResult = myCollator.compare(subt, subs);
report(subs, subt, result, revResult);
String msg = "";
String addOne = subs + String.valueOf(0xE000);
result = myCollator.compare(subs, addOne);
if (result != -1) {
msg += "Test : ";
msg += subs;
msg += " .LT. ";
msg += addOne;
msg += " Failed.";
errln(msg);
}
msg = "";
result = myCollator.compare(addOne, subs);
if (result != 1) {
msg += "Test : ";
msg += addOne;
msg += " .GT. ";
msg += subs;
msg += " Failed.";
errln(msg);
}
}
Aggregations