diff --git a/src/main/java/model/Cell.java b/src/main/java/model/Cell.java index b8d733d16b56a7c6a6f5ffe1b56b0ce5e124e7b1..abf8cb1794680ae450f7762e900deb87e0efa9d0 100644 --- a/src/main/java/model/Cell.java +++ b/src/main/java/model/Cell.java @@ -30,6 +30,15 @@ public class Cell { getStateProperty().setValue(cellState); } + /** + * Sets the state of this {@link Cell} to an arbitrary alive state. + */ + + public void setAlive() { + getStateProperty().setValue(CellState.ALIVE); + } + + /** * Returns the current state of this {@link Cell}. * diff --git a/src/test/java/model/GridTest.java b/src/test/java/model/GridTest.java index bf3637238f83b04cd794f6176f454aa0c2c4579b..9ae2d7924a13bcdc49890b28be7af8bbf1679774 100644 --- a/src/test/java/model/GridTest.java +++ b/src/test/java/model/GridTest.java @@ -9,30 +9,42 @@ public class GridTest { private Grid grid; @BeforeEach - public void initializeGrid(){ - grid = new Grid(3,3); + public void initializeGrid() { + grid = new Grid(6, 6); } @Test - public void testGetNeighbors(){ - assertThat(grid.getNeighbors(1,1)).isNotNull(); - assertThat(grid.getNeighbors(1,1)).hasSize(8); - assertThat(grid.getNeighbors(1,1)) - .containsExactlyInAnyOrder(grid.getCell(0,0), - grid.getCell(0,1), - grid.getCell(0,2), - grid.getCell(1,0), - grid.getCell(1,2), - grid.getCell(2,0), - grid.getCell(2,1), - grid.getCell(2,2)); + public void testGetNeighbours() { + assertThat(grid.getNeighbors(1, 1)).isNotNull(); + assertThat(grid.getNeighbors(1, 1)).hasSize(8); + assertThat(grid.getNeighbors(1, 1)) + .containsExactlyInAnyOrder(grid.getCell(0, 0), + grid.getCell(0, 1), + grid.getCell(0, 2), + grid.getCell(1, 0), + grid.getCell(1, 2), + grid.getCell(2, 0), + grid.getCell(2, 1), + grid.getCell(2, 2)); } @Test - public void testCountAliveNeighbors(){ - assertThat(grid.countAliveNeighbors(1,1)).isEqualTo(0); - grid.getCell(2,2).setState(CellState.ALIVE); - grid.getCell(0,0).setState(CellState.ALIVE); - assertThat(grid.countAliveNeighbors(1,1)).isEqualTo(2); + public void testCountAliveNeighbours() { + assertThat(grid.countAliveNeighbors(1, 1)).isEqualTo(0); + grid.getCell(2, 2).setAlive(); + grid.getCell(0, 0).setAlive(); + assertThat(grid.countAliveNeighbors(1, 1)).isEqualTo(2); } -} + + @Test + public void testCalculateNextState() { + grid.getCell(1, 0).setAlive(); + grid.getCell(1, 1).setAlive(); + grid.getCell(1, 2).setAlive(); + assertThat(grid.calculateNextState(0, 0).isAlive).isFalse(); + assertThat(grid.calculateNextState(1, 0).isAlive).isFalse(); + assertThat(grid.calculateNextState(1, 1).isAlive).isTrue(); + assertThat(grid.calculateNextState(2, 1).isAlive).isTrue(); + } + +} \ No newline at end of file