import java.util.*;
import java.io.*;

/**
 * This tests version 1.0 of the wordList class.
 * It inserts all the 5-letter words from words.dat into the hash table
 * and then searches for them.
 * It also reports some statistics on the number of probes performed.
 * This is an important indicator of how efficient the date structure is.
 *
 * @author: Sriram Pemmaraju
 * @date Nove 13th, 2008
*/

public class wordListTester{

	public static void main(String args[])
	{
		String[] wordList;
		
		// Defines a wordList object that is expected to store about 5,800 words,
		// which is the number of words in words.dat
		wordList T = new wordList(5800);
		
		try
		{
			// This is one way to read from a file. The list of all 5-letter words
			// is in a file called words.dat
			BufferedReader in = new BufferedReader(new FileReader("words.dat"));
			String word;

        		// read all the words from the file                
			System.out.println( "Reading words.dat..." );
			while( (word = in.readLine()) != null )
			{
				// insert this word into the word list class
				T.insert( word );

			}
			in.close();

			System.out.println("Number of words in wordList is " + T.numberWords());
			System.out.println("Average number of probes per word insertion " + T.averageNumberOfProbes());
			
			System.out.println("Testing wordList insert and search.");
			System.out.println("Expect to find the first 10 words and then not find the next 10 words.");

			String[] searchWords = {"hello", "abode", "zebra", "seize", "blaze", "catch", "merge", "felon", "claim", "chain",
                                                "mansion", "cow", "bricklayer", "at", "energy", "man", "New York", "1234", "Jujitsu", "critical"};
			for(int i = 0; i < searchWords.length; i++)
			{
				System.out.print(i+1);
				if(T.search(searchWords[i]))
					System.out.println(" Found " + searchWords[i]);
				else
					System.out.println(" Not found " + searchWords[i]);
			}

		}
		catch (IOException e) {}
	}

}
