tests/GameOfLife/Inputs/TemplateHandler/TemplatePlacerTest.php
/**
     * Checks whether templates can be placed as expected.
     *
     * @param int $_templatePosX The x position of the top left corner of the template
     * @param int $_templatePosY The y position of the top left corner of the template
     * @param Bool $_adjustDimensions Indicates whether the board will be adjusted to have the same dimensions like the template
     * @param String $_expectedExceptionMessage The expected exception message (if any)
     *
     * @throws \Exception
     *
     * @covers \TemplateHandler\FieldsPlacer::placeTemplate()
     * @covers \TemplateHandler\FieldsPlacer::isTemplateOutOfBounds()
     *
     *
     * @dataProvider placeTemplateProvider()
     */
Checks whether templates can be placed as expected.
@param int $_templatePosX The x position of the top left corner of the template
@param int $_templatePosY The y position of the top left corner of the template
@param Bool $_adjustDimensions Indicates whether the board will be adjusted to have the same dimensions like the template
@param String $_expectedExceptionMessage The expected exception message (if any)

@throws \Exception




Checks whether templates can be placed as expected . @param int $_templatePosX The x position of the top left corner of the template @param int $_templatePosY The y position of the top left corner of the template @param Bool $_adjustDimensions Indicates whether the board will be adjusted to have the same dimensions like the template @param String $_expectedExceptionMessage The expected exception message ( if any ) @throws \ Exception
public function testCanPlaceTemplate(int $_templatePosX, int $_templatePosY, Bool $_adjustDimensions, String $_expectedExceptionMessage = "")
    {
        $templatePlacer = new FieldsPlacer();
        $exceptionOccurred = false;
        try
        {
            $templatePlacer->placeTemplate($this->fields, $this->board, $_templatePosX, $_templatePosY, $_adjustDimensions);
        }
        catch (\Exception $_exception)
        {
            $exceptionOccurred = true;
            $this->assertEquals($_expectedExceptionMessage, $_exception->getMessage());
        }
        if ($_expectedExceptionMessage) $this->assertTrue($exceptionOccurred);
        else $this->assertFalse($exceptionOccurred);
        if ($_expectedExceptionMessage) $this->assertEquals(0, $this->board->getAmountCellsAlive());
        else
        {
            $this->assertEquals(5, $this->board->getAmountCellsAlive());
            $this->assertTrue($this->board->getFieldStatus(0, 0));
            $this->assertTrue($this->board->getFieldStatus(1, 0));
            $this->assertTrue($this->board->getFieldStatus(2, 0));
            $this->assertTrue($this->board->getFieldStatus(0, 1));
            $this->assertTrue($this->board->getFieldStatus(1, 1));
        }
        if ($_adjustDimensions)
        {
            $this->assertEquals(count($this->fields[0]), $this->board->width());
            $this->assertEquals(count($this->fields), $this->board->height());
        }
        $board = new Board(10, 10, 1, true);
        $this->assertEquals(0, $board->getAmountCellsAlive());
    }
public function testCanPlaceTemplate ( int $ _templatePosX , int $ _templatePosY , Bool $ _adjustDimensions , String $ _expectedExceptionMessage = " " ) { $ templatePlacer = new FieldsPlacer ( ) ; $ exceptionOccurred = false ; try { $ templatePlacer -> placeTemplate ( $ this -> fields , $ this -> board , $ _templatePosX , $ _templatePosY , $ _adjustDimensions ) ; } catch ( \ Exception $ _exception ) { $ exceptionOccurred = true ; $ this -> assertEquals ( $ _expectedExceptionMessage , $ _exception -> getMessage ( ) ) ; } if ( $ _expectedExceptionMessage ) $ this -> assertTrue ( $ exceptionOccurred ) ; else $ this -> assertFalse ( $ exceptionOccurred ) ; if ( $ _expectedExceptionMessage ) $ this -> assertEquals ( 0 , $ this -> board -> getAmountCellsAlive ( ) ) ; else { $ this -> assertEquals ( 5 , $ this -> board -> getAmountCellsAlive ( ) ) ; $ this -> assertTrue ( $ this -> board -> getFieldStatus ( 0 , 0 ) ) ; $ this -> assertTrue ( $ this -> board -> getFieldStatus ( 1 , 0 ) ) ; $ this -> assertTrue ( $ this -> board -> getFieldStatus ( 2 , 0 ) ) ; $ this -> assertTrue ( $ this -> board -> getFieldStatus ( 0 , 1 ) ) ; $ this -> assertTrue ( $ this -> board -> getFieldStatus ( 1 , 1 ) ) ; } if ( $ _adjustDimensions ) { $ this -> assertEquals ( count ( $ this -> fields [ 0 ] ) , $ this -> board -> width ( ) ) ; $ this -> assertEquals ( count ( $ this -> fields ) , $ this -> board -> height ( ) ) ; } $ board = new Board ( 10 , 10 , 1 , true ) ; $ this -> assertEquals ( 0 , $ board -> getAmountCellsAlive ( ) ) ; }
Checks whether templates can be placed as expected.
Checks whether templates can be placed as expected .
// No dimensions adjustment, invalid position top left