nextGeneration() Implementierung setAlive() auch mit zwei Nachbarn -> Test keepAliveWithTwoNeighbours() passes

This commit is contained in:
Susanne 2025-02-16 16:35:12 +01:00
parent ee5469dbe3
commit bcd68cee42
4 changed files with 2 additions and 5 deletions

View File

@ -54,6 +54,8 @@ public class Life implements ILife {
for (int x = 0; x < grid[y].length; x++) {
if (countAliveNeighbours(x, y) == 3) {
next.setAlive(x, y);
} else if (countAliveNeighbours(x, y) == 2) {
next.setAlive(x, y);
} else if (countAliveNeighbours(x, y) < 2 || countAliveNeighbours(x, y) > 3) {
next.setDead(x, y);
}

View File

@ -37,12 +37,8 @@ public class LifeTest {
}
// Testfall "keepAliveCell()" aufgeteilt in zwei einzelne Tests, da es ja eigentlich üblich ist, dass je Test
// nur ein einzelnes Szenario überprüft wird
@Test
public void keepAliveWithTwoNeighbours() {
// failed, weil bislang nur Zellen mit genau 3 Nachbarn in nextGen auf alive gesetzt werden,
// andernfalls standardmäßig mit false, also tot, initialisiert
Life l = new Life();
l.setAlive(1, 1);
l.setAlive(0, 0);
@ -54,7 +50,6 @@ public class LifeTest {
@Test
public void keepAliveWithThreeNeighbours() {
// passed, weil Zellen mit genau 3 Nachbarn bereits in nextGen auf alive gesetzt werden
Life l = new Life();
l.setAlive(1, 1);
l.setAlive(0, 0);