Skip to content

Commit

Permalink
Add compatibility test for Java. Rename zawgyi output files
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-oly committed Aug 8, 2018
1 parent 67c580e commit 1322916
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ copy-resources:
cp genconvert/input/udhr_mya_unicode_src.txt clients/java/src/test/resources/com/google/myanmartools
cp genconvert/output/mmgov_unicode_out.txt clients/java/src/test/resources/com/google/myanmartools
cp genconvert/output/mmgov_unicode_out.txt clients/js/resources
cp genconvert/output/udhr_mya_zawygyi_out.txt clients/java/src/test/resources/com/google/myanmartools
cp genconvert/output/udhr_mya_zawygyi_out.txt clients/js/resources
cp genconvert/output/udhr_mya_zawgyi_out.txt clients/java/src/test/resources/com/google/myanmartools
cp genconvert/output/udhr_mya_zawgyi_out.txt clients/js/resources

train: zawgyiUnicodeModel.dat compatibility.tsv testData.tsv copy-resources

Expand All @@ -81,7 +81,7 @@ transcompile: transcompile-norm transcompile-Z2U transcompile-U2Z
transliterate-compatibility: compatU2Z compatZ2U

compatU2Z:
$(MVN) -f genconvert/pom.xml -q -e exec:java -Dexec.mainClass=com.google.myanmartools.TransliterateFile -Dexec.args="genconvert/input/my-t-my-d0-zawgyi.txt genconvert/input/udhr_mya_unicode_src.txt genconvert/output/udhr_mya_zawygyi_out.txt"
$(MVN) -f genconvert/pom.xml -q -e exec:java -Dexec.mainClass=com.google.myanmartools.TransliterateFile -Dexec.args="genconvert/input/my-t-my-d0-zawgyi.txt genconvert/input/udhr_mya_unicode_src.txt genconvert/output/udhr_mya_zawgyi_out.txt"

compatZ2U:
$(MVN) -f genconvert/pom.xml -q -e exec:java -Dexec.mainClass=com.google.myanmartools.TransliterateFile -Dexec.args="genconvert/input/my-t-my-s0-zawgyi.txt genconvert/input/mmgov_zawgyi_src.txt genconvert/output/mmgov_unicode_out.txt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@

import static com.google.common.truth.Truth.assertWithMessage;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -642,11 +654,6 @@ public class TransliterateTest {

@BeforeClass
public static void setup() {
/*
System.out.println("zNorm: " + zNorm.printAll());
System.out.println("Z-->U :" + z2U.printAll());
System.out.println("U-->Z: " + u2Z.printAll());
*/
}

// Service function to get hex values.
Expand Down Expand Up @@ -761,4 +768,69 @@ public void u2ZTests() {
}
}

@Test
/**
* Compatibility test for Z->U conversion using golden file.
*/
public void z2UCompatibilityTest() {
String fileInputPath = "src/test/resources/com/google/myanmartools/mmgov_zawgyi_src.txt";
String goldenInputPath = "src/test/resources/com/google/myanmartools/mmgov_unicode_out.txt";

// Open input files.
try {
BufferedReader input = Files.newBufferedReader(Paths.get(fileInputPath), UTF_8);
BufferedReader golden = Files.newBufferedReader(Paths.get(goldenInputPath), UTF_8);

int lineNum = 0;
String zLine = input.readLine();
while (zLine != null) {
String convertedLine = z2U.convert(zLine);
String goldenLine = golden.readLine();
assertWithMessage(
"Difference in line " + lineNum + "\n" +
" expected = " + goldenLine + "\n" +
" actual = " + convertedLine + "\n").
that(convertedLine).isEqualTo(goldenLine);
zLine = input.readLine();
lineNum ++;
}
}
catch (IOException ex) {
org.junit.Assert.fail("** Error in file open/read in z2UCompatibiityTest: " + ex.getMessage());
}
}

@Test
/**
* Compatibility test for U->Z conversion using golden file.
* Note that normalization of Zawgyi is needed for comparison.
*/
public void u2ZCompatibilityTest() {
String fileInputPath = "src/test/resources/com/google/myanmartools/udhr_mya_unicode_src.txt";
String goldenInputPath = "src/test/resources/com/google/myanmartools/udhr_mya_zawgyi_out.txt";

// Open input files.
try {
BufferedReader input = Files.newBufferedReader(Paths.get(fileInputPath), UTF_8);
BufferedReader golden = Files.newBufferedReader(Paths.get(goldenInputPath), UTF_8);

int lineNum = 0;
String uLine = input.readLine();
while (uLine != null) {
String convertedLine = zNorm.convert(u2Z.convert(uLine));
String goldenLine = zNorm.convert(golden.readLine());
assertWithMessage(
"Difference in line " + lineNum + "\n" +
" expected = " + goldenLine + "\n" +
" actual = " + convertedLine + "\n").
that(convertedLine).isEqualTo(goldenLine);
uLine = input.readLine();
lineNum ++;
}
}
catch (IOException ex) {
org.junit.Assert.fail("** Error in file open/read in z2UCompatibiityTest: " + ex.getMessage());
}
}

}
File renamed without changes.

0 comments on commit 1322916

Please sign in to comment.