public void TestTurnOffFor2NeighborsWhenNotAlreadyOn()
    {
        Boolean turnOffCalled = false;

        CellLogic.TurnOff turnOff = (() => { turnOffCalled = true; });

        CellLogic underTest = new CellLogic(null, turnOff, false);

        underTest.checkForNeighbors(2);

        UUnitAssert.True(turnOffCalled);
    }
Exemple #2
0
    public void shouldCallAllCells()
    {
        FieldLogic underTest          = new FieldLogic(3, 3);
        int        timesTurnOffCalled = 0;

        CellLogic.TurnOff testTurnOff = () => { timesTurnOffCalled++; };
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOn), 0, 0);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOff), 0, 1);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOn), 0, 2);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOff), 1, 0);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOff), 1, 1);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOff), 1, 2);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOn), 2, 0);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOff), 2, 1);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOn), 2, 2);

        underTest.Iterate();

        UUnitAssert.Equals(9, timesTurnOffCalled);
    }
Exemple #3
0
    public void shouldCellDieWithTooManyNeighbors()
    {
        FieldLogic underTest     = new FieldLogic(3, 3);
        bool       turnOffCalled = false;

        CellLogic.TurnOff testTurnOff = () => { turnOffCalled = true; };
        underTest.AddCellAt(new CellLogic(emptyTurnOn, emptyTurnOff, cellOn), 0, 0);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, emptyTurnOff, cellOn), 0, 1);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, emptyTurnOff, cellOn), 0, 2);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, emptyTurnOff, cellOn), 1, 0);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, testTurnOff, cellOn), 1, 1);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, emptyTurnOff, cellOn), 1, 2);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, emptyTurnOff, cellOn), 2, 0);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, emptyTurnOff, cellOff), 2, 1);
        underTest.AddCellAt(new CellLogic(emptyTurnOn, emptyTurnOff, cellOn), 2, 2);

        underTest.Iterate();

        UUnitAssert.True(turnOffCalled);
    }
    void AddCellAt(int i, int j)
    {
        GUITexture texture = (GUITexture)Instantiate(baseBlock);

        texture.pixelInset = new Rect(i * 50, j * 50, 50, 50);
        CellLogic.TurnOn  turnOn  = (() => { texture.texture = onTexture; });
        CellLogic.TurnOff turnOff = () => { texture.texture = offTexture; };

        bool isOn = false;

        if (Random.Range(0, 2) == 0)
        {
            texture.texture = onTexture;
            isOn            = true;
        }
        else
        {
            texture.texture = offTexture;
        }
        fieldLogic.AddCellAt(new CellLogic(turnOn, turnOff, isOn), i, j);
    }