tests/GameOfLife/BoardTest.php
/**
     * Checks whether the correct neighbors of a field are returned for both border types (solid and passthrough).
     *
     * @dataProvider neighborsOfFieldProvider
     * @covers \GameOfLife\Board::getNeighborsOfField()
     *
     * @param int[string] $_targetField Coordinates of the target field in the format array("x" => x, "y" => y)
     * @param bool $_hasBorder Defines whether the board has a border
     * @param int[] $_neighborsX All possible X-Coordinates of neighbors
     * @param int[] $_neighborsY All possible Y-Coordinates of neighbors
     * @param int $_amountNeighbors Expected amount of neighbor cells
     */
Checks whether the correct neighbors of a field are returned for both border types (solid and passthrough).


Checks whether the correct neighbors of a field are returned for both border types ( solid and passthrough ) .
public function testCanGetNeighborsOfField($_targetField, $_hasBorder, $_neighborsX, $_neighborsY, $_amountNeighbors)
    {
        $board = new Board(10, 10, 1, $_hasBorder);
        $field = $board->fields()[$_targetField["y"]][$_targetField["x"]];
        $neighbors = $board->getNeighborsOfField($field);
        $this->assertEquals($_amountNeighbors, count($neighbors));
        foreach ($_neighborsY as $y)
        {
            foreach ($_neighborsX as $x)
            {
                if ($field instanceof Field)
                {
                    if ($y != $field->y() || $x != $field->x())
                    {
                        $tmpField = new Field($x, $y, false, $board);
                        $this->assertNotFalse(array_search($tmpField, $neighbors));
                    }
                }
            }
        }
    }
public function testCanGetNeighborsOfField ( $ _targetField , $ _hasBorder , $ _neighborsX , $ _neighborsY , $ _amountNeighbors ) { $ board = new Board ( 10 , 10 , 1 , $ _hasBorder ) ; $ field = $ board -> fields ( ) [ $ _targetField [ " y " ] ] [ $ _targetField [ " x " ] ] ; $ neighbors = $ board -> getNeighborsOfField ( $ field ) ; $ this -> assertEquals ( $ _amountNeighbors , count ( $ neighbors ) ) ; foreach ( $ _neighborsY as $ y ) { foreach ( $ _neighborsX as $ x ) { if ( $ field instanceof Field ) { if ( $ y != $ field -> y ( ) || $ x != $ field -> x ( ) ) { $ tmpField = new Field ( $ x , $ y , false , $ board ) ; $ this -> assertNotFalse ( array_search ( $ tmpField , $ neighbors ) ) ; } } } } }
Checks whether the correct neighbors of a field are returned for both border types (solid and passthrough).
Checks whether the correct neighbors of a field are returned for both border types ( solid and passthrough ) .