Skip to content

Commit 0eedf90

Browse files
committed
🐛 Fix knight move generation test suite (Issue #9)
- Corrected the failing test case for `isValidKnightMove()` - The previous test used an incorrect square index (22 instead of 16) that resulted in a valid move being tested as invalid - The test now correctly validates the wrapping prevention logic for knight moves as intended - All other knight move generation tests remain in place - The test suite should now pass without errors
1 parent 829ee89 commit 0eedf90

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

tests/core/MoveGenerator.test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -744,68 +744,68 @@ describe('MoveGenerator', () => {
744744
test('should generate all 8 moves for knight in center of empty board', () => {
745745
const knight = new Piece('knight', 'white', 3, '♘');
746746
board.squares[28] = knight; // e4
747-
747+
748748
const moves = moveGenerator.generateKnightMoves(knight, 28);
749749
expect(moves).toHaveLength(8);
750750
});
751-
751+
752752
test('should generate 2 moves for knight in corner (a1)', () => {
753753
const knight = new Piece('knight', 'white', 3, '♘');
754754
board.squares[56] = knight; // a1
755-
755+
756756
const moves = moveGenerator.generateKnightMoves(knight, 56);
757757
expect(moves).toHaveLength(2);
758-
const destinations = moves.map((m) => m.to);
758+
const destinations = moves.map(m => m.to);
759759
expect(destinations).toEqual(expect.arrayContaining([41, 50])); // c2, b3
760760
});
761-
761+
762762
test('should generate 4 moves for knight on edge (a4)', () => {
763763
const knight = new Piece('knight', 'white', 3, '♘');
764764
board.squares[32] = knight; // a4
765-
765+
766766
const moves = moveGenerator.generateKnightMoves(knight, 32);
767767
expect(moves).toHaveLength(4);
768768
});
769-
769+
770770
test('should not be blocked by surrounding pieces', () => {
771771
const knight = new Piece('knight', 'white', 3, '♘');
772772
board.squares[28] = knight; // e4
773-
773+
774774
// Surround the knight
775775
board.squares[27] = new Piece('pawn', 'black', 1, '♟'); // d4
776776
board.squares[29] = new Piece('pawn', 'black', 1, '♟'); // f4
777777
board.squares[36] = new Piece('pawn', 'black', 1, '♟'); // e5
778778
board.squares[20] = new Piece('pawn', 'black', 1, '♟'); // e3
779-
779+
780780
const moves = moveGenerator.generateKnightMoves(knight, 28);
781781
expect(moves).toHaveLength(8); // Still has 8 moves
782782
});
783-
783+
784784
test('should capture enemy pieces but not land on friendly pieces', () => {
785785
const knight = new Piece('knight', 'white', 3, '♘');
786786
board.squares[28] = knight; // e4
787-
787+
788788
// Friendly piece at one destination
789789
board.squares[11] = new Piece('pawn', 'white', 1, '♙'); // d2, blocks one move
790790
// Enemy piece at another
791791
board.squares[13] = new Piece('pawn', 'black', 1, '♟'); // f2, can be captured
792-
792+
793793
const moves = moveGenerator.generateKnightMoves(knight, 28);
794794
expect(moves).toHaveLength(7); // 8 possible moves - 1 blocked by friendly
795-
796-
const captureMove = moves.find((m) => m.to === 13);
795+
796+
const captureMove = moves.find(m => m.to === 13);
797797
expect(captureMove).toBeDefined();
798798
expect(captureMove.type).toBe('capture');
799799
expect(captureMove.captured).toBe('pawn');
800800
});
801-
801+
802802
test('isValidKnightMove should prevent wrapping', () => {
803803
// Valid moves
804804
expect(moveGenerator.isValidKnightMove(0, 10)).toBe(true); // a8 to b6
805805
expect(moveGenerator.isValidKnightMove(28, 11)).toBe(true); // e4 to d2
806-
806+
807807
// Invalid moves (wrapping from h-file to a-file)
808-
expect(moveGenerator.isValidKnightMove(7, 22)).toBe(false); // h8 to a6
808+
expect(moveGenerator.isValidKnightMove(7, 16)).toBe(false); // h8 to a6
809809
expect(moveGenerator.isValidKnightMove(15, 25)).toBe(false); // h7 to b5
810810
});
811811
});
@@ -858,9 +858,9 @@ describe('MoveGenerator', () => {
858858
test('should route to correct piece-specific method for knight', () => {
859859
const whiteKnight = new Piece('knight', 'white', 3, '♘');
860860
board.squares[28] = whiteKnight;
861-
861+
862862
const moves = moveGenerator.generateMoves(whiteKnight, 28);
863-
863+
864864
expect(moves.length).toBeGreaterThan(0);
865865
expect(moves[0].piece).toBe('knight');
866866
});

0 commit comments

Comments
 (0)