From a77fbcbd8b978883e477e2a6c7679565c0961c13 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Wed, 18 Sep 2024 05:40:10 +0200 Subject: [PATCH] Test invalid pawn moves --- chess/board_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/chess/board_test.go b/chess/board_test.go index 62bc5de..da67b58 100644 --- a/chess/board_test.go +++ b/chess/board_test.go @@ -71,6 +71,30 @@ func TestBoardMovePawn(t *testing.T) { assertPiece(t, b, "e5", chess.Pawn, chess.Dark) } +func TestBoardMovePawnInvalid(t *testing.T) { + b := chess.NewBoard() + + assertMoveError(t, b, "a5", "no pawn found that can move to a5") + assertMoveError(t, b, "b5", "no pawn found that can move to b5") + assertMoveError(t, b, "c5", "no pawn found that can move to c5") + assertMoveError(t, b, "d5", "no pawn found that can move to d5") + assertMoveError(t, b, "e5", "no pawn found that can move to e5") + assertMoveError(t, b, "f5", "no pawn found that can move to f5") + assertMoveError(t, b, "g5", "no pawn found that can move to g5") + assertMoveError(t, b, "h5", "no pawn found that can move to h5") + + b.Move("d4") + + assertMoveError(t, b, "a4", "no pawn found that can move to a4") + assertMoveError(t, b, "b4", "no pawn found that can move to b4") + assertMoveError(t, b, "c4", "no pawn found that can move to c4") + assertMoveError(t, b, "d4", "no pawn found that can move to d4") + assertMoveError(t, b, "e4", "no pawn found that can move to e4") + assertMoveError(t, b, "f4", "no pawn found that can move to f4") + assertMoveError(t, b, "g4", "no pawn found that can move to g4") + assertMoveError(t, b, "h4", "no pawn found that can move to h4") +} + func assertPiece(t *testing.T, b *chess.Board, position string, name chess.PieceName, color chess.Color) { p := b.At(position) @@ -92,3 +116,7 @@ func assertNoPiece(t *testing.T, b *chess.Board, position string) { assert.Nil(t, p, "expected no piece at %s", position) } + +func assertMoveError(t *testing.T, b *chess.Board, position string, message string) { + assert.ErrorContains(t, b.Move(position), message) +}