Skip to content

Instantly share code, notes, and snippets.

@tarynsauer
Created January 12, 2014 21:58
Show Gist options
  • Save tarynsauer/8391159 to your computer and use it in GitHub Desktop.
Save tarynsauer/8391159 to your computer and use it in GitHub Desktop.
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.ArrayList;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
public class BoardTest {
private Board board;
@Before
public void setUp() {
board = new Board();
}
@Test
public void testInitializesCells() {
assertEquals("2", board.getCells()[1]);
}
@Test
public void testIsAvailableReturnsTrueWhenAvailable() {
for(int i = 0; i <= 7; i++) {
board.getCells()[i] = "X";
}
assertTrue(board.hasAvailableCell());
}
@Test
public void testGetRandomCellDoesNotReturnUnavailableCell() {
String cellID = board.getRandomCell();
board.getCells()[0] = "X";
assertThat(cellID, not("1"));
}
@Test
public void testGetRandomCellReturnsTheOnlyOpenCell() {
board.getCells()[0] = "X";
board.getCells()[1] = "O";
board.getCells()[2] = "X";
board.getCells()[3] = "X";
board.getCells()[4] = "O";
board.getCells()[5] = "X";
board.getCells()[6] = "O";
board.getCells()[7] = "O";
String cellID = board.getRandomCell();
assertEquals("9", cellID);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment