feat: NCS-16 Core Separation via Patterns #10

Merged
Janis merged 20 commits from feat/GUI-UI-Core-Separation into main 2026-03-31 10:31:03 +02:00

20 Commits

Author SHA1 Message Date
Janis 9f0e2b0a14 test: add tests for undo and redo notifications in GameEngine
Build & Test (NowChessSystems) TeamCity build finished
2026-03-31 10:10:09 +02:00
Janis 5fab97ec10 fix: improve TerminalUI coverage and make MoveCommand/ResetCommand immutable
**TerminalUI Coverage Fix:**
- Added explicit test for empty input case (lines 64-65 previously uncovered)
- Test "TerminalUI should explicitly handle empty input by re-prompting" validates
  that multiple empty inputs are properly handled by re-prompting
- UI module coverage improved to near-100%

**MoveCommand Immutability (Anti-pattern Fix):**
- Changed MoveCommand fields from var to val: moveResult, previousBoard,
  previousHistory, previousTurn
- Changed ResetCommand fields from var to val: previousBoard, previousHistory,
  previousTurn
- Updated GameEngine to use .copy() instead of direct mutation when updating
  command state (lines 88, 95, 103, 112)
- Removed 3 edge-case tests that relied on command mutation (now impossible with
  immutable fields)

**MoveCommand Immutability Tests:**
- Added MoveCommandImmutabilityTest to verify:
  - Fields cannot be mutated after creation
  - equals/hashCode respect immutability invariant
  - .copy() creates new instances with updated values

All tests pass; 100% core coverage maintained.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-31 10:10:09 +02:00
Janis 288a1c5ac3 fix: add thread-safety synchronization to Observable and CommandInvoker
Test-driven fixes for code review blockers NCS-16:

**Observable (CRITICAL):** Added synchronized blocks to subscribe, unsubscribe,
notifyObservers, and observerCount to prevent race conditions when concurrent
threads register observers while notifications are dispatched.

**CommandInvoker (IMPORTANT):** Added synchronized blocks to all methods
(execute, undo, redo, history, getCurrentIndex, canUndo, canRedo, clear) to
ensure atomic access to mutable state (executedCommands, currentIndex).

Tests:
- Added ObservableThreadSafetyTest: 3 tests for concurrent subscribe/unsubscribe/notify
- Added CommandInvokerThreadSafetyTest: 2 tests for concurrent execute/undo/redo
- All 54 existing tests remain green
- Full build passes with 100% core coverage

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-31 10:10:09 +02:00
Janis 2ee201abe1 refactor: simplify undo and redo logic in GameEngine and removed Hacky Test 2026-03-31 10:10:09 +02:00
shahdlala66 94981d9cff test: added UI model tests 2026-03-31 10:10:09 +02:00
shahdlala66 fb46dc9d7d fix: PR issues fixed 2026-03-31 10:10:09 +02:00
shahdlala66 0458688409 test: 100% 2026-03-31 10:10:09 +02:00
shahdlala66 f290bc5895 fix: removing the scala metal folder 2026-03-31 10:10:09 +02:00
shahdlala66 81b83fc81d fix: removing metal folder 2026-03-31 10:10:09 +02:00
shahdlala66 cfe0e80414 test: reached 99% for GameEngine 2026-03-31 10:10:09 +02:00
shahdlala66 6a04b79517 test: more branch coverage for CommandInvoker 2026-03-31 10:10:09 +02:00
shahdlala66 1f3a653bcd feat: undo/redo added 2026-03-31 10:10:09 +02:00
shahdlala66 bbe53905c3 feat: core sepration, observer added 2026-03-31 10:10:09 +02:00
Janis 8fa44bdb81 feat: enhance FEN and PGN parsers with additional test cases and coverage improvements 2026-03-31 10:10:09 +02:00
Janis 9924a461da style: replace .isDefined/.get with pattern matching in PgnParser
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 10:10:09 +02:00
Janis 189c268892 feat: add PGN exporter for game notation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 10:10:09 +02:00
Janis bda1109e01 feat: add PGN parser with algebraic move notation
Implements PgnParser with parsePgn(), parseAlgebraicMove(), and move
resolution using geometric piece reachability with disambiguation support
for piece type, file, and rank hints.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-31 10:10:09 +02:00
Janis 8747fad282 feat: add full FEN parsing with GameState support
Implements parseFen() in FenParser and gameStateToFen() in FenExporter,
covering all 6 FEN fields (piece placement, active color, castling,
en passant, half-move clock, full-move number).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 10:10:09 +02:00
Janis 2974029473 feat: add FEN exporter and round-trip tests
Implements FenExporter.boardToFen() converting Board to FEN piece-placement string,
and adds three round-trip tests (initial position, empty board, partial position).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 10:10:09 +02:00
Janis 2925c385bc feat: add FEN piece-placement parser
Implements FenParser.parseBoard() to parse FEN piece-placement strings
into a Board, with proper None propagation on invalid input.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 10:10:09 +02:00