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); | ||||
} | } | ||||
} | } |
@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)); | |||||
} | } | ||||