// Test driver for the CrosswordBoard class class TestBoard { private static CrosswordBoard the_board; // The board used for testing private static final String ACROSS = "ACROSS"; private static final String DOWN = "DOWN"; // To simplify testing, we create a wrapper in the driver for calling // the placeWord methods for a board. It just reports the success or // failure of placing a word on the board created by the test driver. public static void placeWord(String s, int row, int col, String dir) { System.out.print("Placing \"" + s + "\" " + dir + " at (" + row + "," + col + "):"); boolean success = (dir == ACROSS ? the_board.placeWordAcross(s, row, col) : the_board.placeWordDown(s, row, col) ); System.out.println(success ? " Succeeded" : " Failed"); } public static void main(String args[] ) { System.out.println("---- Test 1, empty 3x3 board ----"); the_board = new CrosswordBoard(3,3); System.out.println(the_board); // Expect: // *** // *** // *** System.out.println("---- Test 2, filling 3x3 board ---"); placeWord("foo", 0, 0, ACROSS); // succeed placeWord("bar", 0, 0, DOWN); // fail placeWord("oop", 0, 2, DOWN); // succeed placeWord("oop", 2, 0, ACROSS); // succeed // Expect: // foo // **o // oop System.out.println(the_board.toString()); System.out.println("---- Test 3, filling 5x4 board ---"); the_board = new CrosswordBoard(5,4); placeWord("prof", 0, 0, ACROSS); // succeed placeWord("bar", 0, 0, DOWN); // fail placeWord("rag", 0, 1, DOWN); // succeed placeWord("phone", 0, 0, DOWN); // succeed placeWord("frets", 0, 3, DOWN); // succeed placeWord("hair", 1, 0, ACROSS); // succeed placeWord("hairy", 1, 0, ACROSS); // fail placeWord("hair", 3, 0, ACROSS); // fail placeWord("oil", 0, 2, DOWN); // succeed placeWord("eats", 4, 0, ACROSS); // succeed // Expect: // prof // hair // ogle // n**t // eats System.out.println(the_board); } }