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

section 5 State fini

parent cb86aaef
No related branches found
No related tags found
No related merge requests found
......@@ -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
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment