Commit Graph

20 Commits

Author SHA1 Message Date
Janis d2c22337aa refactor(tests): improve CommandInvoker tests for clarity and coverage
Build & Test (NowChessSystems) TeamCity build failed
2026-04-05 22:44:53 +02:00
Janis 3cec5b8898 refactor(tests): enhance test coverage for move application and piece movement logic 2026-04-05 22:03:40 +02:00
Janis 4cf39e3e97 refactor(core): enhance castling logic to include rook movement and improve safety checks 2026-04-05 19:17:23 +02:00
Janis 2cd3ea35f6 refactor(tests): improve FEN and PGN parser test cases for clarity and coverage 2026-04-05 18:41:26 +02:00
Janis 1fc5e43e77 refactor(core): enhance MoveType to support capture flag and update related logic
Build & Test (NowChessSystems) TeamCity build failed
2026-04-05 17:28:56 +02:00
Janis 432385c7b0 refactor(core): replace GameHistory with HistoryMove in PGN export logic 2026-04-05 17:08:54 +02:00
Janis 17fa13c82a test(core): add GameEngineLoadGameTest for loadGame/exportGame
Add 3 focused tests for GameEngine load/export functionality:
- loadGame with PgnParser validates PGN parsing and undo/redo state
- loadGame with FenParser validates position loading without move replay
- exportGame with PgnExporter validates PGN output

Fix: PgnParser now extends GameContextImport trait for consistency with FenParser.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 15:22:04 +02:00
Janis 8b5303fdab test(io): add exportGameContext tests
Add two simple tests for exportGameContext functionality:
1. Test that moves are preserved in PGN output
2. Test that empty game exports headers with proper terminator

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:45:25 +02:00
Janis 16a9632e69 fix(io): add error handling for missing piece in PgnExporter replay
Replace unsafe fallback to Pawn with explicit exception on invariant
violation. This ensures data corruption in GameContext.moves is detected
immediately rather than producing silently incorrect PGN output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:22:13 +02:00
Janis 09a70ed435 feat(io): implement PgnExporter.exportGameContext with move replay
PgnExporter now extends GameContextExport and implements exportGameContext,
which replays moves from GameContext.initial to reconstruct HistoryMove records
with proper castling/promotion info before generating PGN.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:20:59 +02:00
Janis f0316013fc test(io): add importGameContext tests to PgnParserTest
Added three test cases to validate importGameContext method:
1. Valid PGN with moves returns Right with populated GameContext
2. Invalid PGN (illegal move) returns Left with error message
3. PGN with no moves returns Right with initial position

Tests use coordinate notation (e.g., e2e4) compatible with importGameContext's move replay mechanism.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:19:55 +02:00
Janis 2d07f1f75a refactor(io): remove dead code from PgnParser.importGameContext
Remove unnecessary if/else check (lines 49-50) that could never be true.
DefaultRules.applyMove always calls .withMove(move) on the context,
so finalCtx.moves is always populated when game.moves.nonEmpty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:15:41 +02:00
Janis 7c42260d14 feat(io): implement PgnParser.importGameContext with move replay
Implement the importGameContext method to validate PGN input via validatePgn()
and replay each move using DefaultRules.applyMove to populate GameContext.moves.
Returns final GameContext with all moves applied or error message on failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:14:25 +02:00
Janis 9f48f7afeb test(io): add comprehensive error path coverage to FenParserTest
Added 3 new tests for missing error paths:
- Invalid en passant square parsing (e.g., "x5")
- Half-move clock non-integer (e.g., "abc")
- Full-move number non-integer (e.g., "abc")

Updated 3 existing error tests to verify error messages:
- "expected 6" for invalid parts count
- "color" for invalid active color
- "castling" for invalid castling rights

All error assertions now use .fold() to verify message content, improving test robustness. Test count increased from 19 to 22.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:12:19 +02:00
Janis 3214386556 fix(io): update FEN tests to use Either API after parseFen signature change
FenParser.parseFen now returns Either[String, GameContext] instead of Option.
Updated all tests to use Either combinators (isRight, isLeft, fold) instead
of Option methods (isDefined, get). Both FenParserTest and FenExporterTest
now properly handle the Either-based return type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 13:10:24 +02:00
Janis c0a3592d3d refactor(io): implement FenParser.parseFen returning Either with detailed error messages
Update parseFen to return Either[String, GameContext] with specific error messages for each validation failure:
- Invalid parts count: reports expected 6 fields
- Invalid board: clear message about board position
- Invalid color: explains expected 'w' or 'b'
- Invalid castling, en passant, and move counts with clear descriptions

Simplify importGameContext to delegate directly to parseFen.

Keep helper methods (parseColor, parseCastling, parseEnPassant, etc.) returning Option as before.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:58:15 +02:00
Janis 6fcb880b93 fix(io): update GameContextExport to Scala 3 syntax and add importGameContext tests
- Update GameContextExport trait to use Scala 3 syntax (colon-based) to match GameContextImport
- Add test coverage for FenParser.importGameContext method:
  * Valid FEN string returns Right[GameContext] with correct context data
  * Invalid FEN string returns Left[String] with error message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:43:25 +02:00
Janis f6f05ff2a1 refactor(io): change GameContextImport return type from Option to Either
Update GameContextImport trait to return Either[String, GameContext] instead of
Option[GameContext] to provide better error context during parsing. Update FenParser
implementation to convert Option to Either using toRight().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 12:33:13 +02:00
Janis 9b3bbfbcb7 refactor(core): integrate Rule module and update GameContext handling 2026-04-04 20:25:20 +02:00
Janis 6def31dd80 refactor(core): add IO module and integrate GameContext import/export traits 2026-04-04 19:50:08 +02:00