/* * TestSimpleGameKeeper.java * * Created on June 22, 2003, 12:44 AM */ package gamekeeper2a; /** Test cases for two types of game keepers. * */ public class TestTwoGamekeepers { /** Run a test case. *Two different game keepers are tested in parallel. *Probably somewhat confusing... * @return true if the test succeeds, false if it fails. */ static void testCase1() { IRecordkeeper bbkeeper = new BaseballGamekeeper(); IRecordkeeper golfkeeper = new GolfGamekeeper(); String case1 = "Mike Tyson 98, Tanya Harding 77"; bbkeeper.acceptGameResults(case1); golfkeeper.acceptGameResults(case1); String case2 = "Tanya Harding 30, Pelle 29"; bbkeeper.acceptGameResults(case2); golfkeeper.acceptGameResults(case2); IContestant th1 = bbkeeper.findContestant(" Tanya Harding "); System.out.println(th1); IContestant th2 = golfkeeper.findContestant("Tanya Harding"); System.out.println(th2); System.out.println(th2.getName() + " " + th2.getGamesLost()); } /** Run a test case. *Two different game keepers are tested in parallel. *Probably somewhat confusing... * @return true if the test succeeds, false if it fails. */ static void testCase2() { IRecordkeeper bbkeeper = new BaseballGamekeeper(); IRecordkeeper golfkeeper = new GolfGamekeeper(); String case1 = "Mike Tyson 28, Tanya Harding 27"; String case2 = "Tyler Durden 11, Pelle 2"; String case3 = "Hepburn 1, Tracy 0"; String case4 = "U.W. 90, W.S.U. 2"; String case5 = "U.W. 3, U.W. 4"; String case6 = " Mike Tyson 3, Pelle 0005"; String[] cases = new String[] {case1, case2, case3, case4, case5, case6}; for (int c = 0; c < cases.length; c++) { //try each case with each game keeper bbkeeper.acceptGameResults(cases[c]); golfkeeper.acceptGameResults(cases[c]); System.out.println("Baseball results after " + cases[c] + ":"); GameUtilities.printArray(bbkeeper.listContestantResults()); System.out.println("Golf results after " + cases[c] + ":"); GameUtilities.printArray(golfkeeper.listContestantResults()); } bbkeeper.acceptGameResults("Pelle ", 1, " U.W.", -1); golfkeeper.acceptGameResults("Pelle ", 1, " U.W.", -1); System.out.println("Final Baseball results:"); GameUtilities.printArray(bbkeeper.listContestantResults()); System.out.println("Final Baseball results again:"); GameUtilities.printArray(bbkeeper.listContestants()); System.out.println("Final Golf results:"); GameUtilities.printArray(golfkeeper.listContestantResults()); System.out.println("Final Golf results again:"); GameUtilities.printArray(golfkeeper.listContestants()); } /** Run the test cases contained in this file. */ public static void main(String[] args) { testCase1(); testCase2(); } }