/** Test cases for Assignment 4, CS 146, Spring 2002. Here, four different implementations of the Lexicographical interface are used, and three different lexicographically based sorting algorithms are applied to arrays of each type. */ import java.util.*; public class A4 { /** @return a random string of lower case characters, of random length from 3 through 9. */ // The string is constructed by taking characters // randomly and uniformly chosen from the alphabet. // Since the method to get the size of the alphabet // can't be both static and part of the Lexicographical // interface, we instantiate a dummy TrieString from // which we can get this size. // Here we use the property of TrieStrings that the // alphabet is the same for each character position. public static TrieString makeRandomTrieString(Random r) { int len=3+r.nextInt(7); TrieString ts=new TrieString(""); int alphabetSize = ts.getAlphabetSize(); StringBuffer s=new StringBuffer(len); for (int i=0; i<=len; i++) s.append((char) ((int)'a' + r.nextInt( ts.getAlphabetSize()-1))); return new TrieString(new String(s)); } public static void main(String[] args) { TrieString ts=new TrieString(""); // These objects are needed only to get the // alphabet size for their class, as in // the makeRandomTrieString method. // As in that method, we rely on the fact // that the underlying alphabet is the same // for each position, for each of the 3 classes TrieInteger ti= new TrieInteger(0,4); TrieIntegerString tis= new TrieIntegerString(0); TriColor tc=new TriColor(); // Create an empty trie for each class Trie t= new Trie(ts.getAlphabetSize()); Trie t2= new Trie(ti.getAlphabetSize()); Trie t3= new Trie(tis.getAlphabetSize()); Trie t4= new Trie(tc.getAlphabetSize()); // Create a random array for each class java.util.Random r=new java.util.Random(1); Lexicographical[] a=new Lexicographical[100]; Lexicographical[] b=new Lexicographical[100]; Lexicographical[] c=new Lexicographical[100]; Lexicographical[] d=new Lexicographical[100]; for (int i=0; i