Cleanup
X-SVN-Rev: 1267
This commit is contained in:
parent
a7adfb1195
commit
17fb1e156d
@ -14,345 +14,318 @@ public class RoundTripTest extends TestFmwk {
|
|||||||
new RoundTripTest().run(args);
|
new RoundTripTest().run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TestRoundTrip() throws IOException, ParseException {
|
public void TestHiragana() throws IOException, ParseException {
|
||||||
Test t;
|
|
||||||
|
|
||||||
// Test Hiragana
|
|
||||||
new Test("Latin-Kana",
|
new Test("Latin-Kana",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.HIRAGANA_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.HIRAGANA_SCRIPT)
|
||||||
.test("[a-z]", "[\u3040-\u3094]", this);
|
.test("[a-z]", "[\u3040-\u3094]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Katakana
|
public void TestKatakana() throws IOException, ParseException {
|
||||||
new Test("Latin-Kana",
|
new Test("Latin-Kana",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.KATAKANA_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.KATAKANA_SCRIPT)
|
||||||
.test("[A-Z]", "[\u30A1-\u30FA]", this);
|
.test("[A-Z]", "[\u30A1-\u30FA]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Arabic
|
public void TestArabic() throws IOException, ParseException {
|
||||||
new Test("Latin-Arabic",
|
new Test("Latin-Arabic",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.ARABIC_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.ARABIC_SCRIPT)
|
||||||
.test(null, "[\u0620-\u065F-[\u0640]]", this);
|
.test(null, "[\u0620-\u065F-[\u0640]]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Hebrew
|
public void TestHebrew() throws IOException, ParseException {
|
||||||
new Test("Latin-Hebrew",
|
new Test("Latin-Hebrew",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.HEBREW_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.HEBREW_SCRIPT)
|
||||||
.test(null, "[\u05D0-\u05EF]", this);
|
.test(null, "[\u05D0-\u05EF]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Hangul
|
public void TestHangul() throws IOException, ParseException {
|
||||||
t = new TestHangul();
|
Test t = new TestHangul();
|
||||||
t.setPairLimit(30); // Don't run full test -- too long
|
t.setPairLimit(30); // Don't run full test -- too long
|
||||||
t.test(null, null, this);
|
t.test(null, null, this);
|
||||||
|
}
|
||||||
// Test Jamo
|
|
||||||
t = new Test("Latin-Jamo",
|
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.JAMO_SCRIPT);
|
|
||||||
t.setErrorLimit(100);
|
|
||||||
t.test(null, null, this);
|
|
||||||
|
|
||||||
// Test JamoHangul
|
|
||||||
t = new Test("Latin-Jamo;Jamo-Hangul",
|
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.HANGUL_SCRIPT);
|
|
||||||
t.setErrorLimit(100);
|
|
||||||
t.test(null, null, this);
|
|
||||||
|
|
||||||
// Test Greek
|
public void TestJamo() throws IOException, ParseException {
|
||||||
|
Test t = new Test("Latin-Jamo",
|
||||||
|
TestUtility.LATIN_SCRIPT, TestUtility.JAMO_SCRIPT);
|
||||||
|
t.setErrorLimit(100); // Don't run full test -- too long
|
||||||
|
t.test(null, null, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TestJamoHangul() throws IOException, ParseException {
|
||||||
|
Test t = new Test("Latin-Jamo;Jamo-Hangul",
|
||||||
|
TestUtility.LATIN_SCRIPT, TestUtility.HANGUL_SCRIPT);
|
||||||
|
t.setErrorLimit(50); // Don't run full test -- too long
|
||||||
|
t.test(null, null, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TestGreek() throws IOException, ParseException {
|
||||||
new Test("Latin-Greek",
|
new Test("Latin-Greek",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.GREEK_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.GREEK_SCRIPT)
|
||||||
.test(null, "[\u0380-\u03CF]", this);
|
.test(null, "[\u0380-\u03CF]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Cyrillic
|
public void TestCyrillic() throws IOException, ParseException {
|
||||||
new Test("Latin-Cyrillic",
|
new Test("Latin-Cyrillic",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.CYRILLIC_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.CYRILLIC_SCRIPT)
|
||||||
.test(null, "[\u0401\u0410-\u0451]", this);
|
.test(null, "[\u0401\u0410-\u0451]", this);
|
||||||
|
|
||||||
// Test Utility
|
|
||||||
// TestUtility.test(); // dump blocks and scripts for debugging
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Test {
|
static class Test {
|
||||||
|
|
||||||
PrintWriter out;
|
PrintWriter out;
|
||||||
|
|
||||||
private String transliteratorID;
|
private String transliteratorID;
|
||||||
private byte sourceScript;
|
private byte sourceScript;
|
||||||
private byte targetScript;
|
private byte targetScript;
|
||||||
private boolean showProgress = true;
|
private int errorLimit = Integer.MAX_VALUE;
|
||||||
private boolean showSuccess = false;
|
private int errorCount = 0;
|
||||||
private int errorLimit = Integer.MAX_VALUE;
|
private int pairLimit = 0x10000;
|
||||||
private int errorCount = 0;
|
UnicodeSet sourceRange;
|
||||||
private int pairLimit = 0x10000;
|
UnicodeSet targetRange;
|
||||||
UnicodeSet sourceRange;
|
TestLog log;
|
||||||
UnicodeSet targetRange;
|
|
||||||
TestLog log;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create a test for the given script transliterator.
|
* create a test for the given script transliterator.
|
||||||
*/
|
*/
|
||||||
Test(String transliteratorID,
|
Test(String transliteratorID,
|
||||||
byte sourceScript, byte targetScript) {
|
byte sourceScript, byte targetScript) {
|
||||||
this.transliteratorID = transliteratorID;
|
this.transliteratorID = transliteratorID;
|
||||||
this.sourceScript = sourceScript;
|
this.sourceScript = sourceScript;
|
||||||
this.targetScript = targetScript;
|
this.targetScript = targetScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setErrorLimit(int limit) {
|
public void setErrorLimit(int limit) {
|
||||||
errorLimit = limit;
|
errorLimit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPairLimit(int limit) {
|
public void setPairLimit(int limit) {
|
||||||
pairLimit = limit;
|
pairLimit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test(String sourceRange, String targetRange, TestLog log)
|
public void test(String sourceRange, String targetRange, TestLog log)
|
||||||
throws java.io.IOException, java.text.ParseException {
|
throws java.io.IOException, java.text.ParseException {
|
||||||
|
|
||||||
if (sourceRange != null && sourceRange.length() > 0) {
|
if (sourceRange != null && sourceRange.length() > 0) {
|
||||||
this.sourceRange = new UnicodeSet(sourceRange);
|
this.sourceRange = new UnicodeSet(sourceRange);
|
||||||
}
|
}
|
||||||
if (targetRange != null && targetRange.length() > 0) {
|
if (targetRange != null && targetRange.length() > 0) {
|
||||||
this.targetRange = new UnicodeSet(targetRange);
|
this.targetRange = new UnicodeSet(targetRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sourceRange == null) this.sourceRange = new UnicodeSet("[a-Z]");
|
if (this.sourceRange == null) this.sourceRange = new UnicodeSet("[a-Z]");
|
||||||
|
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
|
||||||
// make a UTF-8 output file we can read with a browser
|
// make a UTF-8 output file we can read with a browser
|
||||||
|
|
||||||
// note: check that every transliterator transliterates the null string correctly!
|
// note: check that every transliterator transliterates the null string correctly!
|
||||||
|
|
||||||
String logFileName = "test_" + transliteratorID + "_"
|
String logFileName = "test_" + transliteratorID + "_"
|
||||||
+ sourceScript + "_" + targetScript + ".html";
|
+ sourceScript + "_" + targetScript + ".html";
|
||||||
|
|
||||||
log.logln("Creating log file " + logFileName);
|
log.logln("Creating log file " + logFileName);
|
||||||
|
|
||||||
out = new PrintWriter(
|
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
|
||||||
new BufferedWriter(
|
new FileOutputStream(logFileName), "UTF8"), 4*1024));
|
||||||
new OutputStreamWriter(
|
|
||||||
new FileOutputStream(logFileName),
|
|
||||||
"UTF8"),
|
|
||||||
4*1024));
|
|
||||||
//out.write('\uFFEF'); // BOM
|
//out.write('\uFFEF'); // BOM
|
||||||
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
|
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
|
||||||
out.println("<HTML><HEAD>");
|
out.println("<HTML><HEAD>");
|
||||||
out.println("<META content=\"text/html; charset=utf-8\" http-equiv=Content-Type></HEAD>");
|
out.println("<META content=\"text/html; charset=utf-8\" http-equiv=Content-Type></HEAD>");
|
||||||
out.println("<BODY>");
|
out.println("<BODY>");
|
||||||
out.println("<TABLE>");
|
out.println("<TABLE>");
|
||||||
test2();
|
try {
|
||||||
out.println("</TABLE></BODY></HTML>");
|
test2();
|
||||||
|
out.println("</TABLE>");
|
||||||
|
} catch (TestTruncated e) {
|
||||||
|
out.println("</TABLE>" + e.getMessage());
|
||||||
|
}
|
||||||
|
out.println("</BODY></HTML>");
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
if (errorCount > 0) {
|
if (errorCount > 0) {
|
||||||
log.errln(transliteratorID + " errors: " + errorCount);
|
log.errln(transliteratorID + " errors: " + errorCount + ", see " + logFileName);
|
||||||
} else {
|
} else {
|
||||||
log.logln(transliteratorID + " ok");
|
log.logln(transliteratorID + " ok");
|
||||||
new File(logFileName).delete();
|
new File(logFileName).delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test2() {
|
public void test2() {
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
Transliterator sourceToTarget = Transliterator.getInstance(transliteratorID);
|
Transliterator sourceToTarget = Transliterator.getInstance(transliteratorID);
|
||||||
Transliterator targetToSource = sourceToTarget.getInverse();
|
Transliterator targetToSource = sourceToTarget.getInverse();
|
||||||
|
|
||||||
log.logln("Checking that all source characters convert to target - Singles");
|
log.logln("Checking that all source characters convert to target - Singles");
|
||||||
|
|
||||||
// check single letters
|
|
||||||
for (char c = 0; c < 0xFFFF; ++c) {
|
for (char c = 0; c < 0xFFFF; ++c) {
|
||||||
if (Character.getType(c) == Character.UNASSIGNED) continue;
|
if (Character.getType(c) == Character.UNASSIGNED ||
|
||||||
if (!isSource(c)) continue;
|
!isSource(c)) continue;
|
||||||
//if (showProgress && (count++ % 100) == 0) {
|
String cs = String.valueOf(c);
|
||||||
// log.logln(count + ": " + TestUtility.hex(c));
|
String targ = sourceToTarget.transliterate(String.valueOf(cs));
|
||||||
//}
|
if (!isReceivingTarget(targ)) {
|
||||||
String cs = String.valueOf(c);
|
logWrongScript("Source-Target", cs, targ);
|
||||||
String targ = sourceToTarget.transliterate(String.valueOf(cs));
|
}
|
||||||
if (!isReceivingTarget(targ)) {
|
|
||||||
out.println("<TR><TD>Fail Source-Target: " + cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")</TD></TR>");
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (showSuccess) {
|
|
||||||
out.println(c + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logln("Checking that all source characters convert to target - Doubles");
|
log.logln("Checking that all source characters convert to target - Doubles");
|
||||||
count = 0;
|
|
||||||
|
|
||||||
for (char c = 0; c < 0xFFFF; ++c) {
|
for (char c = 0; c < 0xFFFF; ++c) {
|
||||||
if (Character.getType(c) == Character.UNASSIGNED) continue;
|
if (Character.getType(c) == Character.UNASSIGNED ||
|
||||||
if (!isSource(c)) continue;
|
!isSource(c)) continue;
|
||||||
for (char d = 0; d < 0xFFFF; ++d) {
|
for (char d = 0; d < 0xFFFF; ++d) {
|
||||||
if (Character.getType(d) == Character.UNASSIGNED) continue;
|
if (Character.getType(d) == Character.UNASSIGNED ||
|
||||||
if (!isSource(d)) continue;
|
!isSource(d)) continue;
|
||||||
String cs = String.valueOf(c) + d;
|
String cs = String.valueOf(c) + d;
|
||||||
//if (showProgress && (count++ % 1000) == 0) {
|
String targ = sourceToTarget.transliterate(cs);
|
||||||
// log.logln(count + ": " + TestUtility.hex(cs));
|
if (!isReceivingTarget(targ)) {
|
||||||
//}
|
logWrongScript("Source-Target", cs, targ);
|
||||||
String targ = sourceToTarget.transliterate(cs);
|
}
|
||||||
if (!isReceivingTarget(targ)) {
|
|
||||||
out.println("<TR><TD>Fail Source-Target: " + cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")</TR></TD>");
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (showSuccess) {
|
|
||||||
out.println(c + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logln("Checking that target characters convert to source and back - Singles");
|
log.logln("Checking that target characters convert to source and back - Singles");
|
||||||
count = 0;
|
|
||||||
|
|
||||||
for (char c = 0; c < 0xFFFF; ++c) {
|
for (char c = 0; c < 0xFFFF; ++c) {
|
||||||
if (Character.getType(c) == Character.UNASSIGNED) continue;
|
if (Character.getType(c) == Character.UNASSIGNED ||
|
||||||
if (!isTarget(c)) continue;
|
!isTarget(c)) continue;
|
||||||
//if (showProgress && (count++ % 100) == 0) {
|
String cs = String.valueOf(c);
|
||||||
// log.logln(count + ": " + TestUtility.hex(c));
|
|
||||||
//}
|
|
||||||
String cs = String.valueOf(c);
|
|
||||||
if (c > 0x0400) {
|
|
||||||
cs = cs + "";
|
|
||||||
}
|
|
||||||
String targ = targetToSource.transliterate(cs);
|
|
||||||
String reverse = sourceToTarget.transliterate(targ);
|
|
||||||
if (!isReceivingSource(targ)) {
|
|
||||||
out.println("<TR><TD>Fail Target-Source: " + cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")</TR></TD>" );
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (!cs.equals(reverse)) {
|
|
||||||
out.println("<TR><TD>Fail Roundtrip:</TD><TD><FONT SIZE=\"6\">" +
|
|
||||||
cs + "</FONT></TD><TD>(" +
|
|
||||||
TestUtility.hex(cs) + ") =></TD><TD>" +
|
|
||||||
targ + "</TD><TD>(" +
|
|
||||||
TestUtility.hex(targ) + ") =></TD><TD><FONT SIZE=\"6\">" +
|
|
||||||
reverse + "</TD><TD>(" +
|
|
||||||
TestUtility.hex(reverse) + ")</TD></TR>" );
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (showSuccess) {
|
|
||||||
out.println(cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")"
|
|
||||||
+ " => " + reverse + "(" + TestUtility.hex(reverse) + ")" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.logln("Checking that target characters convert to source and back - Doubles");
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
StringBuffer buf = new StringBuffer("aa");
|
|
||||||
for (char c = 0; c < 0xFFFF; ++c) {
|
|
||||||
if (Character.getType(c) == Character.UNASSIGNED) continue;
|
|
||||||
if (!isTarget(c)) continue;
|
|
||||||
if (++count > pairLimit) {
|
|
||||||
out.println("<TR><TD>Test truncated at " + pairLimit + " x 64k pairs</TR></TD>");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buf.setCharAt(0, c);
|
|
||||||
if (showProgress) { // && (count++ % 10000) == 0) {
|
|
||||||
log.log(TestUtility.hex(c));
|
|
||||||
// count + ": " + TestUtility.hex(cs));
|
|
||||||
}
|
|
||||||
for (char d = 0; d < 0xFFFF; ++d) {
|
|
||||||
if (Character.getType(d) == Character.UNASSIGNED) continue;
|
|
||||||
if (!isTarget(d)) continue;
|
|
||||||
buf.setCharAt(1, d);
|
|
||||||
String cs = buf.toString();
|
|
||||||
String targ = targetToSource.transliterate(cs);
|
String targ = targetToSource.transliterate(cs);
|
||||||
String reverse = sourceToTarget.transliterate(targ);
|
String reverse = sourceToTarget.transliterate(targ);
|
||||||
if (!isReceivingSource(targ)) {
|
if (!isReceivingSource(targ)) {
|
||||||
out.println("<TR><TD>Fail Target-Source: " + cs + "(" + TestUtility.hex(cs) + ")"
|
logWrongScript("Target-Source", cs, targ);
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")</TR></TD>" );
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (!cs.equals(reverse)) {
|
} else if (!cs.equals(reverse)) {
|
||||||
out.println("<TR><TD>Fail Roundtrip:</TD><TD><FONT SIZE=\"6\">" +
|
logRoundTripFailure(cs, targ, reverse);
|
||||||
cs + "</FONT></TD><TD>(" +
|
|
||||||
TestUtility.hex(cs) + ") =></TD><TD>" +
|
|
||||||
targ + "</TD><TD>(" +
|
|
||||||
TestUtility.hex(targ) + ") =></TD><TD><FONT SIZE=\"6\">" +
|
|
||||||
reverse + "</TD><TD>(" +
|
|
||||||
TestUtility.hex(reverse) + ")</TD></TR>" );
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (showSuccess) {
|
|
||||||
out.println(cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")"
|
|
||||||
+ " => " + reverse + "(" + TestUtility.hex(reverse) + ")" );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (showProgress) log.logln("");
|
|
||||||
|
log.logln("Checking that target characters convert to source and back - Doubles");
|
||||||
|
int count = 0;
|
||||||
|
StringBuffer buf = new StringBuffer("aa");
|
||||||
|
for (char c = 0; c < 0xFFFF; ++c) {
|
||||||
|
if (Character.getType(c) == Character.UNASSIGNED ||
|
||||||
|
!isTarget(c)) continue;
|
||||||
|
if (++count > pairLimit) {
|
||||||
|
throw new TestTruncated("Test truncated at " + pairLimit + " x 64k pairs");
|
||||||
|
}
|
||||||
|
buf.setCharAt(0, c);
|
||||||
|
log.log(TestUtility.hex(c));
|
||||||
|
for (char d = 0; d < 0xFFFF; ++d) {
|
||||||
|
if (Character.getType(d) == Character.UNASSIGNED ||
|
||||||
|
!isTarget(d)) continue;
|
||||||
|
buf.setCharAt(1, d);
|
||||||
|
String cs = buf.toString();
|
||||||
|
String targ = targetToSource.transliterate(cs);
|
||||||
|
String reverse = sourceToTarget.transliterate(targ);
|
||||||
|
if (!isReceivingSource(targ)) {
|
||||||
|
logWrongScript("Target-Source", cs, targ);
|
||||||
|
} else if (!cs.equals(reverse)) {
|
||||||
|
logRoundTripFailure(cs, targ, reverse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.logln("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
final void logWrongScript(String label, String from, String to) {
|
||||||
* Characters to filter for source-target mapping completeness
|
out.println("<TR><TD>Fail " + label + ":</TD><TD><FONT SIZE=\"6\">" +
|
||||||
* Typically is base alphabet, minus extended characters
|
from + "</FONT></TD><TD>(" +
|
||||||
* Default is ASCII letters for Latin
|
TestUtility.hex(from) + ") =></TD><TD><FONT SIZE=\"6\">" +
|
||||||
*/
|
to + "</FONT></TD><TD>(" +
|
||||||
public boolean isSource(char c) {
|
TestUtility.hex(to) + ")</TD></TR>" );
|
||||||
byte script = TestUtility.getScript(c);
|
if (++errorCount >= errorLimit) {
|
||||||
if (script != sourceScript) return false;
|
throw new TestTruncated("Test truncated; too many failures");
|
||||||
if (!Character.isLetter(c)) return false;
|
}
|
||||||
if (!sourceRange.contains(c)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Characters to check for target back to source mapping.
|
|
||||||
* Typically the same as the target script, plus punctuation
|
|
||||||
*/
|
|
||||||
public boolean isReceivingSource(char c) {
|
|
||||||
byte script = TestUtility.getScript(c);
|
|
||||||
return (script == sourceScript || script == TestUtility.COMMON_SCRIPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Characters to filter for target-source mapping
|
|
||||||
* Typically is base alphabet, minus extended characters
|
|
||||||
*/
|
|
||||||
public boolean isTarget(char c) {
|
|
||||||
byte script = TestUtility.getScript(c);
|
|
||||||
if (script != targetScript) return false;
|
|
||||||
if (!Character.isLetter(c)) return false;
|
|
||||||
if (targetRange != null && !targetRange.contains(c)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Characters to check for target-source mapping
|
|
||||||
* Typically the same as the source script, plus punctuation
|
|
||||||
*/
|
|
||||||
public boolean isReceivingTarget(char c) {
|
|
||||||
byte script = TestUtility.getScript(c);
|
|
||||||
return (script == targetScript || script == TestUtility.COMMON_SCRIPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final boolean isSource(String s) {
|
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
|
||||||
if (!isSource(s.charAt(i))) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean isTarget(String s) {
|
final void logRoundTripFailure(String from, String to, String back) {
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
out.println("<TR><TD>Fail Roundtrip:</TD><TD><FONT SIZE=\"6\">" +
|
||||||
if (!isTarget(s.charAt(i))) return false;
|
from + "</FONT></TD><TD>(" +
|
||||||
|
TestUtility.hex(from) + ") =></TD><TD>" +
|
||||||
|
to + "</TD><TD>(" +
|
||||||
|
TestUtility.hex(to) + ") =></TD><TD><FONT SIZE=\"6\">" +
|
||||||
|
back + "</TD><TD>(" +
|
||||||
|
TestUtility.hex(back) + ")</TD></TR>" );
|
||||||
|
if (++errorCount >= errorLimit) {
|
||||||
|
throw new TestTruncated("Test truncated; too many failures");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean isReceivingSource(String s) {
|
/*
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
* Characters to filter for source-target mapping completeness
|
||||||
if (!isReceivingSource(s.charAt(i))) return false;
|
* Typically is base alphabet, minus extended characters
|
||||||
|
* Default is ASCII letters for Latin
|
||||||
|
*/
|
||||||
|
public boolean isSource(char c) {
|
||||||
|
byte script = TestUtility.getScript(c);
|
||||||
|
if (script != sourceScript) return false;
|
||||||
|
if (!Character.isLetter(c)) return false;
|
||||||
|
if (!sourceRange.contains(c)) return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean isReceivingTarget(String s) {
|
/*
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
* Characters to check for target back to source mapping.
|
||||||
if (!isReceivingTarget(s.charAt(i))) return false;
|
* Typically the same as the target script, plus punctuation
|
||||||
|
*/
|
||||||
|
public boolean isReceivingSource(char c) {
|
||||||
|
byte script = TestUtility.getScript(c);
|
||||||
|
return (script == sourceScript || script == TestUtility.COMMON_SCRIPT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters to filter for target-source mapping
|
||||||
|
* Typically is base alphabet, minus extended characters
|
||||||
|
*/
|
||||||
|
public boolean isTarget(char c) {
|
||||||
|
byte script = TestUtility.getScript(c);
|
||||||
|
if (script != targetScript) return false;
|
||||||
|
if (!Character.isLetter(c)) return false;
|
||||||
|
if (targetRange != null && !targetRange.contains(c)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters to check for target-source mapping
|
||||||
|
* Typically the same as the source script, plus punctuation
|
||||||
|
*/
|
||||||
|
public boolean isReceivingTarget(char c) {
|
||||||
|
byte script = TestUtility.getScript(c);
|
||||||
|
return (script == targetScript || script == TestUtility.COMMON_SCRIPT);
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isSource(String s) {
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isSource(s.charAt(i))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isTarget(String s) {
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isTarget(s.charAt(i))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isReceivingSource(String s) {
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isReceivingSource(s.charAt(i))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isReceivingTarget(String s) {
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isReceivingTarget(s.charAt(i))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TestTruncated extends RuntimeException {
|
||||||
|
TestTruncated(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestHangul extends Test {
|
static class TestHangul extends Test {
|
||||||
|
@ -14,345 +14,318 @@ public class RoundTripTest extends TestFmwk {
|
|||||||
new RoundTripTest().run(args);
|
new RoundTripTest().run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TestRoundTrip() throws IOException, ParseException {
|
public void TestHiragana() throws IOException, ParseException {
|
||||||
Test t;
|
|
||||||
|
|
||||||
// Test Hiragana
|
|
||||||
new Test("Latin-Kana",
|
new Test("Latin-Kana",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.HIRAGANA_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.HIRAGANA_SCRIPT)
|
||||||
.test("[a-z]", "[\u3040-\u3094]", this);
|
.test("[a-z]", "[\u3040-\u3094]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Katakana
|
public void TestKatakana() throws IOException, ParseException {
|
||||||
new Test("Latin-Kana",
|
new Test("Latin-Kana",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.KATAKANA_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.KATAKANA_SCRIPT)
|
||||||
.test("[A-Z]", "[\u30A1-\u30FA]", this);
|
.test("[A-Z]", "[\u30A1-\u30FA]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Arabic
|
public void TestArabic() throws IOException, ParseException {
|
||||||
new Test("Latin-Arabic",
|
new Test("Latin-Arabic",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.ARABIC_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.ARABIC_SCRIPT)
|
||||||
.test(null, "[\u0620-\u065F-[\u0640]]", this);
|
.test(null, "[\u0620-\u065F-[\u0640]]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Hebrew
|
public void TestHebrew() throws IOException, ParseException {
|
||||||
new Test("Latin-Hebrew",
|
new Test("Latin-Hebrew",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.HEBREW_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.HEBREW_SCRIPT)
|
||||||
.test(null, "[\u05D0-\u05EF]", this);
|
.test(null, "[\u05D0-\u05EF]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Hangul
|
public void TestHangul() throws IOException, ParseException {
|
||||||
t = new TestHangul();
|
Test t = new TestHangul();
|
||||||
t.setPairLimit(30); // Don't run full test -- too long
|
t.setPairLimit(30); // Don't run full test -- too long
|
||||||
t.test(null, null, this);
|
t.test(null, null, this);
|
||||||
|
}
|
||||||
// Test Jamo
|
|
||||||
t = new Test("Latin-Jamo",
|
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.JAMO_SCRIPT);
|
|
||||||
t.setErrorLimit(100);
|
|
||||||
t.test(null, null, this);
|
|
||||||
|
|
||||||
// Test JamoHangul
|
|
||||||
t = new Test("Latin-Jamo;Jamo-Hangul",
|
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.HANGUL_SCRIPT);
|
|
||||||
t.setErrorLimit(100);
|
|
||||||
t.test(null, null, this);
|
|
||||||
|
|
||||||
// Test Greek
|
public void TestJamo() throws IOException, ParseException {
|
||||||
|
Test t = new Test("Latin-Jamo",
|
||||||
|
TestUtility.LATIN_SCRIPT, TestUtility.JAMO_SCRIPT);
|
||||||
|
t.setErrorLimit(100); // Don't run full test -- too long
|
||||||
|
t.test(null, null, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TestJamoHangul() throws IOException, ParseException {
|
||||||
|
Test t = new Test("Latin-Jamo;Jamo-Hangul",
|
||||||
|
TestUtility.LATIN_SCRIPT, TestUtility.HANGUL_SCRIPT);
|
||||||
|
t.setErrorLimit(50); // Don't run full test -- too long
|
||||||
|
t.test(null, null, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TestGreek() throws IOException, ParseException {
|
||||||
new Test("Latin-Greek",
|
new Test("Latin-Greek",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.GREEK_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.GREEK_SCRIPT)
|
||||||
.test(null, "[\u0380-\u03CF]", this);
|
.test(null, "[\u0380-\u03CF]", this);
|
||||||
|
}
|
||||||
|
|
||||||
// Test Cyrillic
|
public void TestCyrillic() throws IOException, ParseException {
|
||||||
new Test("Latin-Cyrillic",
|
new Test("Latin-Cyrillic",
|
||||||
TestUtility.LATIN_SCRIPT, TestUtility.CYRILLIC_SCRIPT)
|
TestUtility.LATIN_SCRIPT, TestUtility.CYRILLIC_SCRIPT)
|
||||||
.test(null, "[\u0401\u0410-\u0451]", this);
|
.test(null, "[\u0401\u0410-\u0451]", this);
|
||||||
|
|
||||||
// Test Utility
|
|
||||||
// TestUtility.test(); // dump blocks and scripts for debugging
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Test {
|
static class Test {
|
||||||
|
|
||||||
PrintWriter out;
|
PrintWriter out;
|
||||||
|
|
||||||
private String transliteratorID;
|
private String transliteratorID;
|
||||||
private byte sourceScript;
|
private byte sourceScript;
|
||||||
private byte targetScript;
|
private byte targetScript;
|
||||||
private boolean showProgress = true;
|
private int errorLimit = Integer.MAX_VALUE;
|
||||||
private boolean showSuccess = false;
|
private int errorCount = 0;
|
||||||
private int errorLimit = Integer.MAX_VALUE;
|
private int pairLimit = 0x10000;
|
||||||
private int errorCount = 0;
|
UnicodeSet sourceRange;
|
||||||
private int pairLimit = 0x10000;
|
UnicodeSet targetRange;
|
||||||
UnicodeSet sourceRange;
|
TestLog log;
|
||||||
UnicodeSet targetRange;
|
|
||||||
TestLog log;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create a test for the given script transliterator.
|
* create a test for the given script transliterator.
|
||||||
*/
|
*/
|
||||||
Test(String transliteratorID,
|
Test(String transliteratorID,
|
||||||
byte sourceScript, byte targetScript) {
|
byte sourceScript, byte targetScript) {
|
||||||
this.transliteratorID = transliteratorID;
|
this.transliteratorID = transliteratorID;
|
||||||
this.sourceScript = sourceScript;
|
this.sourceScript = sourceScript;
|
||||||
this.targetScript = targetScript;
|
this.targetScript = targetScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setErrorLimit(int limit) {
|
public void setErrorLimit(int limit) {
|
||||||
errorLimit = limit;
|
errorLimit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPairLimit(int limit) {
|
public void setPairLimit(int limit) {
|
||||||
pairLimit = limit;
|
pairLimit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test(String sourceRange, String targetRange, TestLog log)
|
public void test(String sourceRange, String targetRange, TestLog log)
|
||||||
throws java.io.IOException, java.text.ParseException {
|
throws java.io.IOException, java.text.ParseException {
|
||||||
|
|
||||||
if (sourceRange != null && sourceRange.length() > 0) {
|
if (sourceRange != null && sourceRange.length() > 0) {
|
||||||
this.sourceRange = new UnicodeSet(sourceRange);
|
this.sourceRange = new UnicodeSet(sourceRange);
|
||||||
}
|
}
|
||||||
if (targetRange != null && targetRange.length() > 0) {
|
if (targetRange != null && targetRange.length() > 0) {
|
||||||
this.targetRange = new UnicodeSet(targetRange);
|
this.targetRange = new UnicodeSet(targetRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sourceRange == null) this.sourceRange = new UnicodeSet("[a-Z]");
|
if (this.sourceRange == null) this.sourceRange = new UnicodeSet("[a-Z]");
|
||||||
|
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
|
||||||
// make a UTF-8 output file we can read with a browser
|
// make a UTF-8 output file we can read with a browser
|
||||||
|
|
||||||
// note: check that every transliterator transliterates the null string correctly!
|
// note: check that every transliterator transliterates the null string correctly!
|
||||||
|
|
||||||
String logFileName = "test_" + transliteratorID + "_"
|
String logFileName = "test_" + transliteratorID + "_"
|
||||||
+ sourceScript + "_" + targetScript + ".html";
|
+ sourceScript + "_" + targetScript + ".html";
|
||||||
|
|
||||||
log.logln("Creating log file " + logFileName);
|
log.logln("Creating log file " + logFileName);
|
||||||
|
|
||||||
out = new PrintWriter(
|
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
|
||||||
new BufferedWriter(
|
new FileOutputStream(logFileName), "UTF8"), 4*1024));
|
||||||
new OutputStreamWriter(
|
|
||||||
new FileOutputStream(logFileName),
|
|
||||||
"UTF8"),
|
|
||||||
4*1024));
|
|
||||||
//out.write('\uFFEF'); // BOM
|
//out.write('\uFFEF'); // BOM
|
||||||
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
|
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
|
||||||
out.println("<HTML><HEAD>");
|
out.println("<HTML><HEAD>");
|
||||||
out.println("<META content=\"text/html; charset=utf-8\" http-equiv=Content-Type></HEAD>");
|
out.println("<META content=\"text/html; charset=utf-8\" http-equiv=Content-Type></HEAD>");
|
||||||
out.println("<BODY>");
|
out.println("<BODY>");
|
||||||
out.println("<TABLE>");
|
out.println("<TABLE>");
|
||||||
test2();
|
try {
|
||||||
out.println("</TABLE></BODY></HTML>");
|
test2();
|
||||||
|
out.println("</TABLE>");
|
||||||
|
} catch (TestTruncated e) {
|
||||||
|
out.println("</TABLE>" + e.getMessage());
|
||||||
|
}
|
||||||
|
out.println("</BODY></HTML>");
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
if (errorCount > 0) {
|
if (errorCount > 0) {
|
||||||
log.errln(transliteratorID + " errors: " + errorCount);
|
log.errln(transliteratorID + " errors: " + errorCount + ", see " + logFileName);
|
||||||
} else {
|
} else {
|
||||||
log.logln(transliteratorID + " ok");
|
log.logln(transliteratorID + " ok");
|
||||||
new File(logFileName).delete();
|
new File(logFileName).delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test2() {
|
public void test2() {
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
Transliterator sourceToTarget = Transliterator.getInstance(transliteratorID);
|
Transliterator sourceToTarget = Transliterator.getInstance(transliteratorID);
|
||||||
Transliterator targetToSource = sourceToTarget.getInverse();
|
Transliterator targetToSource = sourceToTarget.getInverse();
|
||||||
|
|
||||||
log.logln("Checking that all source characters convert to target - Singles");
|
log.logln("Checking that all source characters convert to target - Singles");
|
||||||
|
|
||||||
// check single letters
|
|
||||||
for (char c = 0; c < 0xFFFF; ++c) {
|
for (char c = 0; c < 0xFFFF; ++c) {
|
||||||
if (Character.getType(c) == Character.UNASSIGNED) continue;
|
if (Character.getType(c) == Character.UNASSIGNED ||
|
||||||
if (!isSource(c)) continue;
|
!isSource(c)) continue;
|
||||||
//if (showProgress && (count++ % 100) == 0) {
|
String cs = String.valueOf(c);
|
||||||
// log.logln(count + ": " + TestUtility.hex(c));
|
String targ = sourceToTarget.transliterate(String.valueOf(cs));
|
||||||
//}
|
if (!isReceivingTarget(targ)) {
|
||||||
String cs = String.valueOf(c);
|
logWrongScript("Source-Target", cs, targ);
|
||||||
String targ = sourceToTarget.transliterate(String.valueOf(cs));
|
}
|
||||||
if (!isReceivingTarget(targ)) {
|
|
||||||
out.println("<TR><TD>Fail Source-Target: " + cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")</TD></TR>");
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (showSuccess) {
|
|
||||||
out.println(c + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logln("Checking that all source characters convert to target - Doubles");
|
log.logln("Checking that all source characters convert to target - Doubles");
|
||||||
count = 0;
|
|
||||||
|
|
||||||
for (char c = 0; c < 0xFFFF; ++c) {
|
for (char c = 0; c < 0xFFFF; ++c) {
|
||||||
if (Character.getType(c) == Character.UNASSIGNED) continue;
|
if (Character.getType(c) == Character.UNASSIGNED ||
|
||||||
if (!isSource(c)) continue;
|
!isSource(c)) continue;
|
||||||
for (char d = 0; d < 0xFFFF; ++d) {
|
for (char d = 0; d < 0xFFFF; ++d) {
|
||||||
if (Character.getType(d) == Character.UNASSIGNED) continue;
|
if (Character.getType(d) == Character.UNASSIGNED ||
|
||||||
if (!isSource(d)) continue;
|
!isSource(d)) continue;
|
||||||
String cs = String.valueOf(c) + d;
|
String cs = String.valueOf(c) + d;
|
||||||
//if (showProgress && (count++ % 1000) == 0) {
|
String targ = sourceToTarget.transliterate(cs);
|
||||||
// log.logln(count + ": " + TestUtility.hex(cs));
|
if (!isReceivingTarget(targ)) {
|
||||||
//}
|
logWrongScript("Source-Target", cs, targ);
|
||||||
String targ = sourceToTarget.transliterate(cs);
|
}
|
||||||
if (!isReceivingTarget(targ)) {
|
|
||||||
out.println("<TR><TD>Fail Source-Target: " + cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")</TR></TD>");
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (showSuccess) {
|
|
||||||
out.println(c + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.logln("Checking that target characters convert to source and back - Singles");
|
log.logln("Checking that target characters convert to source and back - Singles");
|
||||||
count = 0;
|
|
||||||
|
|
||||||
for (char c = 0; c < 0xFFFF; ++c) {
|
for (char c = 0; c < 0xFFFF; ++c) {
|
||||||
if (Character.getType(c) == Character.UNASSIGNED) continue;
|
if (Character.getType(c) == Character.UNASSIGNED ||
|
||||||
if (!isTarget(c)) continue;
|
!isTarget(c)) continue;
|
||||||
//if (showProgress && (count++ % 100) == 0) {
|
String cs = String.valueOf(c);
|
||||||
// log.logln(count + ": " + TestUtility.hex(c));
|
|
||||||
//}
|
|
||||||
String cs = String.valueOf(c);
|
|
||||||
if (c > 0x0400) {
|
|
||||||
cs = cs + "";
|
|
||||||
}
|
|
||||||
String targ = targetToSource.transliterate(cs);
|
|
||||||
String reverse = sourceToTarget.transliterate(targ);
|
|
||||||
if (!isReceivingSource(targ)) {
|
|
||||||
out.println("<TR><TD>Fail Target-Source: " + cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")</TR></TD>" );
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (!cs.equals(reverse)) {
|
|
||||||
out.println("<TR><TD>Fail Roundtrip:</TD><TD><FONT SIZE=\"6\">" +
|
|
||||||
cs + "</FONT></TD><TD>(" +
|
|
||||||
TestUtility.hex(cs) + ") =></TD><TD>" +
|
|
||||||
targ + "</TD><TD>(" +
|
|
||||||
TestUtility.hex(targ) + ") =></TD><TD><FONT SIZE=\"6\">" +
|
|
||||||
reverse + "</TD><TD>(" +
|
|
||||||
TestUtility.hex(reverse) + ")</TD></TR>" );
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (showSuccess) {
|
|
||||||
out.println(cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")"
|
|
||||||
+ " => " + reverse + "(" + TestUtility.hex(reverse) + ")" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.logln("Checking that target characters convert to source and back - Doubles");
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
StringBuffer buf = new StringBuffer("aa");
|
|
||||||
for (char c = 0; c < 0xFFFF; ++c) {
|
|
||||||
if (Character.getType(c) == Character.UNASSIGNED) continue;
|
|
||||||
if (!isTarget(c)) continue;
|
|
||||||
if (++count > pairLimit) {
|
|
||||||
out.println("<TR><TD>Test truncated at " + pairLimit + " x 64k pairs</TR></TD>");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buf.setCharAt(0, c);
|
|
||||||
if (showProgress) { // && (count++ % 10000) == 0) {
|
|
||||||
log.log(TestUtility.hex(c));
|
|
||||||
// count + ": " + TestUtility.hex(cs));
|
|
||||||
}
|
|
||||||
for (char d = 0; d < 0xFFFF; ++d) {
|
|
||||||
if (Character.getType(d) == Character.UNASSIGNED) continue;
|
|
||||||
if (!isTarget(d)) continue;
|
|
||||||
buf.setCharAt(1, d);
|
|
||||||
String cs = buf.toString();
|
|
||||||
String targ = targetToSource.transliterate(cs);
|
String targ = targetToSource.transliterate(cs);
|
||||||
String reverse = sourceToTarget.transliterate(targ);
|
String reverse = sourceToTarget.transliterate(targ);
|
||||||
if (!isReceivingSource(targ)) {
|
if (!isReceivingSource(targ)) {
|
||||||
out.println("<TR><TD>Fail Target-Source: " + cs + "(" + TestUtility.hex(cs) + ")"
|
logWrongScript("Target-Source", cs, targ);
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")</TR></TD>" );
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (!cs.equals(reverse)) {
|
} else if (!cs.equals(reverse)) {
|
||||||
out.println("<TR><TD>Fail Roundtrip:</TD><TD><FONT SIZE=\"6\">" +
|
logRoundTripFailure(cs, targ, reverse);
|
||||||
cs + "</FONT></TD><TD>(" +
|
|
||||||
TestUtility.hex(cs) + ") =></TD><TD>" +
|
|
||||||
targ + "</TD><TD>(" +
|
|
||||||
TestUtility.hex(targ) + ") =></TD><TD><FONT SIZE=\"6\">" +
|
|
||||||
reverse + "</TD><TD>(" +
|
|
||||||
TestUtility.hex(reverse) + ")</TD></TR>" );
|
|
||||||
if (++errorCount > errorLimit) return;
|
|
||||||
} else if (showSuccess) {
|
|
||||||
out.println(cs + "(" + TestUtility.hex(cs) + ")"
|
|
||||||
+ " => " + targ + "(" + TestUtility.hex(targ) + ")"
|
|
||||||
+ " => " + reverse + "(" + TestUtility.hex(reverse) + ")" );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (showProgress) log.logln("");
|
|
||||||
|
log.logln("Checking that target characters convert to source and back - Doubles");
|
||||||
|
int count = 0;
|
||||||
|
StringBuffer buf = new StringBuffer("aa");
|
||||||
|
for (char c = 0; c < 0xFFFF; ++c) {
|
||||||
|
if (Character.getType(c) == Character.UNASSIGNED ||
|
||||||
|
!isTarget(c)) continue;
|
||||||
|
if (++count > pairLimit) {
|
||||||
|
throw new TestTruncated("Test truncated at " + pairLimit + " x 64k pairs");
|
||||||
|
}
|
||||||
|
buf.setCharAt(0, c);
|
||||||
|
log.log(TestUtility.hex(c));
|
||||||
|
for (char d = 0; d < 0xFFFF; ++d) {
|
||||||
|
if (Character.getType(d) == Character.UNASSIGNED ||
|
||||||
|
!isTarget(d)) continue;
|
||||||
|
buf.setCharAt(1, d);
|
||||||
|
String cs = buf.toString();
|
||||||
|
String targ = targetToSource.transliterate(cs);
|
||||||
|
String reverse = sourceToTarget.transliterate(targ);
|
||||||
|
if (!isReceivingSource(targ)) {
|
||||||
|
logWrongScript("Target-Source", cs, targ);
|
||||||
|
} else if (!cs.equals(reverse)) {
|
||||||
|
logRoundTripFailure(cs, targ, reverse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.logln("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
final void logWrongScript(String label, String from, String to) {
|
||||||
* Characters to filter for source-target mapping completeness
|
out.println("<TR><TD>Fail " + label + ":</TD><TD><FONT SIZE=\"6\">" +
|
||||||
* Typically is base alphabet, minus extended characters
|
from + "</FONT></TD><TD>(" +
|
||||||
* Default is ASCII letters for Latin
|
TestUtility.hex(from) + ") =></TD><TD><FONT SIZE=\"6\">" +
|
||||||
*/
|
to + "</FONT></TD><TD>(" +
|
||||||
public boolean isSource(char c) {
|
TestUtility.hex(to) + ")</TD></TR>" );
|
||||||
byte script = TestUtility.getScript(c);
|
if (++errorCount >= errorLimit) {
|
||||||
if (script != sourceScript) return false;
|
throw new TestTruncated("Test truncated; too many failures");
|
||||||
if (!Character.isLetter(c)) return false;
|
}
|
||||||
if (!sourceRange.contains(c)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Characters to check for target back to source mapping.
|
|
||||||
* Typically the same as the target script, plus punctuation
|
|
||||||
*/
|
|
||||||
public boolean isReceivingSource(char c) {
|
|
||||||
byte script = TestUtility.getScript(c);
|
|
||||||
return (script == sourceScript || script == TestUtility.COMMON_SCRIPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Characters to filter for target-source mapping
|
|
||||||
* Typically is base alphabet, minus extended characters
|
|
||||||
*/
|
|
||||||
public boolean isTarget(char c) {
|
|
||||||
byte script = TestUtility.getScript(c);
|
|
||||||
if (script != targetScript) return false;
|
|
||||||
if (!Character.isLetter(c)) return false;
|
|
||||||
if (targetRange != null && !targetRange.contains(c)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Characters to check for target-source mapping
|
|
||||||
* Typically the same as the source script, plus punctuation
|
|
||||||
*/
|
|
||||||
public boolean isReceivingTarget(char c) {
|
|
||||||
byte script = TestUtility.getScript(c);
|
|
||||||
return (script == targetScript || script == TestUtility.COMMON_SCRIPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final boolean isSource(String s) {
|
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
|
||||||
if (!isSource(s.charAt(i))) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean isTarget(String s) {
|
final void logRoundTripFailure(String from, String to, String back) {
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
out.println("<TR><TD>Fail Roundtrip:</TD><TD><FONT SIZE=\"6\">" +
|
||||||
if (!isTarget(s.charAt(i))) return false;
|
from + "</FONT></TD><TD>(" +
|
||||||
|
TestUtility.hex(from) + ") =></TD><TD>" +
|
||||||
|
to + "</TD><TD>(" +
|
||||||
|
TestUtility.hex(to) + ") =></TD><TD><FONT SIZE=\"6\">" +
|
||||||
|
back + "</TD><TD>(" +
|
||||||
|
TestUtility.hex(back) + ")</TD></TR>" );
|
||||||
|
if (++errorCount >= errorLimit) {
|
||||||
|
throw new TestTruncated("Test truncated; too many failures");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean isReceivingSource(String s) {
|
/*
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
* Characters to filter for source-target mapping completeness
|
||||||
if (!isReceivingSource(s.charAt(i))) return false;
|
* Typically is base alphabet, minus extended characters
|
||||||
|
* Default is ASCII letters for Latin
|
||||||
|
*/
|
||||||
|
public boolean isSource(char c) {
|
||||||
|
byte script = TestUtility.getScript(c);
|
||||||
|
if (script != sourceScript) return false;
|
||||||
|
if (!Character.isLetter(c)) return false;
|
||||||
|
if (!sourceRange.contains(c)) return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean isReceivingTarget(String s) {
|
/*
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
* Characters to check for target back to source mapping.
|
||||||
if (!isReceivingTarget(s.charAt(i))) return false;
|
* Typically the same as the target script, plus punctuation
|
||||||
|
*/
|
||||||
|
public boolean isReceivingSource(char c) {
|
||||||
|
byte script = TestUtility.getScript(c);
|
||||||
|
return (script == sourceScript || script == TestUtility.COMMON_SCRIPT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters to filter for target-source mapping
|
||||||
|
* Typically is base alphabet, minus extended characters
|
||||||
|
*/
|
||||||
|
public boolean isTarget(char c) {
|
||||||
|
byte script = TestUtility.getScript(c);
|
||||||
|
if (script != targetScript) return false;
|
||||||
|
if (!Character.isLetter(c)) return false;
|
||||||
|
if (targetRange != null && !targetRange.contains(c)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Characters to check for target-source mapping
|
||||||
|
* Typically the same as the source script, plus punctuation
|
||||||
|
*/
|
||||||
|
public boolean isReceivingTarget(char c) {
|
||||||
|
byte script = TestUtility.getScript(c);
|
||||||
|
return (script == targetScript || script == TestUtility.COMMON_SCRIPT);
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isSource(String s) {
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isSource(s.charAt(i))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isTarget(String s) {
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isTarget(s.charAt(i))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isReceivingSource(String s) {
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isReceivingSource(s.charAt(i))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isReceivingTarget(String s) {
|
||||||
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
|
if (!isReceivingTarget(s.charAt(i))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TestTruncated extends RuntimeException {
|
||||||
|
TestTruncated(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestHangul extends Test {
|
static class TestHangul extends Test {
|
||||||
|
Loading…
Reference in New Issue
Block a user