/* * TestProject1.java * - inspired by Test1SimpleGameKeeper.java by Martin Dickey * * @author David Tran * @version 1.0 * * Created on June 27, 2003, 1:58 PM * Last modified June 27, 2003 2:00 PM */ /** Test cases for the SimpleGamekeeper class. * PLEASE NOTE: You may have more or less test cases * than the ones mentioned here, due to * your specific implementation of this project. * As a result, SOME TESTS ARE OPTIONAL, and are noted as such. * CORRECT OUPUT FOR THIS IMPLEMENTATION: * Testing was a success! * e e cummings 2-0 * Robert Frost 2-2 * Friedrich Nietzsche 1-0 * Worst Poet Ever 0-3 */ public class TestProject1 { /** * HELPER METHOD * Print an array of any type of objects, one per line. */ private static void printArray(Object[] anyArray) { for (int line = 0; line < anyArray.length; line++) { System.out.println(anyArray[line].toString()); } } public static void main(String[] args) { IRecordkeeper gkeep = new SimpleGamekeeper(); String[] results; // Test rejection of null String names gkeep.acceptGameResults(null, 23, null, 20); gkeep.acceptGameResults("e e cummings", 23, null, 20); gkeep.acceptGameResults(null, 23, "e e cummings", 20); results = gkeep.listContestantResults(); if (results.length != 0) { System.out.println("Failure! List not empty after null names were given."); return; } // Test standard contestant entry gkeep.acceptGameResults(" e e cummings ", 23, " Robert Frost ", 20); results = gkeep.listContestantResults(); if (results.length != 2) { System.out.println("Failure! Contestant list not properly " + "maintained! There should be 2 entries, " + "but instead there are (is) " + results.length); return; } // Test trimming of white space gkeep.acceptGameResults("e e cummings", 1, "Robert Frost", 0); results = gkeep.listContestantResults(); if (results.length != 2) { System.out.println("Failure! White space not trimmed from " + "contestant names!"); return; } // Test if an invalid game involving only one contestant is recorded if ( gkeep.acceptGameResults("e e cummings", 20, " e e cummings ", 19) ) { System.out.println("Failure! e e cummings can't compete in a " + "game against himself..."); return; } else { results = gkeep.listContestantResults(); if (results.length != 2) { System.out.println("Failure! Contestant list not properly " + "maintained after an invalid match " + "involving one player! There should " + "be 2 entries, but instead " + "there are (is) " + results.length); return; } } gkeep.acceptGameResults("Friedrich Nietzsche", 20, "Worst Poet Ever", 0); for (int i = 0; i < 2; i++) { gkeep.acceptGameResults("Robert Frost", 7, "Worst Poet Ever", 0); } results = gkeep.listContestantResults(); if (results.length != 4) { System.out.println("Failure! Contestant list not properly maintained! " + "There should be 4 entries, " + "but instead there are (is) " + results.length); return; } System.out.println("Testing was a success!\nCurrent Standings:"); printArray(results); } }