Skip to content
Snippets Groups Projects
Commit 0b05b409 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Tests changés pour utiliser setAlive de CellState

parent 48a1a068
Branches
Tags
No related merge requests found
...@@ -30,6 +30,15 @@ public class Cell { ...@@ -30,6 +30,15 @@ public class Cell {
getStateProperty().setValue(cellState); 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}. * Returns the current state of this {@link Cell}.
* *
......
...@@ -9,30 +9,42 @@ public class GridTest { ...@@ -9,30 +9,42 @@ public class GridTest {
private Grid grid; private Grid grid;
@BeforeEach @BeforeEach
public void initializeGrid(){ public void initializeGrid() {
grid = new Grid(3,3); grid = new Grid(6, 6);
} }
@Test @Test
public void testGetNeighbors(){ public void testGetNeighbours() {
assertThat(grid.getNeighbors(1,1)).isNotNull(); assertThat(grid.getNeighbors(1, 1)).isNotNull();
assertThat(grid.getNeighbors(1,1)).hasSize(8); assertThat(grid.getNeighbors(1, 1)).hasSize(8);
assertThat(grid.getNeighbors(1,1)) assertThat(grid.getNeighbors(1, 1))
.containsExactlyInAnyOrder(grid.getCell(0,0), .containsExactlyInAnyOrder(grid.getCell(0, 0),
grid.getCell(0,1), grid.getCell(0, 1),
grid.getCell(0,2), grid.getCell(0, 2),
grid.getCell(1,0), grid.getCell(1, 0),
grid.getCell(1,2), grid.getCell(1, 2),
grid.getCell(2,0), grid.getCell(2, 0),
grid.getCell(2,1), grid.getCell(2, 1),
grid.getCell(2,2)); grid.getCell(2, 2));
} }
@Test @Test
public void testCountAliveNeighbors(){ public void testCountAliveNeighbours() {
assertThat(grid.countAliveNeighbors(1,1)).isEqualTo(0); assertThat(grid.countAliveNeighbors(1, 1)).isEqualTo(0);
grid.getCell(2,2).setState(CellState.ALIVE); grid.getCell(2, 2).setAlive();
grid.getCell(0,0).setState(CellState.ALIVE); grid.getCell(0, 0).setAlive();
assertThat(grid.countAliveNeighbors(1,1)).isEqualTo(2); 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment