import org.junit.Test; import static org.junit.Assert.assertEquals; /** * The test class TicTacToeBoardTest -- * it tests the TicTacToeBoard class * * @author Phill Conrad, and folks in the lecture * @version lecture for CS56, 05/10/2011 * @see TicTacToeBoard */ public class TicTacToeBoardTest { /** Test the constructor and toString */ @Test public void testConstructorAndToString() { TicTacToeBoard tttb = new TicTacToeBoard(); String expected = " | | \n" + "---+---+---\n" + " | | \n" + "---+---+---\n" + " | | \n"; assertEquals(expected,tttb.toString()); } /** Test the constructor and toString */ @Test public void playTwoMoves() { TicTacToeBoard tttb = new TicTacToeBoard(); tttb.move(4); // implicit whether x or o String expected = " | | \n" + "---+---+---\n" + " x | | \n" + "---+---+---\n" + " | | \n"; assertEquals(expected,tttb.toString()); // nobody won yet. Let's check if the method // returns that correctly assertFalse(tttb.someoneWon()); tttb.move(7); // implicit whether x or o String expected = " | | \n" + "---+---+---\n" + " x | | \n" + "---+---+---\n" + " o | | \n"; assertEquals(expected,tttb.toString()); assertFalse(tttb.someoneWon()); } /** Test the constructor and toString */ @Test public void gameWhereXIsDumb() { TicTacToeBoard tttb = new TicTacToeBoard(); tttb.move(4); // implicit whether x or o String expected = " | | \n" + "---+---+---\n" + " x | | \n" + "---+---+---\n" + " | | \n"; assertEquals(expected,tttb.toString()); // nobody won yet. Let's check if the method // returns that correctly assertFalse(tttb.someoneWon()); tttb.move(7); // implicit whether x or o String expected = " | | \n" + "---+---+---\n" + " x | | \n" + "---+---+---\n" + " o | | \n"; assertEquals(expected,tttb.toString()); assertFalse(tttb.someoneWon()); tttb.move(1); // implicit whether x or o String expected = " x | | \n" + "---+---+---\n" + " x | | \n" + "---+---+---\n" + " o | | \n"; assertEquals(expected,tttb.toString()); assertFalse(tttb.someoneWon()); tttb.move(5); // implicit whether x or o String expected = " x | | \n" + "---+---+---\n" + " x | o | \n" + "---+---+---\n" + " o | | \n"; assertEquals(expected,tttb.toString()); assertFalse(tttb.someoneWon()); tttb.move(2); // implicit whether x or o String expected = " x | x | \n" + "---+---+---\n" + " x | o | \n" + "---+---+---\n" + " o | | \n"; assertEquals(expected,tttb.toString()); assertFalse(tttb.someoneWon()); tttb.move(3); // implicit whether x or o String expected = " x | x | o \n" + "---+---+---\n" + " x | o | \n" + "---+---+---\n" + " o | | \n"; assertEquals(expected,tttb.toString()); assertTrue(tttb.someoneWon()); assertFalse(tttb.xWon()); assertTrue(tttb.oWon()); assertFalse(tttb.boardFull()); assertEquals(tttb.victory(), 2); assertNotEquals(tttb.victory(), 1); } }