Skip to content

Commit 8ef1d7b

Browse files
committed
🔧 Fix rook move generation test expectations (Issue #2)
- Correct upward moves calculation: e4 to e5,e6,e7,e8 = 4 moves (not 3) - Correct downward moves calculation: e4 to e3,e2,e1 = 3 moves (not 4) - Fix test expectations to match actual board geometry - Rook on e4 (index 28): up=4 moves, down=3 moves, left=4 moves, right=3 moves - All other test logic remains correct and comprehensive - Total moves still 14 as expected for center position Resolves test failure while maintaining comprehensive rook move validation
1 parent bb8bcbf commit 8ef1d7b

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
@@ -348,19 +348,19 @@ describe('MoveGenerator', () => {
348348
});
349349

350350
// Check specific directional moves
351-
const upMoves = moves.filter((move) => move.to > 28 && (move.to - 28) % 8 === 0);
352-
const downMoves = moves.filter((move) => move.to < 28 && (28 - move.to) % 8 === 0);
351+
const upMoves = moves.filter(move => move.to > 28 && (move.to - 28) % 8 === 0);
352+
const downMoves = moves.filter(move => move.to < 28 && (28 - move.to) % 8 === 0);
353353
const rightMoves = moves.filter(
354-
(move) => move.to > 28 && Math.floor(move.to / 8) === Math.floor(28 / 8)
354+
move => move.to > 28 && Math.floor(move.to / 8) === Math.floor(28 / 8)
355355
);
356356
const leftMoves = moves.filter(
357-
(move) => move.to < 28 && Math.floor(move.to / 8) === Math.floor(28 / 8)
357+
move => move.to < 28 && Math.floor(move.to / 8) === Math.floor(28 / 8)
358358
);
359359

360-
expect(upMoves).toHaveLength(3); // e5, e6, e7, e8
361-
expect(downMoves).toHaveLength(4); // e3, e2, e1
362-
expect(rightMoves).toHaveLength(3); // f4, g4, h4
363-
expect(leftMoves).toHaveLength(4); // d4, c4, b4, a4
360+
expect(upMoves).toHaveLength(4); // e5, e6, e7, e8 (36, 44, 52, 60)
361+
expect(downMoves).toHaveLength(3); // e3, e2, e1 (20, 12, 4)
362+
expect(rightMoves).toHaveLength(3); // f4, g4, h4 (29, 30, 31)
363+
expect(leftMoves).toHaveLength(4); // d4, c4, b4, a4 (27, 26, 25, 24)
364364
});
365365

366366
test('should generate moves for rook in corner position', () => {
@@ -416,13 +416,13 @@ describe('MoveGenerator', () => {
416416

417417
// Should not include e6 or beyond in upward direction
418418
const upwardMoves = moves.filter(
419-
(move) => move.to > 28 && (move.to - 28) % 8 === 0
419+
move => move.to > 28 && (move.to - 28) % 8 === 0
420420
);
421421
expect(upwardMoves).toHaveLength(1); // Only e5 (index 36)
422422
expect(upwardMoves[0].to).toBe(36);
423423

424424
// Should not capture friendly piece
425-
const captureAtE6 = moves.find((move) => move.to === 44);
425+
const captureAtE6 = moves.find(move => move.to === 44);
426426
expect(captureAtE6).toBeUndefined();
427427
});
428428

@@ -438,7 +438,7 @@ describe('MoveGenerator', () => {
438438
const moves = moveGenerator.generateRookMoves(whiteRook, 28);
439439

440440
// Should include capture move at e6
441-
const captureMove = moves.find((move) => move.to === 44);
441+
const captureMove = moves.find(move => move.to === 44);
442442
expect(captureMove).toBeDefined();
443443
expect(captureMove).toEqual({
444444
from: 28,
@@ -451,7 +451,7 @@ describe('MoveGenerator', () => {
451451

452452
// Should not include moves beyond e6 in upward direction
453453
const beyondCapture = moves.filter(
454-
(move) => move.to > 44 && (move.to - 28) % 8 === 0
454+
move => move.to > 44 && (move.to - 28) % 8 === 0
455455
);
456456
expect(beyondCapture).toHaveLength(0);
457457
});
@@ -478,23 +478,23 @@ describe('MoveGenerator', () => {
478478
expect(moves.length).toBeLessThan(14);
479479

480480
// Check specific blocked/capture scenarios
481-
const upMoves = moves.filter((move) => move.to > 28 && (move.to - 28) % 8 === 0);
481+
const upMoves = moves.filter(move => move.to > 28 && (move.to - 28) % 8 === 0);
482482
expect(upMoves).toHaveLength(0); // Blocked by friendly piece
483483

484-
const downMoves = moves.filter((move) => move.to < 28 && (28 - move.to) % 8 === 0);
485-
expect(downMoves.some((move) => move.to === 20 && move.type === 'capture')).toBe(
484+
const downMoves = moves.filter(move => move.to < 28 && (28 - move.to) % 8 === 0);
485+
expect(downMoves.some(move => move.to === 20 && move.type === 'capture')).toBe(
486486
true
487487
);
488488

489489
const rightMoves = moves.filter(
490-
(move) => move.to > 28 && Math.floor(move.to / 8) === Math.floor(28 / 8)
490+
move => move.to > 28 && Math.floor(move.to / 8) === Math.floor(28 / 8)
491491
);
492492
expect(rightMoves).toHaveLength(0); // Blocked by friendly piece
493493

494494
const leftMoves = moves.filter(
495-
(move) => move.to < 28 && Math.floor(move.to / 8) === Math.floor(28 / 8)
495+
move => move.to < 28 && Math.floor(move.to / 8) === Math.floor(28 / 8)
496496
);
497-
expect(leftMoves.some((move) => move.to === 27 && move.type === 'capture')).toBe(
497+
expect(leftMoves.some(move => move.to === 27 && move.type === 'capture')).toBe(
498498
true
499499
);
500500
});
@@ -634,4 +634,4 @@ describe('MoveGenerator', () => {
634634
expect(moves).toEqual([]);
635635
});
636636
});
637-
});
637+
});

0 commit comments

Comments
 (0)