/* * boardTest.java * JUnit based tests for my TicTacToe game * Written for Jim's Programming Workshop, * Spring, 2006 * * The basic structure comes from Jim's in-class * JUnit examples, and the JUnit FAQs * * * Created on February 18, 2006, 7:46 PM * * $ID$ * */ import junit.framework.*; import java.util.*; /** *A testing suite for a TicTacToe game. * * * * @author dgg */ public class boardTest extends TestCase { public boardTest(String name) { super(name); } //private variables for use by multiple tests private board my_board; private String[][] threeByThree = new String[3][3]; private String[][] winBoard = {{"X","O","X"},{"O","X","X"},{"X","O","O"}}; private String myTurn = "X"; protected void setUp() throws Exception { my_board = new board(); my_board.turn = "X"; } protected void tearDown() throws Exception { } public static Test suite() { return new TestSuite(boardTest.class); } /**Allows us to run tests from the comand line by calling this class directly.*/ public static void main(String args[]){ junit.textui.TestRunner.run(suite()); } /**Makes sure that the board object being returned is of the expected length*/ public void testBoardReturnSize(){ assertEquals(my_board.currentBoard.length,threeByThree.length); } /**Makes sure that board.move is placing the correct mark in the correct place*/ public void testMove(){ my_board.move(1,1); assertEquals("O",my_board.currentBoard[1][1]); } /**Makes sure turns are rotating properly*/ public void testNextTurn(){ my_board.nextTurn(); assertEquals("O",my_board.turn); } /**Make sure we're right about who's turn it is*/ public void testTurns(){ assertEquals(myTurn,my_board.whosTurn()); } /**Make sure the board object is returning what we expect it to.*/ public void testBoardReturn(){ threeByThree[1][1] = "O"; my_board.move(1,1); threeByThree[2][0] = "X"; my_board.move(2,0); threeByThree[0][0] = "O"; my_board.move(0,0); threeByThree[0][1] = "X"; my_board.move(0,1); int i; int j; for (i=0;i<3;i++){ for (j=0;j<3;j++){ assertEquals(threeByThree[i][j],my_board.currentBoard[i][j]); } } } }