public class PublicTest { private static int numerrors = 0; private static int numcorrect = 0; private static void check (boolean result) { if (result) { System.out.println (" OK"); numcorrect++; } else { System.out.println (" ERROR!"); numerrors++; } } public static void main(String[] args) { try { System.out.println ("Constructing a new WordTally..."); WordTally tally = new WordTally (); System.out.println ("Checking number of words..."); check (tally.numberOfWords () == 0); System.out.println ("tallyWord(\"Marmoset\")"); tally.tallyWord("Marmoset"); System.out.println ("Checking number of words..."); check (tally.numberOfWords () == 1); System.out.println ("tallyWord(\"Marmoset\")"); tally.tallyWord("Marmoset"); System.out.println ("Checking number of words..."); check (tally.numberOfWords () == 1); System.out.println ("Tallying lots of words..."); tally.tallyWord("Sewage"); tally.tallyWord("Sewage"); tally.tallyWord("Sewage"); tally.tallyWord("Donut"); tally.tallyWord("Donut"); tally.tallyWord("Frisbee"); tally.tallyWord("Pizza"); tally.tallyWord("Sofabed"); tally.tallyWord("Sofabed"); tally.tallyWord("Homestar"); tally.tallyWord("Frisbee"); tally.tallyWord("Donut"); tally.tallyWord("Olorin"); tally.tallyWord("Erchamion"); System.out.println ("Checking number of words..."); check (tally.numberOfWords () == 9); System.out.println ("Checking getTally..."); check (tally.getTally ("Donut") == 3); check (tally.getTally ("Erchamion") == 1); check (tally.getTally ("NotAWord") == 0); System.out.println ("Checking resetWord..."); tally.resetWord("Donut"); check (tally.getTally ("Donut") == 0); System.out.println ("Checking number of words..."); check (tally.numberOfWords () == 8); System.out.println ("Checking getRankedWord..."); check (tally.getRankedWord (1).equals ("Sewage")); check (tally.getRankedWord (4).equals ("Sofabed")); check (tally.getRankedWord (5).equals ("Erchamion")); check (tally.getRankedWord (8).equals ("Pizza")); if (numerrors == 0) { System.out.println ("Congratulations! Passed all public test cases."); } else { System.out.println ("Passed " + numcorrect + " tests. Failed " + numerrors + " tests."); } } catch (Exception e) { System.out.println ("Exception: " + e); System.out.println ("Terminating testing."); } } }