Use C++11 std::move for swap in selection sort algorithm
[purplehaze.git] / test / unit / test_pieces.cpp
blob44e8997963db4b2fdfc88c5579a8681edb8582c4
1 #include "../../src/pieces.h"
2 #include "gtest/gtest.h"
4 TEST(PiecesTest, Constructor)
6 Pieces pieces;
7 for (const Color &c : COLORS) {
8 EXPECT_EQ(0, pieces.get_nb_pieces(c));
9 for (const PieceType &t : PIECE_TYPES) {
10 EXPECT_EQ(0, pieces.get_nb_pieces(c, t));
11 for (int i = 0; i < 9; ++i) {
12 Piece p(c, t, i);
13 EXPECT_EQ(OUT, pieces.get_position(p));
14 EXPECT_EQ(OUT, pieces.get_position(c, t, i));
20 TEST(PiecesTest, Positions)
22 Pieces pieces;
23 for (const Color &c : COLORS) {
24 for (const PieceType &t : PIECE_TYPES) {
25 for (int i = 0; i < 9; ++i) {
26 for (const Square &s : SQUARES) {
27 Piece p(c, t, i);
29 // Test getters and setters
30 pieces.set_position(p, s);
31 EXPECT_EQ(s, pieces.get_position(p));
32 EXPECT_EQ(s, pieces.get_position(c, t, i));
33 pieces.set_position(c, t, i, s);
34 EXPECT_EQ(s, pieces.get_position(p));
35 EXPECT_EQ(s, pieces.get_position(c, t, i));
37 // Internal counters are not implicitly changed
38 EXPECT_EQ(0, pieces.get_nb_pieces(c));
39 EXPECT_EQ(0, pieces.get_nb_pieces(c, t));
46 TEST(PiecesTest, Count)
48 Pieces pieces;
49 for (const Color &c : COLORS) {
50 EXPECT_EQ(0, pieces.get_nb_pieces(c));
51 for (const PieceType &t : PIECE_TYPES) {
52 EXPECT_EQ(0, pieces.get_nb_pieces(c, t));
53 for (int i = 0; i < 9; ++i) {
54 EXPECT_EQ(i, pieces.get_nb_pieces(c, t));
55 pieces.inc_nb_pieces(c, t);
56 EXPECT_EQ(i + 1, pieces.get_nb_pieces(c, t));
58 for (int i = 9; i > 0; --i) {
59 EXPECT_EQ(i, pieces.get_nb_pieces(c, t));
60 pieces.dec_nb_pieces(c, t);
61 EXPECT_EQ(i - 1, pieces.get_nb_pieces(c, t));
63 EXPECT_EQ(0, pieces.get_nb_pieces(c, t));
65 EXPECT_EQ(0, pieces.get_nb_pieces(c));
69 TEST(PiecesTest, Size)
71 int size = (sizeof(Square) * 2 * 7 * 9) +
72 (sizeof(unsigned char) * 2 * 7) +
73 (sizeof(unsigned char) * 2);
74 EXPECT_EQ(size, 142); // Square is unsigned char (1 byte)
75 EXPECT_EQ(size, sizeof(Pieces));