@Test public void testFinalState() { /* verify that the actual pattern matches the expected pattern after 3 generations * */ /* expected pattern for final state * (X: alive; -: dead) * * 0 1 2 3 4 * 0 - - X - - * 1 - X - X - * 2 X - - - X * 3 - X - X - * 4 - - X - - * */ GameOfLife game = new GameOfLife(true); game.createNextGeneration(); game.createNextGeneration(); final int ROWS = game.getNumRows(); final int COLS = game.getNumCols(); for (int row = 0; row < ROWS; row++) { for (int col = 0; col < COLS; col++) { // in this example, an alive cell has a non-null actor and a dead cell has a null actor Actor cell = game.getActor(row, col); // if the cell at the current row and col should be alive, assert that the actor is not null if ((row == 0 && col == 2) || (row == 1 && col == 1) || (row == 1 && col == 3) || (row == 2 && col == 0) || (row == 2 && col == 4) || (row == 3 && col == 1) || (row == 3 && col == 3) || (row == 4 && col == 2)) { assertNotNull("expected alive cell at (" + row + ", " + col + ")", cell); } else // else, the cell should be dead; assert that the actor is null { assertNull("expected dead cell at (" + row + ", " + col + ")", cell); } } } // ... }
@Test public void testInitialState() { /* expected pattern for initial state * (X: alive; -: dead) * * 0 1 2 3 4 * 0 X - - - X * 1 - X - X - * 2 - - X - - * 3 - X - X - * 4 X - - - X * */ GameOfLife game = new GameOfLife(true); final int ROWS = game.getNumRows(); final int COLS = game.getNumCols(); for (int row = 0; row < ROWS; row++) { for (int col = 0; col < COLS; col++) { // in this example, an alive cell has a non-null actor and a dead cell has a null actor Actor cell = game.getActor(row, col); // if the cell at the current row and col should be alive, assert that the actor is not null if ((row == 0 && col == 0) || (row == 0 && col == 4) || (row == 1 && col == 1) || (row == 1 && col == 3) || (row == 2 && col == 2) || (row == 3 && col == 1) || (row == 3 && col == 3) || (row == 4 && col == 0) || (row == 4 && col == 4)) { assertNotNull("expected alive cell at (" + row + ", " + col + ")", cell); } else // else, the cell should be dead; assert that the actor is null { assertNull("expected dead cell at (" + row + ", " + col + ")", cell); } } } }