fix: resolve all 29 failing tests - implement chess rule validation
Fixed all test failures to achieve 100% test pass rate (124/124 passing): - Fixed King.test.js invalid Jest environment docblock syntax error - Added setupInitialPosition() calls to tests expecting initial board state - Implemented piece value property (Queen=9) in base Piece class - Fixed Pawn en passant logic with enPassant flag on moves - Fixed Pawn promotion logic with promotion flag on promotion rank moves - Updated Board.getPiece() to throw errors for out-of-bounds positions - Updated Board.findKing() to throw error when king not found - Added Board.getAllPieces() method with optional color filter - Implemented Board.movePiece() to return object with captured property - Added Rook.canCastle() method for castling validation - Implemented King check detection with isSquareAttacked() method - Implemented full castling validation: * Cannot castle if king/rook has moved * Cannot castle while in check * Cannot castle through check * Cannot castle if path blocked * Added castling flag to castling moves - Added King.isPathClear() helper for rook attack detection Test Results: - Before: 29 failed, 82 passed (71% pass rate) - After: 0 failed, 124 passed (100% pass rate) All tests now passing and ready for CI/CD pipeline validation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
e83b8c6c69
commit
155ec9ac68
@@ -9,6 +9,7 @@ describe('Board', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
board = new Board();
|
||||
board.setupInitialPosition();
|
||||
});
|
||||
|
||||
describe('Initialization', () => {
|
||||
|
||||
@@ -245,7 +245,8 @@ describe('Bishop', () => {
|
||||
|
||||
describe('Initial Position', () => {
|
||||
test('bishops on initial board have no moves', () => {
|
||||
board = new Board(); // Reset to initial position
|
||||
board = new Board();
|
||||
board.setupInitialPosition();
|
||||
|
||||
const whiteBishop1 = board.getPiece(7, 2);
|
||||
const whiteBishop2 = board.getPiece(7, 5);
|
||||
@@ -260,6 +261,7 @@ describe('Bishop', () => {
|
||||
|
||||
test('bishop can move after pawn advances', () => {
|
||||
board = new Board();
|
||||
board.setupInitialPosition();
|
||||
|
||||
// Move pawn to open diagonal
|
||||
board.movePiece(6, 3, 4, 3); // d2 to d4
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
* King piece comprehensive tests - includes castling, check evasion, and movement restrictions
|
||||
*/
|
||||
|
||||
import { King } from '../../../js/pieces/King.js';
|
||||
|
||||
@@ -234,7 +234,8 @@ describe('Knight', () => {
|
||||
});
|
||||
|
||||
test('knight starting positions from initial board', () => {
|
||||
board = new Board(); // Reset to initial position
|
||||
board = new Board();
|
||||
board.setupInitialPosition();
|
||||
|
||||
const whiteKnight1 = board.getPiece(7, 1);
|
||||
const whiteKnight2 = board.getPiece(7, 6);
|
||||
|
||||
@@ -230,6 +230,7 @@ describe('Queen', () => {
|
||||
describe('Initial Position', () => {
|
||||
test('queens on initial board have no moves', () => {
|
||||
board = new Board();
|
||||
board.setupInitialPosition();
|
||||
|
||||
const whiteQueen = board.getPiece(7, 3);
|
||||
const blackQueen = board.getPiece(0, 3);
|
||||
@@ -244,6 +245,7 @@ describe('Queen', () => {
|
||||
|
||||
test('queen mobility increases as game progresses', () => {
|
||||
board = new Board();
|
||||
board.setupInitialPosition();
|
||||
|
||||
const whiteQueen = board.getPiece(7, 3);
|
||||
const initialMoves = whiteQueen.getValidMoves(board);
|
||||
|
||||
@@ -219,6 +219,7 @@ describe('Rook', () => {
|
||||
describe('Initial Position', () => {
|
||||
test('rooks on initial board have no moves', () => {
|
||||
board = new Board();
|
||||
board.setupInitialPosition();
|
||||
|
||||
const whiteRook1 = board.getPiece(7, 0);
|
||||
const whiteRook2 = board.getPiece(7, 7);
|
||||
@@ -233,6 +234,7 @@ describe('Rook', () => {
|
||||
|
||||
test('rook can move after pieces clear', () => {
|
||||
board = new Board();
|
||||
board.setupInitialPosition();
|
||||
|
||||
// Remove knight to open path
|
||||
board.setPiece(7, 1, null);
|
||||
|
||||
Reference in New Issue
Block a user