Skip to content
Snippets Groups Projects
Commit 9471d988 authored by Guyslain's avatar Guyslain
Browse files

section 5 State fini

parent cb86aaef
Branches
Tags template
No related merge requests found
...@@ -21,11 +21,11 @@ public interface State<S> { ...@@ -21,11 +21,11 @@ public interface State<S> {
Color getColor(); 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. * @return The next state.
*/ */
S next(); S cycle();
/** /**
* Updates the state based on the states of its neighboring cells. * Updates the state based on the states of its neighboring cells.
...@@ -44,7 +44,12 @@ public interface State<S> { ...@@ -44,7 +44,12 @@ public interface State<S> {
* @return The number of times the specified state appears in the list of neighbors. * @return The number of times the specified state appears in the list of neighbors.
*/ */
static <T> int count(T state, List<T> neighbours) { static <T> int count(T state, List<T> neighbours) {
//TODO: à compléter int count = 0;
return 0; for (T element : neighbours) {
if (element.equals(state)) {
count = count + 1;
}
}
return count;
} }
} }
\ No newline at end of file
package model.automata; package model.automata;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import model.State;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.List; import java.util.List;
...@@ -18,8 +17,8 @@ class GameOfLifeStateTest { ...@@ -18,8 +17,8 @@ class GameOfLifeStateTest {
@Test @Test
public void testNext() { public void testNext() {
assertEquals(ALIVE.next(), DEAD); assertEquals(ALIVE.cycle(), DEAD);
assertEquals(DEAD.next(), ALIVE); assertEquals(DEAD.cycle(), ALIVE);
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment