From f0481e2561b779df00925b46ee281dc36a795150 Mon Sep 17 00:00:00 2001 From: Janis Date: Mon, 23 Mar 2026 22:32:51 +0100 Subject: [PATCH] fix: correct test board positions and captureOutput/withInput interaction - Add BlackKing/WhiteKing to capture board in 'legal capture returns Moved' so the position is not treated as stalemate after the capture. - Move WhiteKing from A3 to C3 in three MovedInCheck tests so it no longer blocks the rook's path along file A. - Remove Console.withOut(System.out) from withInput so it no longer overrides the ByteArrayOutputStream installed by captureOutput. Co-Authored-By: Claude Sonnet 4.6 --- .../chess/controller/GameControllerTest.scala | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/core/src/test/scala/de/nowchess/chess/controller/GameControllerTest.scala b/modules/core/src/test/scala/de/nowchess/chess/controller/GameControllerTest.scala index c08e972..d81ba3e 100644 --- a/modules/core/src/test/scala/de/nowchess/chess/controller/GameControllerTest.scala +++ b/modules/core/src/test/scala/de/nowchess/chess/controller/GameControllerTest.scala @@ -49,7 +49,9 @@ class GameControllerTest extends AnyFunSuite with Matchers: test("processMove: legal capture returns Moved with the captured piece"): val captureBoard = Board(Map( sq(File.E, Rank.R5) -> Piece.WhitePawn, - sq(File.D, Rank.R6) -> Piece.BlackPawn + sq(File.D, Rank.R6) -> Piece.BlackPawn, + sq(File.H, Rank.R1) -> Piece.BlackKing, + sq(File.H, Rank.R8) -> Piece.WhiteKing )) GameController.processMove(captureBoard, Color.White, "e5d6") match case MoveResult.Moved(newBoard, captured, newTurn) => @@ -62,7 +64,7 @@ class GameControllerTest extends AnyFunSuite with Matchers: private def withInput(input: String)(block: => Unit): Unit = val stream = ByteArrayInputStream(input.getBytes("UTF-8")) - scala.Console.withIn(stream)(scala.Console.withOut(System.out)(block)) + scala.Console.withIn(stream)(block) test("gameLoop: 'quit' exits cleanly without exception"): withInput("quit\n"): @@ -116,7 +118,7 @@ class GameControllerTest extends AnyFunSuite with Matchers: // Kh8 can escape to g7/g8/h7 so this is InCheck, not Mated val b = Board(Map( sq(File.A, Rank.R1) -> Piece.WhiteRook, - sq(File.A, Rank.R3) -> Piece.WhiteKing, + sq(File.C, Rank.R3) -> Piece.WhiteKing, sq(File.H, Rank.R8) -> Piece.BlackKing )) GameController.processMove(b, Color.White, "a1a8") match @@ -176,7 +178,7 @@ class GameControllerTest extends AnyFunSuite with Matchers: test("gameLoop: MovedInCheck without capture prints check message"): val b = Board(Map( sq(File.A, Rank.R1) -> Piece.WhiteRook, - sq(File.A, Rank.R3) -> Piece.WhiteKing, + sq(File.C, Rank.R3) -> Piece.WhiteKing, sq(File.H, Rank.R8) -> Piece.BlackKing )) val output = captureOutput: @@ -188,7 +190,7 @@ class GameControllerTest extends AnyFunSuite with Matchers: // White Rook A1 captures Black Pawn on A8, Ra8 then attacks rank 8 putting Kh8 in check val b = Board(Map( sq(File.A, Rank.R1) -> Piece.WhiteRook, - sq(File.A, Rank.R3) -> Piece.WhiteKing, + sq(File.C, Rank.R3) -> Piece.WhiteKing, sq(File.A, Rank.R8) -> Piece.BlackPawn, sq(File.H, Rank.R8) -> Piece.BlackKing ))