-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRookTestSuite.cpp
More file actions
124 lines (106 loc) · 3.59 KB
/
Copy pathRookTestSuite.cpp
File metadata and controls
124 lines (106 loc) · 3.59 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "RookTestSuite.h"
#include "../Rook.h"
#include "UnitTest++.h"
#include <vector>
#include "../ChessPiece.h"
class RookFixture
{
public:
Rook* ptr_WhiteRook;
Rook* ptr_BlackRook;
RookFixture(){
ptr_WhiteRook = new Rook(0, 0, "White");
ptr_BlackRook= new Rook(0,7, "Black");
}
~RookFixture(){
delete ptr_WhiteRook;
delete ptr_BlackRook;
}
};
SUITE(RookTests){
TEST_FIXTURE(RookFixture, TestPieceSymbol){
CHECK_EQUAL(ptr_BlackRook->GetSymbol(), 'R');
CHECK_EQUAL(ptr_WhiteRook->GetSymbol(), 'r');
}
TEST_FIXTURE(RookFixture, TestValidMoves){
//From Initial Coordinate
//Check Following are InValidVector
position_t initPsn(ptr_BlackRook->GetPosition());
CHECK_EQUAL(initPsn.x, 0);
CHECK_EQUAL(initPsn.y, 7);
std::vector<position_t> initPsnValid(ptr_BlackRook->GetValidMoves());
std::vector<position_t> initPsnCheck;
//0,0
initPsnCheck.push_back(position_t(initPsn.x, initPsn.y - 7));
//7,7
initPsnCheck.push_back(position_t(initPsn.x + 7, initPsn.y));
//0,4
initPsnCheck.push_back(position_t(initPsn.x, initPsn.y - 3));
//4,7
initPsnCheck.push_back(position_t(initPsn.x + 4, initPsn.y));
bool containsAll = false;
for(int i = 0; i < initPsnCheck.size(); i++){
containsAll = false;
for (int j = 0; j < initPsnValid.size(); j++)
{
if(initPsnCheck[i] == initPsnValid[j]){
containsAll = true;
}
}
if(!containsAll){
break;
}
}
CHECK(containsAll);
//Check Following Are not in valid vector
std::vector<position_t> invalidPsn;
//Initial coordinates shouldn't be in it.
invalidPsn.push_back(position_t(initPsn.x, initPsn.y));
//No diagonal (1,6)
invalidPsn.push_back(position_t(initPsn.x + 1, initPsn.y - 1 ));
//Random one
invalidPsn.push_back(position_t(3,3));
bool doesNotContain = true; // Assume it does not contain
for (int i = 0; i < initPsnValid.size(); i++){
doesNotContain = true;
for (int j = 0; j < invalidPsn.size(); j++){
if(initPsnValid[i] == invalidPsn[j]){
doesNotContain = false;
}
}
if(!doesNotContain){
break;
}
}
CHECK(doesNotContain);
//Move Piece to middle of Board
ptr_BlackRook->SetPosition(4,5);
position_t movedPsn(ptr_BlackRook->GetPosition());
CHECK_EQUAL(movedPsn.x, 4);
CHECK_EQUAL(movedPsn.y, 5);
std::vector<position_t> newPsnValid(ptr_BlackRook->GetValidMoves());
std::vector<position_t> newPsnCheck;
//4,7
newPsnCheck.push_back(position_t(movedPsn.x, movedPsn.y + 2));
//0,5
newPsnCheck.push_back(position_t(movedPsn.x - 4, movedPsn.y));
//4,3
newPsnCheck.push_back(position_t(movedPsn.x, movedPsn.y - 2 ));
//5,5
newPsnCheck.push_back(position_t(movedPsn.x + 1, movedPsn.y));
containsAll = false;
for(int i = 0; i < newPsnCheck.size(); i++){
containsAll = false;
for (int j = 0; j < newPsnValid.size(); j++)
{
if(newPsnCheck[i] == newPsnValid[j]){
containsAll = true;
}
}
if(!containsAll){
break;
}
}
CHECK(containsAll);
}
}