17#ifndef HOOVER_CHESS_UTILS__PGN_READER__CHESSBOARD_TEST_PLAYMOVE_HELPER_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__CHESSBOARD_TEST_PLAYMOVE_HELPER_H_INCLUDED
23#include "gtest/gtest.h"
30template <
typename ... Args>
33 std::size_t expectNumMoves,
40 std::size_t numMoves { (board.*generateMovesFn)(moves, srcSqMask, dstSq, std::forward<Args>(args) ...) };
41 EXPECT_EQ(expectNumMoves, numMoves);
43 Move singleMove { (board.*generateSingleMoveFn)(srcSqMask, dstSq, std::forward<Args>(args) ...) };
45 if (expectNumMoves == 0U)
47 EXPECT_TRUE(singleMove.isIllegal());
50 else if (expectNumMoves == 1U)
52 EXPECT_FALSE(singleMove.isIllegal());
56 EXPECT_TRUE(singleMove.isIllegal());
60 if (numMoves == expectNumMoves)
64 EXPECT_EQ(singleMove, moves[0U]);
69 EXPECT_TRUE(srcSqMask.isMember(singleMove.getSrc()));
72 EXPECT_EQ(dstSq, singleMove.getDst());
83 std::forward<Args>(args) ...);
96 std::size_t expectNumMoves,
102 std::size_t numMoves { (board.*generateMovesFn)(moves) };
103 EXPECT_EQ(expectNumMoves, numMoves);
105 Move singleMove { (board.*generateSingleMoveFn)() };
107 if (expectNumMoves == 0U)
109 EXPECT_TRUE(singleMove.isIllegal());
112 else if (expectNumMoves == 1U)
114 EXPECT_FALSE(singleMove.isIllegal());
118 EXPECT_TRUE(singleMove.isIllegal());
122 if (numMoves == expectNumMoves)
126 EXPECT_EQ(singleMove, moves[0U]);
138#define PLAY_MOVE(board, MoveFunction, ...) \
139 hoover_chess_utils::pgn_reader::unit_test::playMove( \
142 &hoover_chess_utils::pgn_reader::ChessBoard::generateMovesFor ## MoveFunction, \
143 &hoover_chess_utils::pgn_reader::ChessBoard::generateSingleMoveFor ## MoveFunction \
144 __VA_OPT__(,) __VA_ARGS__)
146#define PLAY_MOVE_EXPECT_NO_MOVES(board, MoveFunction, ...) \
147 hoover_chess_utils::pgn_reader::unit_test::playMove( \
150 &hoover_chess_utils::pgn_reader::ChessBoard::generateMovesFor ## MoveFunction, \
151 &hoover_chess_utils::pgn_reader::ChessBoard::generateSingleMoveFor ## MoveFunction \
152 __VA_OPT__(,) __VA_ARGS__)
The chessboard.
Definition chessboard.h:589
void printBoard() const
Prints the current board to stdout. This is intended only for debugging purposes.
void doMove(Move m) noexcept
Applies a move on the current position. The move is assumed to be legal, and it must be from one of t...
A legal move. Important: see the note!
Definition chessboard.h:198
static constexpr Move illegalNoMove() noexcept
Token for illegal move: no moves generated.
Definition chessboard.h:429
static constexpr Move illegalAmbiguousMove() noexcept
Token for illegal move: ambiguous move generation.
Definition chessboard.h:437
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
std::array< CompactMove, 8U > ShortMoveList
Short move list returned by move generators for writing a SAN move. That is, when the piece type and ...
Definition chessboard.h:514
Square
Named square.
Definition chessboard-types.h:122
Definition chessboard-test-playmove-helper.h:27
void playMove(ChessBoard &board, std::size_t expectNumMoves, std::size_t(ChessBoard::*generateMovesFn)(ShortMoveList &moves, SquareSet, Square, Args ...) const noexcept, Move(ChessBoard::*generateSingleMoveFn)(SquareSet, Square, Args ...) const noexcept, SquareSet srcSqMask, Square dstSq, Args &&... args)
Definition chessboard-test-playmove-helper.h:31