1 #include "../../src/pieces.h"
2 #include "../../src/game.h"
3 #include "gtest/gtest.h"
5 TEST(PiecesTest
, Constructor
)
8 for (const Color
&c
: COLORS
) {
9 EXPECT_EQ(0, pieces
.count(c
));
10 for (const PieceType
&t
: PIECE_TYPES
) {
11 EXPECT_EQ(0, pieces
.count(c
, t
));
12 for (int i
= 0; i
< 9; ++i
) {
14 EXPECT_EQ(OUT
, pieces
.position(p
));
15 EXPECT_EQ(OUT
, pieces
.position(c
, t
, i
));
21 TEST(PiecesTest
, Positions
)
24 for (const Color
&c
: COLORS
) {
25 for (const PieceType
&t
: PIECE_TYPES
) {
26 for (int i
= 0; i
< 9; ++i
) {
27 for (const Square
&s
: SQUARES
) {
30 // Test getters and setters
31 pieces
.set_position(p
, s
);
32 EXPECT_EQ(s
, pieces
.position(p
));
33 EXPECT_EQ(s
, pieces
.position(c
, t
, i
));
34 pieces
.set_position(c
, t
, i
, s
);
35 EXPECT_EQ(s
, pieces
.position(p
));
36 EXPECT_EQ(s
, pieces
.position(c
, t
, i
));
38 // Internal counters are not implicitly changed
39 EXPECT_EQ(0, pieces
.count(c
));
40 EXPECT_EQ(0, pieces
.count(c
, t
));
47 TEST(PiecesTest
, Count
)
50 for (const Color
&c
: COLORS
) {
51 for (const PieceType
&t
: PIECE_TYPES
) {
52 EXPECT_EQ(0, pieces
.count(c
));
53 EXPECT_EQ(0, pieces
.count(c
, t
));
54 for (int i
= 0; i
< 9; ++i
) {
55 EXPECT_EQ(i
, pieces
.count(c
));
56 EXPECT_EQ(i
, pieces
.count(c
, t
));
57 pieces
.inc_nb_pieces(c
, t
);
58 EXPECT_EQ(i
+ 1, pieces
.count(c
));
59 EXPECT_EQ(i
+ 1, pieces
.count(c
, t
));
61 for (int i
= 9; i
> 0; --i
) {
62 EXPECT_EQ(i
, pieces
.count(c
));
63 EXPECT_EQ(i
, pieces
.count(c
, t
));
64 pieces
.dec_nb_pieces(c
, t
);
65 EXPECT_EQ(i
- 1, pieces
.count(c
));
66 EXPECT_EQ(i
- 1, pieces
.count(c
, t
));
68 EXPECT_EQ(0, pieces
.count(c
));
69 EXPECT_EQ(0, pieces
.count(c
, t
));
74 TEST(PiecesTest
, CountBoard
)
77 game
.init("8/8/1k6/ppp4P/6P1/5P2/4P3/4K3 w - - 0 1");
78 EXPECT_EQ(5, game
.pieces
.count(WHITE
));
79 EXPECT_EQ(4, game
.pieces
.count(WHITE
, PAWN
));
80 EXPECT_EQ(1, game
.pieces
.count(WHITE
, KING
));
81 EXPECT_EQ(4, game
.pieces
.count(BLACK
));
82 EXPECT_EQ(3, game
.pieces
.count(BLACK
, PAWN
));
83 EXPECT_EQ(1, game
.pieces
.count(BLACK
, KING
));
87 TEST(PiecesTest
, Size
)
89 int size
= (sizeof(Square
) * 2 * 7 * 9) +
90 (sizeof(unsigned char) * 2 * 7) +
91 (sizeof(unsigned char) * 2);
92 EXPECT_EQ(size
, 142); // Square is unsigned char (1 byte)
93 EXPECT_EQ(size
, sizeof(Pieces
));