LifeTest third step passed

This commit is contained in:
Moritz Neumeier 2021-12-17 13:39:11 +01:00
parent 2b8a04fe31
commit c620449f0f
4 changed files with 13 additions and 1 deletions

View File

@ -92,7 +92,7 @@ public class Life implements ILife {
else if(isAlive(x,y) && alive < 2){ else if(isAlive(x,y) && alive < 2){
nextBoard[y] = nextBoard[y].substring(0, x) + ' ' + nextBoard[y].substring(x+1); nextBoard[y] = nextBoard[y].substring(0, x) + ' ' + nextBoard[y].substring(x+1);
} }
else{ else if(isAlive(x,y) && (alive==2 || alive ==3)){
nextBoard[y] = nextBoard[y].substring(0, x) + board[y].charAt(x) + nextBoard[y].substring(x+1); nextBoard[y] = nextBoard[y].substring(0, x) + board[y].charAt(x) + nextBoard[y].substring(x+1);
} }
} }

View File

@ -40,6 +40,18 @@ public class LifeTest {
@Test @Test
public void keepAliveCell() { public void keepAliveCell() {
//Eine lebende Zelle mit zwei oder drei lebenden Nachbarn bleibt in der Folgegeneration am Leben.
// Arrange: drei lebende Zellen
Life l = new Life();
l.setAlive(0, 0);
l.setAlive(0, 1);
l.setAlive(0, 2);
// Act: Berechnung der Folgegeneration
l.nextGeneration();
// Assert: Rasterpunkt mit zwei oder 3 lebenden Nachbarn bleibt am Leben
assertTrue(l.isAlive(0, 1));
} }