From 9471d9883e6400f3c768423ed4e54fd18449257f Mon Sep 17 00:00:00 2001 From: Guyslain <guyslain.naves@lis-lab.fr> Date: Mon, 23 Oct 2023 15:57:54 +0200 Subject: [PATCH] section 5 State fini --- src/main/java/model/State.java | 13 +++++++++---- .../java/model/automata/GameOfLifeStateTest.java | 5 ++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/model/State.java b/src/main/java/model/State.java index 1954558..813285d 100644 --- a/src/main/java/model/State.java +++ b/src/main/java/model/State.java @@ -21,11 +21,11 @@ public interface State<S> { Color getColor(); /** - * Computes and returns the next state based on the rules of the cellular automaton. + * Computes and returns the states by cycling through each possible state * * @return The next state. */ - S next(); + S cycle(); /** * Updates the state based on the states of its neighboring cells. @@ -44,7 +44,12 @@ public interface State<S> { * @return The number of times the specified state appears in the list of neighbors. */ static <T> int count(T state, List<T> neighbours) { - //TODO: à compléter - return 0; + int count = 0; + for (T element : neighbours) { + if (element.equals(state)) { + count = count + 1; + } + } + return count; } } \ No newline at end of file diff --git a/src/test/java/model/automata/GameOfLifeStateTest.java b/src/test/java/model/automata/GameOfLifeStateTest.java index ee988ff..d184627 100644 --- a/src/test/java/model/automata/GameOfLifeStateTest.java +++ b/src/test/java/model/automata/GameOfLifeStateTest.java @@ -1,7 +1,6 @@ package model.automata; import javafx.scene.paint.Color; -import model.State; import org.junit.jupiter.api.Test; import java.util.List; @@ -18,8 +17,8 @@ class GameOfLifeStateTest { @Test public void testNext() { - assertEquals(ALIVE.next(), DEAD); - assertEquals(DEAD.next(), ALIVE); + assertEquals(ALIVE.cycle(), DEAD); + assertEquals(DEAD.cycle(), ALIVE); } @Test -- GitLab