-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathninarow_move_ut.cpp
72 lines (61 loc) · 2.17 KB
/
ninarow_move_ut.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <gtest/gtest.h>
#include "ninarow_move.h"
using namespace NInARow;
/**
* Tests Move implementation.
*/
TEST(NInARowMoveTest, TestMove) {
using Move = Move<3, 3, 3>;
Move move1 = Move();
Move move2 = Move(1, 1000, Player::Player1);
Move move3 = Move(8, -1000, Player::Player2);
Move move4 = Move(2, 2, -50, Player::Player1);
// Can't construct moves that are off the board.
EXPECT_THROW((Move(9, -1000, Player::Player2)), std::out_of_range);
EXPECT_THROW((Move(3, 3, -1000, Player::Player2)), std::out_of_range);
EXPECT_FALSE(move1 < move1);
EXPECT_TRUE(move1 < move2);
EXPECT_FALSE(move2 < move1);
EXPECT_TRUE(move3 < move2);
EXPECT_FALSE(move2 < move3);
EXPECT_TRUE(move3 < move1);
EXPECT_FALSE(move1 < move3);
EXPECT_TRUE(move3 < move4);
EXPECT_FALSE(move4 < move3);
EXPECT_TRUE(move4 < move2);
EXPECT_FALSE(move2 < move4);
EXPECT_TRUE(move4 < move1);
EXPECT_FALSE(move1 < move4);
EXPECT_EQ(Move(0, 2, 0, Player::Player1).board_position,
Move(2, 0, Player::Player1).board_position);
EXPECT_EQ(Move(1, 2, 0, Player::Player1).board_position,
Move(5, 0, Player::Player1).board_position);
EXPECT_EQ(Move(2, 2, 0, Player::Player1).board_position,
Move(8, 0, Player::Player1).board_position);
EXPECT_EQ(Move(2, 0, 0, Player::Player1).board_position,
Move(6, 0, Player::Player1).board_position);
EXPECT_EQ(Move(2, 1, 0, Player::Player1).board_position,
Move(7, 0, Player::Player1).board_position);
}
/**
* Tests implementation of get_row() and get_col().
*/
TEST(NInARowMoveTest, TestGetRowCol) {
using Move = Move<3, 3, 3>;
{
Move move1 = Move(0, 2, 0, Player::Player1);
Move move2 = Move(2, 0, Player::Player2);
EXPECT_EQ(move1.get_row(), 0);
EXPECT_EQ(move1.get_col(), 2);
EXPECT_EQ(move2.get_row(), 0);
EXPECT_EQ(move2.get_col(), 2);
}
{
Move move1 = Move(2, 1, 0, Player::Player1);
Move move2 = Move(7, 0, Player::Player2);
EXPECT_EQ(move1.get_row(), 2);
EXPECT_EQ(move1.get_col(), 1);
EXPECT_EQ(move2.get_row(), 2);
EXPECT_EQ(move2.get_col(), 1);
}
}