diff --git a/src/main/java/model/State.java b/src/main/java/model/State.java index 1954558460d6969d09544c64c40152d97c1a736e..813285dd495f7da078701d942ecf748a1a07be4c 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 ee988ff84a1937c6b86efab59de11ed21b30a223..d18462719a975d62bd49bcb7dd86eaee364410fd 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