You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LifeTest.java 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import org.junit.Test;
  2. import static org.junit.Assert.*;
  3. public class LifeTest {
  4. @Test
  5. public void createNewCell() {
  6. Life l = new Life();
  7. l.setAlive(0, 0);
  8. l.setAlive(0, 1);
  9. l.setAlive(0, 2);
  10. ILife nextGen = l.nextGeneration();
  11. assertTrue(nextGen.isAlive(1, 1));
  12. }
  13. @Test
  14. public void destroyLonelyCell() {
  15. Life firstGen = new Life();
  16. firstGen.setAlive(0, 0);
  17. firstGen.setAlive(0, 2);
  18. ILife nextGen = firstGen.nextGeneration();
  19. assertTrue(nextGen.isDead(0, 0));
  20. assertTrue(nextGen.isDead(0, 2));
  21. }
  22. @Test
  23. public void keepAliveCell() {
  24. Life firstGen = new Life();
  25. firstGen.setAlive(2, 2);
  26. firstGen.setAlive(3, 3);
  27. firstGen.setAlive(4, 4);
  28. ILife nextGen = firstGen.nextGeneration();
  29. assertTrue(nextGen.isAlive(3, 3));
  30. }
  31. @Test
  32. public void destroyCrowdedCell() {
  33. Life firstGen = new Life();
  34. firstGen.setAlive(0, 0);
  35. firstGen.setAlive(0, 1);
  36. firstGen.setAlive(0, 2);
  37. firstGen.setAlive(1, 0);
  38. firstGen.setAlive(1, 1);
  39. ILife nextGen = firstGen.nextGeneration();
  40. assertTrue(nextGen.isDead(0, 1));
  41. assertTrue(nextGen.isDead(1, 1));
  42. }
  43. }