Refactoring: Überprüfung implementieren, wann setAlive() aufgerufen werden darf
This commit is contained in:
parent
e69a9a5b44
commit
566d74f5bf
Binary file not shown.
Binary file not shown.
@ -33,7 +33,7 @@ public class Life implements ILife {
|
||||
|
||||
@Override
|
||||
public void setAlive(int x, int y) {
|
||||
grid[x][y] = true; // damit Test grün wird, muss Zelle im grid true (alive) werden
|
||||
grid[x][y] = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,18 +44,21 @@ public class Life implements ILife {
|
||||
|
||||
@Override
|
||||
public boolean isAlive(int x, int y) {
|
||||
// REFACTORING: return nicht mehr einfach auf 'true' setzen, sondern tatsächlich eine Überprüfung ausführen
|
||||
|
||||
// Zustand der Zelle an Position (x, y)
|
||||
return grid[x][y];
|
||||
|
||||
// -> grid muss erstellt werden, siehe Zeile 3
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILife nextGeneration() {
|
||||
Life next = new Life();
|
||||
next.setAlive(1,1); // muss jetzt ausgelöst werden, damit Zelle alive wird
|
||||
|
||||
if (countAliveNeighbours() == 3) {
|
||||
next.setAlive(1,1);
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
private int countAliveNeighbours() {
|
||||
return 3;
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@ public class LifeTest {
|
||||
|
||||
// Assert: Rasterpunkt mit drei Nachbarn sollte jetzt leben
|
||||
assertTrue(nextGen.isAlive(1, 1));
|
||||
// TEST GRÜN WENN nextGen!=null UND isAlive==true
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user