From 0b05b4090fb04c0d662635033e679d295e40d650 Mon Sep 17 00:00:00 2001
From: arnaudlabourel <arnaud.labourel@univ-amu.fr>
Date: Wed, 29 Sep 2021 07:44:38 +0200
Subject: [PATCH] =?UTF-8?q?Tests=20chang=C3=A9s=20pour=20utiliser=20setAli?=
 =?UTF-8?q?ve=20de=20CellState?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/main/java/model/Cell.java     |  9 ++++++
 src/test/java/model/GridTest.java | 52 +++++++++++++++++++------------
 2 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/src/main/java/model/Cell.java b/src/main/java/model/Cell.java
index b8d733d..abf8cb1 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 bf36372..9ae2d79 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
-- 
GitLab