2 * Copyright 2001 Sun Microsystems, Inc.
4 * See the file "license.terms" for information on usage and
5 * redistribution of this file, and for a DISCLAIMER OF ALL
9 import junit.framework.*;
13 import com.sun.speech.freetts.*;
14 import com.sun.speech.freetts.lexicon.LetterToSound;
15 import com.sun.speech.freetts.lexicon.LetterToSoundImpl;
18 * Provides junit tests for the LetterToSound class
22 public class LetterToSoundTest extends TestCase {
23 BufferedReader reader = null;
24 LetterToSound lts = null;
27 * Creates the set of LetterToSoundTest
29 * @param name the name of the test.
31 public LetterToSoundTest(String name) {
37 * Common code run before each test
39 protected void setUp() {
41 lts = new LetterToSoundImpl(
42 new URL("file:../bld/classes/com/sun/speech/freetts/en/us/cmulex_lts.bin"), true);
43 assertTrue("LTS Rules created", lts != null);
44 reader = new BufferedReader(new FileReader("LTS.txt"));
45 assertTrue("Data File opened", reader != null);
46 } catch (IOException e) {
53 * Common code run after each test
55 protected void tearDown() {
60 * Tests to see that we succeed
62 public void testSuccess() {
63 assertTrue("Should succeed", true);
68 * Tests that LTS generated match those from the standard results.
70 public void testLTS() {
74 String[] lts_phone_array;
75 StringBuffer lts_phones;
78 while ((line = reader.readLine()) != null) {
79 if (line.startsWith("***")) {
82 i = line.indexOf(' ');
83 word = line.substring(0,i);
84 flite_phones = line.substring(i+1);
85 lts_phone_array = lts.getPhones(word, null);
86 assertTrue("Phones returned for " + word + " is not null: ",
87 lts_phone_array != null);
88 lts_phones = new StringBuffer("(");
89 for (i = 0; i < lts_phone_array.length; i++) {
91 lts_phones.append(" ");
93 lts_phones.append(lts_phone_array[i]);
95 lts_phones.append(")");
96 assertTrue("Phones returned for " + word + " are identical "
97 + "(Our phones: " + lts_phones + ", "
98 + "Flite phones: " + flite_phones + "): ",
99 flite_phones.equals(lts_phones.toString()));
101 } catch (IOException e) {
102 assertTrue("FILE IO problem: ", false);
107 * Tests to see if the binary version of the database matches
108 * that of the text database.
109 public void testBinaryLoad() {
111 LetterToSoundImpl text = new LetterToSoundImpl(
112 new URL("file:../en/us/cmulex_lts.txt"), false);
113 LetterToSoundImpl binary = new LetterToSoundImpl(
114 new URL("file:../en/us/cmulex_lts.bin"), true);
116 assertTrue("text binary compare", text.compare(binary));
117 } catch (IOException ioe) {
118 fail("Can't load lts " + ioe);
123 * Factory method that creates the test suite.
125 * @return the test suite.
127 public static Test suite() {
128 return new TestSuite(LetterToSoundTest.class);
134 * Main entry point for this test suite.
136 * @param args the command line arguments.
138 public static void main(String[] args) {
139 junit.textui.TestRunner.run(suite());