tests/GameOfLife/Rules/BaseRuleTest.php
/**
     * Checks whether the birth/stay alive rules are correctly applied.
     *
     * Tests all possible combinations of living/dead neighbors with the comway rules
     *
     * @dataProvider calculateNewStateProvider
     *
     * @param bool $_initialState Initial state of the field
     * @param int $_amountLivingNeighbors Amount of living neighbors
     * @param bool $_expectedState Expected new state of the field
     */
Checks whether the birth/stay alive rules are correctly applied.
Tests all possible combinations of living/dead neighbors with the comway rules



@param bool $_initialState Initial state of the field
@param int $_amountLivingNeighbors Amount of living neighbors
@param bool $_expectedState Expected new state of the field
Checks whether the birth / stay alive rules are correctly applied . Tests all possible combinations of living / dead neighbors with the comway rules @param bool $_initialState Initial state of the field @param int $_amountLivingNeighbors Amount of living neighbors @param bool $_expectedState Expected new state of the field
public function testCanCalculateNewState(bool $_initialState, int $_amountLivingNeighbors, bool $_expectedState)
    {
        $fieldMock = $this->getMockBuilder(\GameOfLife\Field::class)
                          ->disableOriginalConstructor()
                          ->getMock();
        $fieldMock->expects($this->exactly(1))
                  ->method("isAlive")
                  ->willReturn($_initialState);
        $fieldMock->expects($this->exactly(1))
                  ->method("numberOfLivingNeighbors")
                  ->willReturn($_amountLivingNeighbors);
        if ($_initialState == $_expectedState && $_initialState == false)
        { 
            $fieldMock->expects($this->exactly(1))
                      ->method("value")
                      ->willReturn($_initialState);
        }
        $rule = new ConwayRule();
        if ($fieldMock instanceof Field)
        {
            $newState = $rule->calculateNewState($fieldMock);
            $this->assertEquals($_expectedState, $newState);
        }
    }
public function testCanCalculateNewState ( bool $ _initialState , int $ _amountLivingNeighbors , bool $ _expectedState ) { $ fieldMock = $ this -> getMockBuilder ( \ GameOfLife \ Field :: class ) -> disableOriginalConstructor ( ) -> getMock ( ) ; $ fieldMock -> expects ( $ this -> exactly ( 1 ) ) -> method ( " isAlive " ) -> willReturn ( $ _initialState ) ; $ fieldMock -> expects ( $ this -> exactly ( 1 ) ) -> method ( " numberOfLivingNeighbors " ) -> willReturn ( $ _amountLivingNeighbors ) ; if ( $ _initialState == $ _expectedState && $ _initialState == false ) { $ fieldMock -> expects ( $ this -> exactly ( 1 ) ) -> method ( " value " ) -> willReturn ( $ _initialState ) ; } $ rule = new ConwayRule ( ) ; if ( $ fieldMock instanceof Field ) { $ newState = $ rule -> calculateNewState ( $ fieldMock ) ; $ this -> assertEquals ( $ _expectedState , $ newState ) ; } }
Checks whether the birth/stay alive rules are correctly applied.
Checks whether the birth / stay alive rules are correctly applied .
// If cell state won't change