refactor: NCS-22 NCS-23 reworked modules and tests #17

Merged
Janis merged 42 commits from refactor/NCS-22 into main 2026-04-06 09:07:40 +02:00
2 changed files with 9 additions and 2 deletions
Showing only changes of commit 9e5ef5a059 - Show all commits
@@ -150,16 +150,20 @@ class GameEngine(
game.moves.foreach { histMove =>
handleParsedMove(histMove.from, histMove.to)
histMove.promotionPiece.foreach(completePromotion)
if pendingPromotion.isDefined && histMove.promotionPiece.isEmpty then
// $COVERAGE-OFF$ unreachable: PgnParser.validatePgn ensures promotion annotation is present
if pendingPromotion.isDefined && histMove.promotionPiece.isEmpty then
error = Some(s"Promotion required for move ${histMove.from}${histMove.to}")
break()
// $COVERAGE-ON$
}
}
error match
// $COVERAGE-OFF$ unreachable: error is only set in the unreachable block above
case Some(err) =>
currentContext = savedContext
Left(err)
// $COVERAGE-ON$
case None =>
notifyObservers(PgnLoadedEvent(currentContext))
Right(())
@@ -245,7 +249,9 @@ class GameEngine(
case PieceType.King => "K"
case _ => ""
if isCapture then s"${letter}x${move.to}" else s"$letter${move.to}"
// $COVERAGE-OFF$ unreachable: executeMove is only called after a piece existence check
case None => move.to.toString
// $COVERAGE-ON$
private def computeCaptured(context: GameContext, move: Move): Option[Piece] =
move.moveType match
@@ -2,9 +2,10 @@ package de.nowchess.chess.engine
import de.nowchess.api.board.{Board, Color, File, Piece, PieceType, Rank, Square}
import de.nowchess.api.game.GameContext
import de.nowchess.api.move.{MoveType, PromotionPiece}
import de.nowchess.api.move.{Move, MoveType, PromotionPiece}
import de.nowchess.chess.notation.FenParser
import de.nowchess.chess.observer.*
import de.nowchess.rules.{RuleSet, StandardRules}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers