Add rules-engine tests: check, mate, stalemate, castling, en passant, undo
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- testing-qa
Research direction
Read tests/unit/game-moves.test.js and tests/integration/game-flow.test.js, then inspect the named move and piece logic in js/game.js and js/pieces.js. Start with the helper from issue #40 and run npm test; the issue lists the expected rule cases and outcomes. Done means every listed case has a test and forcing isCheckmate to return false makes the suite fail.
Written by the indexing model from the issue text.
Description
Summary
The suite has four tests, and the only two that touch game logic both play e2 to e4. Check, checkmate, stalemate, castling, en passant, promotion, pins, notation and undo are untested.
Where
tests/unit/game-moves.test.js:111-116,tests/integration/game-flow.test.js:118-126- Untested:
js/game.js:281-300,js/game.js:334-461,js/game.js:497-520,js/game.js:582-650,js/game.js:845-906,js/pieces.js:41-96
Impact
js/game.js is about a third of the code base and is the product. Regressions in move legality or game-end detection ship with CI green, which has already happened (#22, #24, #25).
Suggested fix
Using the helper from #40, add:
- Perft from the start position: White has 20 legal moves; after 1.e4, Black has 20
-
isPseudoLegalMovetable tests per piece: knight L-shapes, bishop off-diagonal rejected, pawn backward rejected, double push only from the start rank, same square rejected - Sliders are blocked by own and enemy pieces
- A pinned piece has no moves that expose the king (white Ke1, Re2, black Re8)
- In check, only moves that resolve it are legal
- Fool's mate (f3 e5 g4 Qh4): status "Checkmate! Black wins.", notation
Qh4# - Stalemate (white Kf7, Qg6, black Kh8, Black to move): status "Stalemate! Game is a draw."
- Castling: allowed both sides when clear; refused in check, through an attacked square, after the king or rook moved, with a piece between; notation
O-OandO-O-O - Queenside castling with only the b-file square attacked is allowed
- En passant: offered only right after the double push, removes the captured pawn, not offered when it exposes the king
- Promotion: h7 to h8 becomes a queen, notation
h8=Q - SAN disambiguation:
Nbd2for two knights,R1a3for two rooks on one file - Undo after a plain move, a capture, castling, en passant, a double push and a promotion restores the exact prior state
-
handleBoardClickignores the opponent's pieces and all clicks after game over
Some of these should fail until the linked bugs are fixed; write them to the chess rule.
Acceptance criteria
- Each item above has a test
- Making
isCheckmatereturnfalseunconditionally fails the suite
Getting started
- Relevant files:
js/game.js,js/pieces.js,tests/unit/ - How to run tests:
npm install, thennpm testandnpm run lint - Related docs:
docs/ARCHITECTURE.md,.github/CONTRIBUTING.md
Filed by repo-audit/full-audit at 8a2c86c. Severity: medium. Effort: M. audit-key: testing|js/game.js|generateLegalMovesForPiece
- Dominant language
- JavaScript
- Stars
- 4
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TMHSDigital/Static_Chess
-
enhancement good first issue severity: medium
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
TMHSDigital/Static_Chess#53 ·
-
documentation good first issue severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
TMHSDigital/Static_Chess#49 ·
-
documentation good first issue severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
TMHSDigital/Static_Chess#48 ·
-
documentation severity: medium
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
TMHSDigital/Static_Chess#47 ·
-
documentation good first issue severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
TMHSDigital/Static_Chess#46 ·
All issues in TMHSDigital/Static_Chess
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
good first issue tests
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug role: dev-lead
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
briangwalker/TrussExplorer#424 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
eliasstravik/herdr-projects#1032 ·
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 90/100