ticket: 2844:synch up icu4j/java i18n tests

X-SVN-Rev: 14445
This commit is contained in:
GCL Shanghai 2004-02-04 02:40:14 +00:00
parent 1fb1aab1ed
commit a130f9df82
5 changed files with 487 additions and 5 deletions

View file

@ -1076,5 +1076,15 @@ public class CollationAPITest extends TestFmwk {
}
}
}
}
public final void TestGetAll() {
Locale[] list = Collator.getAvailableLocales();
for (int i = 0; i < list.length; ++i) {
log("Locale name: ");
log(list[i].toString());
log(" , the display name is : ");
logln(list[i].getDisplayName());
}
}
}

View file

@ -19,7 +19,10 @@ package com.ibm.icu.dev.test.collator;
import com.ibm.icu.dev.test.*;
import com.ibm.icu.text.*;
import java.util.Locale;
import java.util.Vector;
import java.text.ParseException;
public class CollationRegressionTest extends TestFmwk {
public static void main(String[] args) throws Exception{
@ -834,6 +837,304 @@ public class CollationRegressionTest extends TestFmwk {
}
}
private void checkListOrder(String[] sortedList, Collator c) {
// this function uses the specified Collator to make sure the
// passed-in list is already sorted into ascending order
for (int i = 0; i < sortedList.length - 1; i++) {
if (c.compare(sortedList[i], sortedList[i + 1]) >= 0) {
errln("List out of order at element #" + i + ": "
+ sortedList[i] + " >= "
+ sortedList[i + 1]);
}
}
}
public void Test4171974() {
// test French accent ordering more thoroughly
/*String[] frenchList = {
"\u0075\u0075", // u u
"\u00fc\u0075", // u-umlaut u
"\u01d6\u0075", // u-umlaut-macron u
"\u016b\u0075", // u-macron u
"\u1e7b\u0075", // u-macron-umlaut u
"\u0075\u00fc", // u u-umlaut
"\u00fc\u00fc", // u-umlaut u-umlaut
"\u01d6\u00fc", // u-umlaut-macron u-umlaut
"\u016b\u00fc", // u-macron u-umlaut
"\u1e7b\u00fc", // u-macron-umlaut u-umlaut
"\u0075\u01d6", // u u-umlaut-macron
"\u00fc\u01d6", // u-umlaut u-umlaut-macron
"\u01d6\u01d6", // u-umlaut-macron u-umlaut-macron
"\u016b\u01d6", // u-macron u-umlaut-macron
"\u1e7b\u01d6", // u-macron-umlaut u-umlaut-macron
"\u0075\u016b", // u u-macron
"\u00fc\u016b", // u-umlaut u-macron
"\u01d6\u016b", // u-umlaut-macron u-macron
"\u016b\u016b", // u-macron u-macron
"\u1e7b\u016b", // u-macron-umlaut u-macron
"\u0075\u1e7b", // u u-macron-umlaut
"\u00fc\u1e7b", // u-umlaut u-macron-umlaut
"\u01d6\u1e7b", // u-umlaut-macron u-macron-umlaut
"\u016b\u1e7b", // u-macron u-macron-umlaut
"\u1e7b\u1e7b" // u-macron-umlaut u-macron-umlaut
};
Collator french = Collator.getInstance(Locale.FRENCH);
logln("Testing French order...");
checkListOrder(frenchList, french);
logln("Testing French order without decomposition...");
french.setDecomposition(Collator.NO_DECOMPOSITION);
checkListOrder(frenchList, french);*/
String[] englishList = {
"\u0075\u0075", // u u
"\u0075\u00fc", // u u-umlaut
"\u0075\u01d6", // u u-umlaut-macron
"\u0075\u016b", // u u-macron
"\u0075\u1e7b", // u u-macron-umlaut
"\u00fc\u0075", // u-umlaut u
"\u00fc\u00fc", // u-umlaut u-umlaut
"\u00fc\u01d6", // u-umlaut u-umlaut-macron
"\u00fc\u016b", // u-umlaut u-macron
"\u00fc\u1e7b", // u-umlaut u-macron-umlaut
"\u01d6\u0075", // u-umlaut-macron u
"\u01d6\u00fc", // u-umlaut-macron u-umlaut
"\u01d6\u01d6", // u-umlaut-macron u-umlaut-macron
"\u01d6\u016b", // u-umlaut-macron u-macron
"\u01d6\u1e7b", // u-umlaut-macron u-macron-umlaut
"\u016b\u0075", // u-macron u
"\u016b\u00fc", // u-macron u-umlaut
"\u016b\u01d6", // u-macron u-umlaut-macron
"\u016b\u016b", // u-macron u-macron
"\u016b\u1e7b", // u-macron u-macron-umlaut
"\u1e7b\u0075", // u-macron-umlaut u
"\u1e7b\u00fc", // u-macron-umlaut u-umlaut
"\u1e7b\u01d6", // u-macron-umlaut u-umlaut-macron
"\u1e7b\u016b", // u-macron-umlaut u-macron
"\u1e7b\u1e7b" // u-macron-umlaut u-macron-umlaut
};
Collator english = Collator.getInstance(Locale.ENGLISH);
logln("Testing English order...");
checkListOrder(englishList, english);
logln("Testing English order without decomposition...");
english.setDecomposition(Collator.NO_DECOMPOSITION);
checkListOrder(englishList, english);
}
public void Test4179216() throws Exception {
// you can position a CollationElementIterator in the middle of
// a contracting character sequence, yielding a bogus collation
// element
RuleBasedCollator coll = (RuleBasedCollator)Collator.getInstance(Locale.US);
coll = new RuleBasedCollator(coll.getRules()
+ " & C < ch , cH , Ch , CH < cat < crunchy");
String testText = "church church catcatcher runcrunchynchy";
CollationElementIterator iter = coll.getCollationElementIterator(
testText);
// test that the "ch" combination works properly
iter.setOffset(4);
int elt4 = CollationElementIterator.primaryOrder(iter.next());
iter.reset();
int elt0 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(5);
int elt5 = CollationElementIterator.primaryOrder(iter.next());
if (elt4 != elt0 || elt5 != elt0)
errln("The collation elements at positions 0 (" + elt0 + "), 4 ("
+ elt4 + "), and 5 (" + elt5 + ") don't match.");
// test that the "cat" combination works properly
iter.setOffset(14);
int elt14 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(15);
int elt15 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(16);
int elt16 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(17);
int elt17 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(18);
int elt18 = CollationElementIterator.primaryOrder(iter.next());
iter.setOffset(19);
int elt19 = CollationElementIterator.primaryOrder(iter.next());
if (elt14 != elt15 || elt14 != elt16 || elt14 != elt17
|| elt14 != elt18 || elt14 != elt19)
errln("\"cat\" elements don't match: elt14 = " + elt14 + ", elt15 = "
+ elt15 + ", elt16 = " + elt16 + ", elt17 = " + elt17
+ ", elt18 = " + elt18 + ", elt19 = " + elt19);
// now generate a complete list of the collation elements,
// first using next() and then using setOffset(), and
// make sure both interfaces return the same set of elements
iter.reset();
int elt = iter.next();
int count = 0;
while (elt != CollationElementIterator.NULLORDER) {
++count;
elt = iter.next();
}
String[] nextElements = new String[count];
String[] setOffsetElements = new String[count];
int lastPos = 0;
iter.reset();
elt = iter.next();
count = 0;
while (elt != CollationElementIterator.NULLORDER) {
nextElements[count++] = testText.substring(lastPos, iter.getOffset());
lastPos = iter.getOffset();
elt = iter.next();
}
count = 0;
for (int i = 0; i < testText.length(); ) {
iter.setOffset(i);
lastPos = iter.getOffset();
elt = iter.next();
setOffsetElements[count++] = testText.substring(lastPos, iter.getOffset());
i = iter.getOffset();
}
for (int i = 0; i < nextElements.length; i++) {
if (nextElements[i].equals(setOffsetElements[i])) {
logln(nextElements[i]);
} else {
errln("Error: next() yielded " + nextElements[i] + ", but setOffset() yielded "
+ setOffsetElements[i]);
}
}
}
public void Test4216006() throws Exception {
// rule parser barfs on "<\u00e0=a\u0300", and on other cases
// where the same token (after normalization) appears twice in a row
boolean caughtException = false;
try {
RuleBasedCollator dummy = new RuleBasedCollator("\u00e0<a\u0300");
}
catch (ParseException e) {
caughtException = true;
}
if (!caughtException) {
throw new Exception("\"a<a\" collation sequence didn't cause parse error!");
}
RuleBasedCollator collator = new RuleBasedCollator("<\u00e0=a\u0300");
//commented by Kevin 2003/10/21
//for "FULL_DECOMPOSITION is not supported here." in ICU4J DOC
//collator.setDecomposition(Collator.FULL_DECOMPOSITION);
collator.setStrength(Collator.IDENTICAL);
String[] tests = {
"a\u0300", "=", "\u00e0",
"\u00e0", "=", "a\u0300"
};
compareArray(collator, tests);
}
// CollationElementIterator.previous broken for expanding char sequences
//
public void Test4179686() throws Exception {
// Create a collator with a few expanding character sequences in it....
RuleBasedCollator coll = new RuleBasedCollator(en_us.getRules()
+ " & ae ; \u00e4 & AE ; \u00c4"
+ " & oe ; \u00f6 & OE ; \u00d6"
+ " & ue ; \u00fc & UE ; \u00dc");
String text = "T\u00f6ne"; // o-umlaut
CollationElementIterator iter = coll.getCollationElementIterator(text);
Vector elements = new Vector();
int elem;
// Iterate forward and collect all of the elements into a Vector
while ((elem = iter.next()) != CollationElementIterator.NULLORDER) {
elements.addElement(new Integer(elem));
}
// Now iterate backward and make sure they're the same
int index = elements.size() - 1;
while ((elem = iter.previous()) != CollationElementIterator.NULLORDER) {
int expect = ((Integer)elements.elementAt(index)).intValue();
if (elem != expect) {
errln("Mismatch at index " + index
+ ": got " + Integer.toString(elem,16)
+ ", expected " + Integer.toString(expect,16));
}
index--;
}
}
static RuleBasedCollator en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);
public void Test4244884() throws Exception {
RuleBasedCollator coll = (RuleBasedCollator)Collator.getInstance(Locale.US);
coll = new RuleBasedCollator(coll.getRules()
+ " & C < ch , cH , Ch , CH < cat < crunchy");
String[] testStrings = new String[] {
"car",
"cave",
"clamp",
"cramp",
"czar",
"church",
"catalogue",
"crunchy",
"dog"
};
for (int i = 1; i < testStrings.length; i++) {
if (coll.compare(testStrings[i - 1], testStrings[i]) >= 0) {
errln("error: \"" + testStrings[i - 1]
+ "\" is greater than or equal to \"" + testStrings[i]
+ "\".");
}
}
}
// CollationElementIterator set doesn't work propertly with next/prev
public void Test4663220() {
RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(Locale.US);
java.text.StringCharacterIterator stringIter = new java.text.StringCharacterIterator("fox");
CollationElementIterator iter = collator.getCollationElementIterator(stringIter);
int[] elements_next = new int[3];
logln("calling next:");
for (int i = 0; i < 3; ++i) {
logln("[" + i + "] " + (elements_next[i] = iter.next()));
}
int[] elements_fwd = new int[3];
logln("calling set/next:");
for (int i = 0; i < 3; ++i) {
iter.setOffset(i);
logln("[" + i + "] " + (elements_fwd[i] = iter.next()));
}
for (int i = 0; i < 3; ++i) {
if (elements_next[i] != elements_fwd[i]) {
errln("mismatch at position " + i +
": " + elements_next[i] +
" != " + elements_fwd[i]);
}
}
}
/* RuleBasedCollator not subclassable
* @bug 4146160
//

View file

@ -191,7 +191,37 @@ public class G7CollationTest extends TestFmwk{
}
}
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) {
errln("Exception: " + foo.getMessage() +
"; Locale : " + locales[i].getDisplayName() + " getRules failed\n");
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;
}
}
// main test routine, tests comparisons for a set of strings against sets of expected results

View file

@ -4,8 +4,8 @@
* Corporation and others. All Rights Reserved.
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/NumberRegression.java,v $
* $Date: 2003/12/20 03:06:51 $
* $Revision: 1.17 $
* $Date: 2004/02/04 02:36:38 $
* $Revision: 1.18 $
*
*****************************************************************************************
**/
@ -1763,6 +1763,43 @@ public class NumberRegression extends com.ibm.icu.dev.test.TestFmwk {
errln("FAIL: input: " + f + ", expected: 0.01, got: " + result);
}
}
/**
* 4241880: Decimal format doesnt round a double properly when the number is less than 1
*/
public void test4241880() {
Locale savedLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
double[] input = {
.019, .009, .015, .016, .014,
.004, .005, .006, .007, .008,
.5, 1.5, .05, .15, .005,
.015, .0005, .0015,
};
String[] pattern = {
"##0%", "##0%", "##0%", "##0%", "##0%",
"##0%", "##0%", "##0%", "##0%", "##0%",
"#,##0", "#,##0", "#,##0.0", "#,##0.0", "#,##0.00",
"#,##0.00", "#,##0.000", "#,##0.000",
};
String[] expected = {
"2%", "1%", "2%", "2%", "1%",
"0%", "0%", "1%", "1%", "1%",
"0", "2", "0.0", "0.2", "0.00",
"0.02", "0.000", "0.002",
};
for (int i = 0; i < input.length; i++) {
DecimalFormat format = new DecimalFormat(pattern[i]);
String result = format.format(input[i]);
if (!result.equals(expected[i])) {
errln("FAIL: input: " + input[i] +
", pattern: " + pattern[i] +
", expected: " + expected[i] +
", got: " + result);
}
}
Locale.setDefault(savedLocale);
}
}
class myformat implements Serializable

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/rbbi/BreakIteratorTest.java,v $
* $Date: 2003/06/03 18:49:30 $
* $Revision: 1.12 $
* $Date: 2004/02/04 02:40:14 $
* $Revision: 1.13 $
*
*****************************************************************************************
*/
@ -1304,6 +1304,95 @@ lineSelectionData.addElement("(\u0e1b\u0e23\u0e30\u0e40\u0e17\u0e28\u0e44\u0e17\
}
}
/**
* Bug 4638433
*/
public void TestLineBreakBasedOnUnicode3_0_0() {
BreakIterator iter;
int i;
/* Latin Extend-B characters
* 0x0218-0x0233 which have been added since Unicode 3.0.0.
*/
iter = BreakIterator.getWordInstance(Locale.US);
iter.setText("\u0216\u0217\u0218\u0219\u021A");
i = iter.first();
i = iter.next();
if (i != 5) {
errln("Word break failure: failed to stop at 5 and bounded at " + i);
}
iter = BreakIterator.getLineInstance(Locale.US);
/* <Three(Nd)><Two(Nd)><Low Double Prime Quotation Mark(Pe)><One(Nd)>
* \u301f has changed its category from Ps to Pe since Unicode 2.1.
*/
iter.setText("32\u301f1");
i = iter.first();
i = iter.next();
if (i != 3) {
errln("Line break failure: failed to skip before \\u301F(Pe) at 3 and bounded at " + i);
}
/* Mongolian <Letter A(Lo)><Todo Soft Hyphen(Pd)><Letter E(Lo)>
* which have been added since Unicode 3.0.0.
*/
iter.setText("\u1820\u1806\u1821");
i = iter.first();
i = iter.next();
if (i != 2) {
errln("Mongolian line break failure: failed to skip position before \\u1806(Pd) at 2 and bounded at " + i);
}
/* Khmer <ZERO(Nd)><Currency Symbol(Sc)><ONE(Nd)> which have
* been added since Unicode 3.0.0.
*/
/*
* Richard: fail to pass, refer to #3550
iter.setText("\u17E0\u17DB\u17E1");
i = iter.first();
i = iter.next();
if (i != 1) {
errln("Khmer line break failure: failed to stop before \\u17DB(Sc) at 1 and bounded at " + i);
}
i = iter.next();
if (i != 3) {
errln("Khmer line break failure: failed to skip position after \\u17DB(Sc) at 3 and bounded at " + i);
}*/
/* Ogham <Letter UR(Lo)><Space Mark(Zs)><Letter OR(Lo)> which have
* been added since Unicode 3.0.0.
*/
iter.setText("\u1692\u1680\u1696");
i = iter.first();
i = iter.next();
if (i != 2) {
errln("Ogham line break failure: failed to skip postion before \\u1680(Zs) at 2 and bounded at " + i);
}
// Confirm changes in BreakIteratorRules_th.java have been reflected.
iter = BreakIterator.getLineInstance(new Locale("th", ""));
/* Thai <Seven(Nd)>
* <Left Double Quotation Mark(Pi)>
* <Five(Nd)>
* <Right Double Quotation Mark(Pf)>
* <Three(Nd)>
*/
iter.setText("\u0E57\u201C\u0E55\u201D\u0E53");
i = iter.first();
i = iter.next();
if (i != 1) {
errln("Thai line break failure: failed to stop before \\u201C(Pi) at 1 and bounded at " + i);
}
i = iter.next();
if (i != 4) {
errln("Thai line break failure: failed to stop after \\u201D(Pf) at 4 and bounded at " + i);
}
}
/**
* @bug 4068137
*/
@ -1416,5 +1505,20 @@ lineSelectionData.addElement("(\u0e1b\u0e23\u0e30\u0e40\u0e17\u0e28\u0e44\u0e17\
generalIteratorTest(e, thaiWordSelection);
}
/**
* Bug 4450804
*/
public void TestLineBreakContractions() {
Vector expected = new Vector();
expected.add("These ");
expected.add("are ");
expected.add("'foobles'. ");
expected.add("Don't ");
expected.add("you ");
expected.add("like ");
expected.add("them?");
generalIteratorTest(lineBreak, expected);
}
}