|
| 1 | +package com.example.deneme; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | +import static org.junit.jupiter.api.Assertions.*; |
| 5 | + |
| 6 | +public class GameRulesTest { |
| 7 | + |
| 8 | + @Test |
| 9 | + void birthRuleSetsAliveWhenExactlyThreeNeighbors() { |
| 10 | + Cell cell = new Cell(); |
| 11 | + cell.setAlive(false); |
| 12 | + cell.setNeighbours(3); |
| 13 | + Game game = new Game(1, 1); |
| 14 | + game.applyBirthRule(cell); |
| 15 | + assertTrue(cell.isAlive(), "Cell should become alive when it has exactly three neighbours"); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + void birthRuleKeepsDeadWhenNotThreeNeighbors() { |
| 20 | + Cell cell = new Cell(); |
| 21 | + cell.setAlive(false); |
| 22 | + cell.setNeighbours(2); |
| 23 | + Game game = new Game(1, 1); |
| 24 | + game.applyBirthRule(cell); |
| 25 | + assertFalse(cell.isAlive(), "Cell should remain dead when it does not have three neighbours"); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + void survivalRuleKeepsAliveWithTwoOrThreeNeighbors() { |
| 30 | + Cell cell = new Cell(); |
| 31 | + cell.setNeighbours(2); |
| 32 | + Game game = new Game(1, 1); |
| 33 | + game.applySurvivalRule(cell); |
| 34 | + assertTrue(cell.isAlive(), "Cell should stay alive with two neighbours"); |
| 35 | + |
| 36 | + cell.setNeighbours(3); |
| 37 | + game.applySurvivalRule(cell); |
| 38 | + assertTrue(cell.isAlive(), "Cell should stay alive with three neighbours"); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void survivalRuleKillsWithOtherNeighborCounts() { |
| 43 | + Cell cell = new Cell(); |
| 44 | + cell.setNeighbours(1); |
| 45 | + Game game = new Game(1, 1); |
| 46 | + game.applySurvivalRule(cell); |
| 47 | + assertFalse(cell.isAlive(), "Cell should die with neighbour count other than two or three"); |
| 48 | + } |
| 49 | +} |
0 commit comments