test: add tests

This commit is contained in:
Cozma Rares
2023-04-07 01:51:43 +03:00
parent 3fc3502826
commit d74ca3dbcb
2 changed files with 71 additions and 0 deletions
@@ -0,0 +1,51 @@
import { describe, expect, test } from "vitest";
import Chess, { COLOR, PIECE } from "../../chess/engine";
describe("valid FEN strings", () => {
test("default", () => {
const builder = new Chess.Builder();
builder.addPiece("a1", { color: COLOR.WHITE, type: PIECE.ROOK });
builder.addPiece("b1", { color: COLOR.WHITE, type: PIECE.KNIGHT });
builder.addPiece("c1", { color: COLOR.WHITE, type: PIECE.BISHOP });
builder.addPiece("d1", { color: COLOR.WHITE, type: PIECE.QUEEN });
builder.addPiece("e1", { color: COLOR.WHITE, type: PIECE.KING });
builder.addPiece("f1", { color: COLOR.WHITE, type: PIECE.BISHOP });
builder.addPiece("g1", { color: COLOR.WHITE, type: PIECE.KNIGHT });
builder.addPiece("h1", { color: COLOR.WHITE, type: PIECE.ROOK });
builder.addPiece("a2", { color: COLOR.WHITE, type: PIECE.PAWN });
builder.addPiece("b2", { color: COLOR.WHITE, type: PIECE.PAWN });
builder.addPiece("c2", { color: COLOR.WHITE, type: PIECE.PAWN });
builder.addPiece("d2", { color: COLOR.WHITE, type: PIECE.PAWN });
builder.addPiece("e2", { color: COLOR.WHITE, type: PIECE.PAWN });
builder.addPiece("f2", { color: COLOR.WHITE, type: PIECE.PAWN });
builder.addPiece("g2", { color: COLOR.WHITE, type: PIECE.PAWN });
builder.addPiece("h2", { color: COLOR.WHITE, type: PIECE.PAWN });
builder.addPiece("a8", { color: COLOR.BLACK, type: PIECE.ROOK });
builder.addPiece("b8", { color: COLOR.BLACK, type: PIECE.KNIGHT });
builder.addPiece("c8", { color: COLOR.BLACK, type: PIECE.BISHOP });
builder.addPiece("d8", { color: COLOR.BLACK, type: PIECE.QUEEN });
builder.addPiece("e8", { color: COLOR.BLACK, type: PIECE.KING });
builder.addPiece("f8", { color: COLOR.BLACK, type: PIECE.BISHOP });
builder.addPiece("g8", { color: COLOR.BLACK, type: PIECE.KNIGHT });
builder.addPiece("h8", { color: COLOR.BLACK, type: PIECE.ROOK });
builder.addPiece("a7", { color: COLOR.BLACK, type: PIECE.PAWN });
builder.addPiece("b7", { color: COLOR.BLACK, type: PIECE.PAWN });
builder.addPiece("c7", { color: COLOR.BLACK, type: PIECE.PAWN });
builder.addPiece("d7", { color: COLOR.BLACK, type: PIECE.PAWN });
builder.addPiece("e7", { color: COLOR.BLACK, type: PIECE.PAWN });
builder.addPiece("f7", { color: COLOR.BLACK, type: PIECE.PAWN });
builder.addPiece("g7", { color: COLOR.BLACK, type: PIECE.PAWN });
builder.addPiece("h7", { color: COLOR.BLACK, type: PIECE.PAWN });
const expected = builder.build();
const chess = Chess.load();
for (let i = 0; i < 64; i++)
expect(chess.getPiece(i)).toEqual(expected.getPiece(i));
});
});
@@ -6,6 +6,26 @@ describe("valid FEN strings", () => {
expect(validateFEN(DEFAULT_POSITION)).toBe(undefined);
});
test("1. e4", () => {
expect(
validateFEN("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1")
).toBe(undefined);
});
test("2. e5", () => {
expect(
validateFEN(
"rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e6 0 2"
)
).toBe(undefined);
});
test("3. ke2", () => {
expect(
validateFEN("rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPPKPPP/RNBQ1BNR b kq - 1 2")
).toBe(undefined);
});
test("random position 1", () => {
expect(
validateFEN("r1b1r1k1/pp4pp/3Bpp2/8/2q5/P5Q1/3R1PPP/R5K1 b - - 0 19")