nextGeneration() Implementierung setAlive() auch mit zwei Nachbarn -> Test keepAliveWithTwoNeighbours() passes
This commit is contained in:
parent
ee5469dbe3
commit
bcd68cee42
Binary file not shown.
Binary file not shown.
@ -54,6 +54,8 @@ public class Life implements ILife {
|
|||||||
for (int x = 0; x < grid[y].length; x++) {
|
for (int x = 0; x < grid[y].length; x++) {
|
||||||
if (countAliveNeighbours(x, y) == 3) {
|
if (countAliveNeighbours(x, y) == 3) {
|
||||||
next.setAlive(x, y);
|
next.setAlive(x, y);
|
||||||
|
} else if (countAliveNeighbours(x, y) == 2) {
|
||||||
|
next.setAlive(x, y);
|
||||||
} else if (countAliveNeighbours(x, y) < 2 || countAliveNeighbours(x, y) > 3) {
|
} else if (countAliveNeighbours(x, y) < 2 || countAliveNeighbours(x, y) > 3) {
|
||||||
next.setDead(x, y);
|
next.setDead(x, y);
|
||||||
}
|
}
|
||||||
|
@ -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
|
@Test
|
||||||
public void keepAliveWithTwoNeighbours() {
|
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();
|
Life l = new Life();
|
||||||
l.setAlive(1, 1);
|
l.setAlive(1, 1);
|
||||||
l.setAlive(0, 0);
|
l.setAlive(0, 0);
|
||||||
@ -54,7 +50,6 @@ public class LifeTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void keepAliveWithThreeNeighbours() {
|
public void keepAliveWithThreeNeighbours() {
|
||||||
// passed, weil Zellen mit genau 3 Nachbarn bereits in nextGen auf alive gesetzt werden
|
|
||||||
Life l = new Life();
|
Life l = new Life();
|
||||||
l.setAlive(1, 1);
|
l.setAlive(1, 1);
|
||||||
l.setAlive(0, 0);
|
l.setAlive(0, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user