GameOfLifeAssignment/test/LifeTest.java

53 lines
1.1 KiB
Java
Raw Normal View History

2021-12-13 15:21:05 +01:00
import org.junit.Test;
import static org.junit.Assert.*;
public class LifeTest {
2021-12-13 15:21:05 +01:00
@Test
public void createNewCell() {
Life l = new Life();
l.setAlive(0, 0);
l.setAlive(0, 1);
l.setAlive(0, 2);
ILife nextGen = l.nextGeneration();
assertTrue(nextGen.isAlive(1, 1));
}
@Test
public void destroyLonelyCell() {
2025-02-12 10:05:31 +01:00
Life l = new Life();
l.setAlive(2, 2);
ILife nextGen = l.nextGeneration();
assertFalse(nextGen.isAlive(2, 2));
2021-12-13 15:21:05 +01:00
}
@Test
public void keepAliveCell() {
2025-02-12 10:11:23 +01:00
Life l = new Life();
l.setAlive(1, 1);
l.setAlive(1, 2);
l.setAlive(2, 1);
ILife nextGen = l.nextGeneration();
2025-02-12 10:08:00 +01:00
2025-02-12 10:11:23 +01:00
assertTrue(nextGen.isAlive(1, 1));
2021-12-13 15:21:05 +01:00
}
@Test
public void destroyCrowdedCell() {
2025-02-12 10:24:34 +01:00
Life l = new Life();
l.setAlive(1, 1);
l.setAlive(0, 1);
l.setAlive(2, 1);
l.setAlive(1, 0);
l.setAlive(1, 2);
2021-12-13 15:21:05 +01:00
2025-02-12 10:24:34 +01:00
ILife nextGen = l.nextGeneration();
2021-12-13 15:21:05 +01:00
2025-02-12 10:24:34 +01:00
assertFalse(nextGen.isAlive(1, 1));
}
}