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.*;
12 import com.sun.speech.freetts.*;
13 import com.sun.speech.freetts.lexicon.Lexicon;
14 import com.sun.speech.freetts.en.us.CMULexicon;
17 * JUnit tests Tests for the LexiconTest class
21 public class LexiconTest extends TestCase {
22 BufferedReader reader = null;
26 * Creates the set of LexiconTest
28 * @param name the name of the test.
30 public LexiconTest(String name) {
36 * Common code run before each test
38 protected void setUp() {
40 lex = CMULexicon.getInstance(true);
41 assertTrue("Lexicon Created", lex != null);
42 reader = new BufferedReader(new FileReader("LEX.txt"));
43 assertTrue("Data File opened", reader != null);
44 } catch (IOException e) {
51 * Common code run after each test
53 protected void tearDown() {
58 * Tests to see that we succeed
60 public void testSuccess() {
61 assertTrue("Should succeed", true);
66 * Tests that Lexicon matches those from the standard results.
68 public void testLexicon() {
73 String[] lex_phone_array;
74 StringBuffer lex_phones;
77 while ((line = reader.readLine()) != null) {
78 if (line.startsWith("***")) {
81 i = line.indexOf(' ');
82 word = line.substring(0,i);
83 line = line.substring(i+1);
84 i = line.indexOf(' ');
85 pos = line.substring(0,i);
86 flite_phones = line.substring(i+1);
87 lex_phone_array = lex.getPhones(word, pos);
88 assertTrue("Phones returned for " + word + pos
90 lex_phone_array != null);
91 lex_phones = new StringBuffer("(");
92 for (i = 0; i < lex_phone_array.length; i++) {
94 lex_phones.append(" ");
96 lex_phones.append(lex_phone_array[i]);
98 lex_phones.append(")");
99 assertTrue("Phones returned for " + word + pos
101 + "(Our phones: " + lex_phones + ", "
102 + "Flite phones: " + flite_phones + "): ",
103 flite_phones.equals(lex_phones.toString()));
105 } catch (IOException e) {
106 assertTrue("FILE IO problem: ", false);
111 * Factory method that creates the test suite.
113 * @return the test suite.
115 public static Test suite() {
116 return new TestSuite(LexiconTest.class);
122 * Main entry point for this test suite.
124 * @param args the command line arguments.
126 public static void main(String[] args) {
127 junit.textui.TestRunner.run(suite());