tests/GameOfLife/GameLogicTest.php
/**
     * Checks whether loops are successfully detected.
     *
     * @covers \GameOfLife\GameLogic::addToHistory()
     * @covers \GameOfLife\GameLogic::calculateNextBoard()
     * @covers \GameOfLife\GameLogic::isLoopDetected()
     */
Checks whether loops are successfully detected.
Checks whether loops are successfully detected .
public function testCanDetectLoops()
    {
        $board = new Board(3, 3, 5, true);
        $board->setField(1, 1, true);
        $board->setField(1, 2, true);
        $board->setField(2, 1, true);
        $board->setField(2, 2, true);
        $gameLogic = new GameLogic(new ConwayRule());
        $this->assertFalse($gameLogic->isLoopDetected());
        $gameLogic->calculateNextBoard($board);
        $this->assertTrue($gameLogic->isLoopDetected());
        $this->assertEquals(1, count($gameLogic->historyOfBoards()));
        $board->resetBoard();
        $board->setField(1,0, true);
        $board->setField(1, 1, true);
        $board->setField(1, 2, true);
        $gameLogic = new GameLogic(new ConwayRule());
        $this->assertFalse($gameLogic->isLoopDetected());
        $gameLogic->calculateNextBoard($board);
        $this->assertFalse($gameLogic->isLoopDetected());
        $this->assertEquals(1, count($gameLogic->historyOfBoards()));
        $gameLogic->calculateNextBoard($board);
        $this->assertTrue($gameLogic->isLoopDetected());
        $this->assertEquals(2, count($gameLogic->historyOfBoards()));
    }
public function testCanDetectLoops ( ) { $ board = new Board ( 3 , 3 , 5 , true ) ; $ board -> setField ( 1 , 1 , true ) ; $ board -> setField ( 1 , 2 , true ) ; $ board -> setField ( 2 , 1 , true ) ; $ board -> setField ( 2 , 2 , true ) ; $ gameLogic = new GameLogic ( new ConwayRule ( ) ) ; $ this -> assertFalse ( $ gameLogic -> isLoopDetected ( ) ) ; $ gameLogic -> calculateNextBoard ( $ board ) ; $ this -> assertTrue ( $ gameLogic -> isLoopDetected ( ) ) ; $ this -> assertEquals ( 1 , count ( $ gameLogic -> historyOfBoards ( ) ) ) ; $ board -> resetBoard ( ) ; $ board -> setField ( 1 , 0 , true ) ; $ board -> setField ( 1 , 1 , true ) ; $ board -> setField ( 1 , 2 , true ) ; $ gameLogic = new GameLogic ( new ConwayRule ( ) ) ; $ this -> assertFalse ( $ gameLogic -> isLoopDetected ( ) ) ; $ gameLogic -> calculateNextBoard ( $ board ) ; $ this -> assertFalse ( $ gameLogic -> isLoopDetected ( ) ) ; $ this -> assertEquals ( 1 , count ( $ gameLogic -> historyOfBoards ( ) ) ) ; $ gameLogic -> calculateNextBoard ( $ board ) ; $ this -> assertTrue ( $ gameLogic -> isLoopDetected ( ) ) ; $ this -> assertEquals ( 2 , count ( $ gameLogic -> historyOfBoards ( ) ) ) ; }
Checks whether loops are successfully detected.
Checks whether loops are successfully detected .
// Place a 2x2 square on the field (static tile with conway rules) // Place a 1x3 blinker on the field (blinking tile with conway rules))