Skip to content
Snippets Groups Projects
Select Git revision
  • ac3e362037a1b31c36a2dc49eb38320cf4906e79
  • main default protected
  • correction_video
  • going_further
  • ImprovedMouseInteraction
  • final2023
  • template
  • ModifGUI
8 results

GameOfLifeState.java

Blame
  • Forked from YAGOUBI Rim / Game of life Template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    GameOfLifeStateTest.java 2.40 KiB
    package model.automata;
    
    import javafx.scene.paint.Color;
    import model.State;
    import org.junit.jupiter.api.Test;
    
    import java.util.List;
    
    import static model.automata.GameOfLifeState.*;
    import static org.junit.jupiter.api.Assertions.*;
    
    class GameOfLifeStateTest {
        @Test
        public void testGetColor() {
            assertEquals(Color.WHITE, DEAD.getColor());
            assertEquals(Color.RED, ALIVE.getColor());
        }
    
        @Test
        public void testNext() {
            assertEquals(ALIVE.next(), DEAD);
            assertEquals(DEAD.next(), ALIVE);
        }
    
        @Test
        public void testAliveUpdate() {
            // Test with three alive neighbors, should be ALIVE
            List<GameOfLifeState> aliveNeighbors =
                    List.of(ALIVE, DEAD, ALIVE, DEAD, ALIVE);
            assertEquals(ALIVE, ALIVE.update(aliveNeighbors));
    
            // Test with two alive neighbors, should be ALIVE
            List<GameOfLifeState> twoAliveNeighbors =
                    List.of(ALIVE, DEAD, ALIVE, DEAD, DEAD);
            assertEquals(ALIVE, ALIVE.update(twoAliveNeighbors));
    
            // Test with four alive neighbors, should be DEAD
            List<GameOfLifeState> fourAliveNeighbors =
                    List.of(ALIVE, ALIVE, DEAD, ALIVE, ALIVE);
            assertEquals(DEAD, ALIVE.update(fourAliveNeighbors));
    
            // Test with zero alive neighbors, should be DEAD
            List<GameOfLifeState> zeroAliveNeighbors =
                    List.of(DEAD, DEAD, DEAD, DEAD);
            assertEquals(DEAD, ALIVE.update(zeroAliveNeighbors));
        }
    
        @Test
        public void testDeadUpdate() {
            // Test with three alive neighbors, should be ALIVE
            List<GameOfLifeState> aliveNeighbors =
                    List.of(ALIVE, DEAD, ALIVE, DEAD, ALIVE);
            assertEquals(ALIVE, DEAD.update(aliveNeighbors));
    
            // Test with two alive neighbors, should be DEAD
            List<GameOfLifeState> twoAliveNeighbors =
                    List.of(ALIVE, DEAD, ALIVE, DEAD, DEAD);
            assertEquals(DEAD, DEAD.update(twoAliveNeighbors));
    
            // Test with four alive neighbors, should be DEAD
            List<GameOfLifeState> fourAliveNeighbors =
                    List.of(ALIVE, ALIVE, DEAD, ALIVE, ALIVE);
            assertEquals(DEAD, DEAD.update(fourAliveNeighbors));
    
            // Test with zero alive neighbors, should be DEAD
            List<GameOfLifeState> zeroAliveNeighbors =
                    List.of(DEAD, DEAD, DEAD, DEAD);
            assertEquals(DEAD, DEAD.update(zeroAliveNeighbors));
        }
    }