Guest User

Untitled

a guest
Jul 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package rules;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import org.junit.Before;
  6. import org.junit.Test;
  7.  
  8. public class RulesForNextGenerationTest {
  9. private RulesForNextGeneration inNextGeneration;
  10.  
  11. @Before
  12. public void setup() {
  13. inNextGeneration = new RulesForNextGeneration();
  14. }
  15.  
  16. @Test
  17. public void deadCellWith_0_LiveNeighbors_StaysDead() throws Exception {
  18. assertIsDeadNextTime(new Cell().withLiveNeighbors(0));
  19. }
  20.  
  21. @Test
  22. public void deadCellWith_1_LiveNeighbors_StaysDead() throws Exception {
  23. assertIsDeadNextTime(new Cell().withLiveNeighbors(1));
  24. }
  25.  
  26. @Test
  27. public void deadCellWith_2_LiveNeighbors_StaysDead() throws Exception {
  28. assertIsDeadNextTime(new Cell().withLiveNeighbors(2));
  29. }
  30.  
  31. @Test
  32. public void deadCellWith_3_LiveNeighbors_ComesAlive() throws Exception {
  33. assertIsAliveNextTime(new Cell().withLiveNeighbors(3));
  34. }
  35.  
  36. @Test
  37. public void deadCellWith_4_LiveNeighbors_staysdead() throws Exception {
  38. assertIsDeadNextTime(new Cell().withLiveNeighbors(4));
  39. }
  40.  
  41. @Test
  42. public void liveCellWith_0_LiveNeighbors_Dies() throws Exception {
  43. assertIsDeadNextTime(new Cell().thatIsAlive().withLiveNeighbors(0));
  44. }
  45.  
  46. @Test
  47. public void liveCellWith_1_LiveNeighbors_Dies() throws Exception {
  48. assertIsDeadNextTime(new Cell().thatIsAlive().withLiveNeighbors(1));
  49. }
  50.  
  51. @Test
  52. public void liveCellWith_2_LiveNeighbors_StaysAlive() throws Exception {
  53. assertIsAliveNextTime(new Cell().thatIsAlive().withLiveNeighbors(2));
  54. }
  55.  
  56. @Test
  57. public void liveCellWith_3_LiveNeighbors_StaysAlive() throws Exception {
  58. assertIsAliveNextTime(new Cell().thatIsAlive().withLiveNeighbors(3));
  59. }
  60.  
  61. @Test
  62. public void liveCellWith_4_LiveNeighbors_Dies() throws Exception {
  63. assertIsDeadNextTime(new Cell().thatIsAlive().withLiveNeighbors(4));
  64. }
  65.  
  66. private void assertIsAliveNextTime(Cell cell) {
  67. assertTrue(inNextGeneration.itTurnsOutThat(cell).comesAlive());
  68. }
  69.  
  70. private void assertIsDeadNextTime(Cell cell) {
  71. assertFalse(inNextGeneration.itTurnsOutThat(cell).comesAlive());
  72. }
  73.  
  74. // Test list
  75.  
  76. // TODO a dead cell with 0 live neighbors stays dead.
  77. // TODO a dead cell with 1 live neighbors stays dead.
  78. // TODO a dead cell with 2 live neighbors stays dead.
  79. // TODO a dead cell with 3 live neighbors comes alive.
  80. // TODO a dead cell with 4 live neighbors stays dead.
  81.  
  82. // TODO a live cell with 0 live neighbors dies.
  83. // TODO a live cell with 1 live neighbor dies.
  84. // TODO a live cell with 2 live neighbors stays alive.
  85. // TODO a live cell with 3 live neighbors stays alive.
  86. // TODO a live cell with 4 live neighbors dies.
  87.  
  88. }
Add Comment
Please, Sign In to add comment