Package pl.michalostruszka.gameoflife.board

Source Code of pl.michalostruszka.gameoflife.board.BoardTest

package pl.michalostruszka.gameoflife.board;

import org.junit.Test;
import pl.michalostruszka.gameoflife.board.Board;
import pl.michalostruszka.gameoflife.cell.LiveCell;

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

public class BoardTest {

    private static final Board EMPTY_BOARD = new Board();
    private Board board;

    @Test
    public void emptyBoardShouldHaveNoLiveNeighboursForAnyCell() throws Exception {
        int result = EMPTY_BOARD.countLiveNeighboursOf(LiveCell.at(0, 0));
        assertThat(result).isZero();
    }

    @Test
    public void countLiveNeighboursForGivenCell() throws Exception {
        board = Board.seedWith(LiveCell.at(1, 0), LiveCell.at(1, 1));
        int result = board.countLiveNeighboursOf(LiveCell.at(0, 0));
        assertThat(result).isEqualTo(2);
    }

    @Test
    public void shouldEvaluateNextBoardState() throws Exception {
        board = Board.seedWith(LiveCell.at(0, 0), LiveCell.at(1, 0), LiveCell.at(1, 1));
        Board next = board.nextState();
        assertThat(next.liveCells()).containsOnly(LiveCell.at(0, 0), LiveCell.at(0, 1), LiveCell.at(1, 1), LiveCell.at(1, 0));
    }
}
TOP

Related Classes of pl.michalostruszka.gameoflife.board.BoardTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.