tests/GameOfLife/Inputs/BoardEditor/Options/SetHeightOptionTest.php
/**
     * Checks whether the option can exit the board editor.
     *
     * @covers \BoardEditor\Options\SetHeightOption::setHeight()
     *
     * @throws \Exception
     */
Checks whether the option can exit the board editor.

@throws \Exception
Checks whether the option can exit the board editor . @throws \ Exception
public function testCanSetWidth()
    {
        $testBoard = new Board(4, 4, 4, true);
        $testBoard->setField(1, 1, true);
        $this->assertEquals(1, $testBoard->getAmountCellsAlive());
        $boardEditor = new BoardEditor("test", $testBoard);
        $option = new SetHeightOption($boardEditor);
        $this->expectOutputRegex("/.*/"); 
        $exceptionOccurred = false;
        try
        {
            $option->setHeight(0);
        }
        catch (\Exception $_exception)
        {
            $exceptionOccurred = true;
            $this->assertEquals("The board height may not be less than 1.", $_exception->getMessage());
        }
        $this->assertTrue($exceptionOccurred);
        $result = $option->setHeight(2);
        $this->assertEquals(1, $testBoard->getAmountCellsAlive());
        $this->assertEquals(2, $testBoard->height());
        $this->assertFalse($result);
        $result = $option->setHeight(1);
        $this->assertEquals(0, $testBoard->getAmountCellsAlive());
        $this->assertEquals(1, $testBoard->height());
        $this->assertFalse($result);
    }
public function testCanSetWidth ( ) { $ testBoard = new Board ( 4 , 4 , 4 , true ) ; $ testBoard -> setField ( 1 , 1 , true ) ; $ this -> assertEquals ( 1 , $ testBoard -> getAmountCellsAlive ( ) ) ; $ boardEditor = new BoardEditor ( " test " , $ testBoard ) ; $ option = new SetHeightOption ( $ boardEditor ) ; $ this -> expectOutputRegex ( " /.*/ " ) ; $ exceptionOccurred = false ; try { $ option -> setHeight ( 0 ) ; } catch ( \ Exception $ _exception ) { $ exceptionOccurred = true ; $ this -> assertEquals ( " The board height may not be less than 1. " , $ _exception -> getMessage ( ) ) ; } $ this -> assertTrue ( $ exceptionOccurred ) ; $ result = $ option -> setHeight ( 2 ) ; $ this -> assertEquals ( 1 , $ testBoard -> getAmountCellsAlive ( ) ) ; $ this -> assertEquals ( 2 , $ testBoard -> height ( ) ) ; $ this -> assertFalse ( $ result ) ; $ result = $ option -> setHeight ( 1 ) ; $ this -> assertEquals ( 0 , $ testBoard -> getAmountCellsAlive ( ) ) ; $ this -> assertEquals ( 1 , $ testBoard -> height ( ) ) ; $ this -> assertFalse ( $ result ) ; }
Checks whether the option can exit the board editor.
Checks whether the option can exit the board editor .
// Invalid height // Hide output // Valid width, living cells still inside board // Valid width, living cells outside new board dimensions