This repository has been archived on 2021-02-18. You can view files and clone it, but cannot push or open issues or pull requests.
chess/src/test/java/dev/kske/chess/board/FENStringTest.java

88 lines
2.1 KiB
Java

package dev.kske.chess.board;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import dev.kske.chess.board.Piece.Color;
import dev.kske.chess.exception.ChessException;
/**
* Project: <strong>Chess</strong><br>
* File: <strong>FENStringTest.java</strong><br>
* Created: <strong>24 Oct 2019</strong><br>
*
* @author Kai S. K. Engelbart
*/
class FENStringTest {
private List<String> fenStrings = new ArrayList<>();
private List<Board> boards = new ArrayList<>();
/**
* Removes all pieces from a board
*
* @param board the board to clean
*/
void cleanBoard(Board board) {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
board.getBoardArr()[i][j] = null;
}
/**
* @throws java.lang.Exception
*/
@BeforeEach
void setUp() throws Exception {
fenStrings.addAll(
Arrays.asList(
"rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2"
)
);
Board board = new Board();
board.set(Position.fromLAN("c7"), null);
board.set(Position.fromLAN("c5"), new Pawn(Color.BLACK, board));
board.set(Position.fromLAN("e4"), new Pawn(Color.WHITE, board));
board.set(Position.fromLAN("f3"), new Knight(Color.WHITE, board));
board.set(Position.fromLAN("e2"), null);
board.set(Position.fromLAN("g1"), null);
board.getLog().setActiveColor(Color.BLACK);
board.getLog().setHalfmoveClock(1);
board.getLog().setFullmoveNumber(2);
boards.add(board);
}
/**
* Test method for {@link FENString#toString()}.
*/
@Test
void testToString() {
for (int i = 0; i < fenStrings.size(); i++)
assertEquals(
fenStrings.get(i),
new FENString(boards.get(i)).toString()
);
}
/**
* Test method for {@link FENString#getBoard()}.
*
* @throws ChessException
*/
@Test
void testGetBoard() throws ChessException {
for (int i = 0; i < boards.size(); i++)
assertEquals(
boards.get(i),
new FENString(fenStrings.get(i)).getBoard()
);
}
}