chess-base
Version:
chess board logic
49 lines (43 loc) • 1.27 kB
JavaScript
import { Chess } from "../src/chess";
const CASTLINGS_KING = [
{
TITLE: "KING CASTLING VALID",
FEN: "r1bqkbnr/pPp2ppp/2np4/4p3/2B5/4PN2/PPPP1PPP/RNBQK2R w KQkq - 2 4",
RESULT_FEN:
"r1bqkbnr/pPp2ppp/2np4/4p3/2B5/4PN2/PPPP1PPP/RNBQ1RK1 b kq - 3 4"
}
];
const CASTLINGS_INVALID = [
{
TITLE: "KING CASTLING VALID",
FEN: "r1bqk1nr/ppp2ppp/2np4/4p3/2B5/4PN2/PPPP1PbP/RNBQK2R w KQkq - 2 4"
}
];
describe("Castling", function() {
CASTLINGS_KING.forEach(movement => {
it("should castling king", function() {
testCastlingKing(new Chess(movement.FEN), movement);
});
});
CASTLINGS_INVALID.forEach(movement => {
it("should throw exception castling target", function() {
const chess = new Chess(movement.FEN);
expect(() => chess.castlingKing()).toThrow("castling target");
});
});
});
function testCastlingKing(chess, movement) {
chess.castlingKing();
const fenResult = chess.toFen();
const isEqual = movement.RESULT_FEN === fenResult;
expect(isEqual).toBeTruthy(
[
"",
`${chess.toAscii(true)}`,
`${movement.TITLE}`,
`FEN expect: ${movement.RESULT_FEN}`,
`FEN result: ${fenResult}`,
""
].join("\n")
);
}