DictionaryTestDriver
/**
* This aplication tests students' Dictionary.java files, Exercise 1.
*
* @author Sam Harbison
* @version September 8, 2002
*/
public class DictionaryTestDriver {
private static Dictionary dictionary;
private static String[] wordList = {"alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel",
"india", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romeo",
"sierra", "tango", "uniform", "victor", "whiskey", "xray", "yankee", "zulu" };
private static String badWordList[] = {"Not in the dictionary", wordList[0].toUpperCase() };
public static void main (String[] args) {
boolean foundErrors = false;
dictionary = new Dictionary();
for(int i = 0; i < wordList.length; i++) {
dictionary.addWord(wordList[i]);
}
for(int i = 0; i < wordList.length; i++) {
if (!dictionary.checkWord(wordList[i])) {
System.err.println("Could not find word: " + wordList[i]);
foundErrors = true;
}
}
for (int i = 0; i < badWordList.length; i++) {
if (dictionary.checkWord(badWordList[i])) {
System.err.println("Found word " + badWordList[i] + ", which should not be in dictionary.");
foundErrors = true;
}
}
if (foundErrors) {
System.err.println("*** Test failed.");
}
else {
System.err.println("All tests passed.");
}
}
}