package hu.supercluster.gameoflife.game.grid;

import org.junit.Before;
import org.junit.Test;

import hu.supercluster.gameoflife.game.cell.Cell;
import hu.supercluster.gameoflife.game.cell.CellFactory;
import hu.supercluster.gameoflife.game.cell.SimpleCell;
import hu.supercluster.gameoflife.game.cell.SimpleCellFactory;
import hu.supercluster.gameoflife.test.support.UnitTestSpecification;

import static org.fest.assertions.api.Assertions.*;

public class EndlessGridTest extends UnitTestSpecification {
    EndlessGrid<SimpleCell> grid;
    CellFactory<SimpleCell> cellFactory;

    @Before
    public void setup() {
        cellFactory = new SimpleCellFactory();
        grid = new EndlessGrid<>(3, 3, cellFactory);
    }

    @Test
    public void testAllCellsAreDeadByDefault() {
        for (int j = 0; j < grid.getSizeY(); j++) {
            for (int i = 0; i < grid.getSizeX(); i++) {
                assertThat(grid.getCell(i, j).isAlive()).isEqualTo(false);
            }
        }
    }

    @Test
    public void testGetSizeX() {
        assertThat(grid.getSizeX()).isEqualTo(3);
    }

    @Test
    public void testGetSizeY() {
        assertThat(grid.getSizeY()).isEqualTo(3);
    }

    @Test
    public void testNormalizeX() {
        assertThat(grid.normalizeX(-5)).isEqualTo(1);
    }

    @Test
    public void testNormalizeY() {
        assertThat(grid.normalizeY(4)).isEqualTo(1);
    }

    @Test
    public void testPutCell() {
        SimpleCell cell = cellFactory.create(1, 1);
        cell.setState(Cell.STATE_ALIVE);
        grid.putCell(cell);
        assertThat(grid.getCell(4, 4).isAlive()).isTrue();
    }

    @Test
    public void testEquals() {
        EndlessGrid other = null;

        assertThat(grid).isEqualTo(grid);
        assertThat(grid.equals(other)).isFalse();
        assertThat(grid.equals(this)).isFalse();

        other = new EndlessGrid<>(1, 3, cellFactory);
        assertThat(grid).isNotEqualTo(other);

        other = new EndlessGrid<>(3, 1, cellFactory);
        assertThat(grid).isNotEqualTo(other);

        other = new EndlessGrid<>(3, 3, cellFactory);
        other.getCell(1, 1).setState(Cell.STATE_ALIVE);
        assertThat(grid).isNotEqualTo(other);

        grid.getCell(1, 1).setState(Cell.STATE_ALIVE);
        assertThat(grid).isEqualTo(other);
    }
}

@@ -689,33 +689,33 @@
 ndlessGrid%3C%3E(3, 
-3
+6
 , cellFactory);%0A
@@ -1175,33 +1175,33 @@
 eY()).isEqualTo(
-3
+6
 );%0A    %7D%0A%0A    @T
@@ -1380,17 +1380,17 @@
 malizeY(
-4
+7
 )).isEqu
@@ -1604,12 +1604,12 @@
 ell(
-4, 4
+1, 1
 ).is
@@ -1889,17 +1889,17 @@
 id%3C%3E(1, 
-3
+6
 , cellFa
@@ -2091,17 +2091,17 @@
 id%3C%3E(3, 
-3
+6
 , cellFa

Modify EndlessGridTest to test for non-square grid