assertEquals("cell had wrong initial state", CellState.DEAD, cell.getCellState());
}
public void testNumberOfNeighbors() {
Cell cell = grid.getCellAt(0, 0);
// corner cells should all have 3 neighbors
assertEquals("cell(0,0) had wrong number of neighbors", 3, cell.getNumberOfNeighboringCells());
cell = grid.getCellAt(0, COLUMNS - 1);
assertEquals("cell(0, COLUMNS-1) had wrong number of neighbors", 3, cell.getNumberOfNeighboringCells());
cell = grid.getCellAt(ROWS - 1, COLUMNS - 1);
assertEquals("cell(ROWS-1, COLUMNS-1) had wrong number of neighbors", 3, cell.getNumberOfNeighboringCells());
cell = grid.getCellAt(ROWS - 1, 0);
assertEquals("cell(ROWS - 1, 0) had wrong number of neighbors", 3, cell.getNumberOfNeighboringCells());
// cells in the first and last row (except corners) should all have 5 neighbors
for(int column = 1; column < COLUMNS -1; column++) {
cell = grid.getCellAt(0, column);
assertEquals("cell had wrong number of neighbors", 5, cell.getNumberOfNeighboringCells());
cell = grid.getCellAt(ROWS-1, column);
assertEquals("cell had wrong number of neighbors", 5, cell.getNumberOfNeighboringCells());
}
// cells in the first and last column (except corners) should all ahve 5 neighbors
for(int row = 1; row < ROWS -1; row++) {
cell = grid.getCellAt(row, 0);
assertEquals("cell had wrong number of neighbors", 5, cell.getNumberOfNeighboringCells());
cell = grid.getCellAt(row, COLUMNS-1);
assertEquals("cell had wrong number of neighbors", 5, cell.getNumberOfNeighboringCells());
}
// cells not in the first row and first column should all have 8 neighbors
for(int row= 1; row < ROWS-1; row++) {
for(int column= 1; column < COLUMNS-1; column++) {
cell = grid.getCellAt(row, column);
assertEquals("cell had wrong number of neighbors", 8, cell.getNumberOfNeighboringCells());
}
}
}