forked from kbuffardi/ConnectX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectXTest.cpp~
169 lines (148 loc) · 4.32 KB
/
ConnectXTest.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* Unit Tests for ConnectX class
**/
#include <gtest/gtest.h>
#include <iostream>
#include "ConnectX.h"
class ConnectXTest : public ::testing::Test
{
protected:
ConnectXTest(){}
virtual ~ConnectXTest(){}
virtual void SetUp(){}
virtual void TearDown(){}
};
TEST(ConnectXTest, atPlacePieceBLACK) //Checking for Black player.
{
ConnectX cx;
cx.placePiece(2);
ASSERT_EQ(2, cx.at(2, 5));
}
TEST(ConnectXTest, atPlacePieceEMPTY) //Checking for EMPTY cell
{
ConnectX cx;
cx.placePiece(2);
ASSERT_EQ(0, cx.at(2, 4));
}
TEST(ConnectXTest, atPlacePieceWHITE1) //Checking for player White with first player placed at invalid location.
{
ConnectX cx;
cx.placePiece(10);
cx.placePiece(3);
ASSERT_EQ(1, cx.at(3, 5));
}
TEST(ConnectXTest, atPlacePieceWHITE2) //Checking for player White with first player placed at valid location.
{
ConnectX cx;
cx.placePiece(3);
//ASSERT_EQ(2, cx.at(3, 5));
cx.placePiece(3);
ASSERT_EQ(1, cx.at(3, 4));
}
TEST(ConnectXTest, atPlacePieceOutBounds) //Placing the piece in invalid location and asserting for INVALID.
{
ConnectX cx;
cx.placePiece(8);
ASSERT_EQ(-1,cx.at(8, 5)); //BUG
//ASSERT_EQ(0,cx.at(4, 3));
}
TEST(ConnectXTest, atPlacePieceNegative) //Checking by placing the piece in an invalid negative value. I am commenting the function call since it throws code dump exception and we cannot test further testcases.
{
ConnectX cx;
cx.placePiece(-1); //BUG
ASSERT_EQ(0,cx.at(4, 3));
}
TEST(ConnectXTest, atWidthOutBounds) //Checking for Width out of bound values
{
ConnectX cx;
cx.placePiece(6);
ASSERT_EQ(-1,cx.at(9, 5)); //BUG
}
TEST(ConnectXTest, atWidthNegative) //Checking for negative Width value.
{
ConnectX cx;
cx.placePiece(4);
ASSERT_EQ(-1,cx.at(-1, 5)); //BUG
}
TEST(ConnectXTest, atHeightOutBounds) //Checking for Height out of bound value.
{
ConnectX cx;
cx.placePiece(6);
ASSERT_EQ(-1,cx.at(6, 7));
}
TEST(ConnectXTest, atHeightNegative) //Checking for negative Height value.
{
ConnectX cx;
cx.placePiece(5);
ASSERT_EQ(-1,cx.at(5, -2));
}
TEST(ConnectXTest, atBothNegative) //Checking negative for both Width and Height value.
{
ConnectX cx;
cx.placePiece(1);
ASSERT_EQ(-1,cx.at(-2, -1));
}
TEST(ConnectXTest, PlacePieceValidAtInvalidPositive) //Checking for invalid positions where the piece is placed at valid location.
{
ConnectX cx;
cx.placePiece(4);
ASSERT_EQ(-1,cx.at(8, 7));
}
TEST(ConnectXTest, showBoardWidthHeightWinOutbound) //Modifying the board dimension and checking for the Piece validation.
{
ConnectX cx(8, 8, 5);
cx.placePiece(7);
ASSERT_EQ(2,cx.at(7, 7)); //Checking for Black
cx.placePiece(0);
ASSERT_EQ(1,cx.at(0, 7)); //Checking for White
}
TEST(ConnectXTest, showBoardWidthNegative) //Modified board dimension having a negative Width value and checking for Piece at valid location
{
ConnectX cx(-1, 3, 2);
cx.placePiece(6);
ASSERT_EQ(2,cx.at(6, 5));
}
TEST(ConnectXTest, showBoardHeightZero) //Modified board dimension having Zero Height and checking for Piece at valid location
{
ConnectX cx(1, 0, 2);
cx.placePiece(6);
ASSERT_EQ(2,cx.at(6, 5));
}
TEST(ConnectXTest, showBoardWinZero) //Modified board dimension having a Zero DefaultWins and checking for Piece at valid location
{
ConnectX cx(1, 1, 0);
cx.placePiece(6);
ASSERT_EQ(2,cx.at(6, 5));
}
TEST(ConnectXTest, showBoardAllOutbound) //Modified board dimension having all negative values except DefaultWins and checking for Piece at valid location
{
ConnectX cx(-1, -1, 0);
cx.placePiece(6);
ASSERT_EQ(2,cx.at(6, 5));
}
TEST(ConnectXTest, showBoardBlackWhite) //Checking for ToggleTurn function by placing a piece over an occupied location.
{
ConnectX cx(2,2,1);
cx.placePiece(1);
ASSERT_EQ(2, cx.at(1, 1)); //Checking for Black
cx.placePiece(1);
ASSERT_EQ(1, cx.at(1, 0)); //Checking for White
cx.placePiece(0);
ASSERT_EQ(2, cx.at(0, 1)); //Checking for Black
cx.placePiece(1);
ASSERT_EQ(2, cx.at(1, 1)); //Placing White over Black piece location
cx.placePiece(0);
ASSERT_EQ(2, cx.at(0, 0)); //Checking for Black
}
TEST(ConnectXTest, placePieceBadEntry) //Checking for Bad piece placement
{
ConnectX cx(2, 2, 1);
cx.placePiece(1);
ASSERT_EQ(2, cx.at(1, 1)); //Checking for Black
cx.placePiece(1);
ASSERT_EQ(1, cx.at(1, 0)); //Checking for White
cx.placePiece(3);
ASSERT_EQ(-1, cx.at(1, 2)); //Checking for invalid location
ASSERT_EQ(0, cx.at(0, 0)); //Checking for EMPTY
cx.showBoard();
}