forked from ChicoState/TicTacToeBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TicTacToeBoardTest.cpp
159 lines (154 loc) · 3.57 KB
/
TicTacToeBoardTest.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
/**
* Unit Tests for TicTacToeBoard
**/
#include <gtest/gtest.h>
#include "TicTacToeBoard.h"
class TicTacToeBoardTest : public ::testing::Test
{
protected:
TicTacToeBoardTest(){} //constructor runs before each test
virtual ~TicTacToeBoardTest(){} //destructor cleans up after tests
virtual void SetUp(){} //sets up before each test (after constructor)
virtual void TearDown(){} //clean up after each test, (before destructor)
};
/* EXAMPLE TEST FORMAT
TEST(TicTacToeBoardTest, unitTestName)
{
ASSERT_TRUE(true);
}
*/
TEST(TicTacToeBoardTest, toggleOne)
{
TicTacToeBoard obj;
Piece outcome = obj.toggleTurn();
ASSERT_EQ(outcome, O);
}
TEST(TicTacToeBoardTest, toggleTwo)
{
TicTacToeBoard obj;
Piece outcome = obj.toggleTurn();
outcome = obj.toggleTurn();
ASSERT_EQ(outcome, X);
}
TEST(TicTacToeBoardTest, toggleThree)
{
TicTacToeBoard obj;
Piece outcome = obj.toggleTurn();
outcome = obj.toggleTurn();
outcome = obj.toggleTurn();
ASSERT_EQ(outcome, O);
}
TEST(TicTacToeBoardTest, placeRowOver2)
{
TicTacToeBoard obj;
Piece outcome = obj.placePiece(3,2);
ASSERT_EQ(outcome, Invalid);
}
TEST(TicTacToeBoardTest, placColOver2)
{
TicTacToeBoard obj;
Piece outcome = obj.placePiece(2,3);
ASSERT_EQ(outcome, Invalid);
}
TEST(TicTacToeBoardTest, placeRowAndColOver2)
{
TicTacToeBoard obj;
Piece outcome = obj.placePiece(3,3);
ASSERT_EQ(outcome, Invalid);
}
TEST(TicTacToeBoardTest, placeX00)
{
TicTacToeBoard obj;
Piece outcome = obj.placePiece(0,0);
ASSERT_EQ(outcome, X);
}
TEST(TicTacToeBoardTest, placeX22)
{
TicTacToeBoard obj;
Piece outcome = obj.placePiece(2,2);
ASSERT_EQ(outcome, X);
}
TEST(TicTacToeBoardTest, placeO)
{
TicTacToeBoard obj;
obj.toggleTurn();
Piece outcome = obj.placePiece(0,0);
ASSERT_EQ(outcome, O);
}
TEST(TicTacToeBoardTest, placeOoverX)
{
TicTacToeBoard obj;
Piece outcome = obj.placePiece(0,0);
outcome = obj.placePiece(0,0);
ASSERT_EQ(outcome, X);
}
TEST(TicTacToeBoardTest, placeXandO)
{
TicTacToeBoard obj;
Piece outcome1 = obj.placePiece(0,0);
Piece outcome2 = obj.placePiece(0,1);
ASSERT_EQ(outcome1, X);
ASSERT_EQ(outcome2, O);
}
TEST(TicTacToeBoardTest, WinfirstcolX)
{
TicTacToeBoard obj;
Piece outcome1 = obj.placePiece(0,0);
obj.toggleTurn();
Piece outcome2 = obj.placePiece(1,0);
obj.toggleTurn();
Piece outcome3 = obj.placePiece(2,0);
Piece outcome4 = obj.getWinner();
ASSERT_EQ(outcome1, X);
ASSERT_EQ(outcome2, X);
ASSERT_EQ(outcome3, X);
ASSERT_EQ(outcome4, X);
}
TEST(TicTacToeBoardTest, WinfirstrowX)
{
TicTacToeBoard obj;
Piece outcome1 = obj.placePiece(0,0);
obj.toggleTurn();
Piece outcome2 = obj.placePiece(0,1);
obj.toggleTurn();
Piece outcome3 = obj.placePiece(0,2);
Piece outcome4 = obj.getWinner();
ASSERT_EQ(outcome1, X);
ASSERT_EQ(outcome2, X);
ASSERT_EQ(outcome3, X);
ASSERT_EQ(outcome4, X);
}
TEST(TicTacToeBoardTest, WinCross)
{
TicTacToeBoard obj;
Piece outcome1 = obj.placePiece(0,0);
obj.toggleTurn();
Piece outcome2 = obj.placePiece(1,1);
obj.toggleTurn();
Piece outcome3 = obj.placePiece(2,2);
Piece outcome4 = obj.getWinner();
ASSERT_EQ(outcome1, X);
ASSERT_EQ(outcome2, X);
ASSERT_EQ(outcome3, X);
ASSERT_EQ(outcome4, X);
}
TEST(TicTacToeBoardTest, WinCrossOpp)
{
TicTacToeBoard obj;
Piece outcome1 = obj.placePiece(0,2);
obj.toggleTurn();
Piece outcome2 = obj.placePiece(1,1);
obj.toggleTurn();
Piece outcome3 = obj.placePiece(2,0);
Piece outcome4 = obj.getWinner();
ASSERT_EQ(outcome1, X);
ASSERT_EQ(outcome2, X);
ASSERT_EQ(outcome3, X);
ASSERT_EQ(outcome4, X);
}
TEST(TicTacToeBoardTest, WinInvalid)
{
TicTacToeBoard obj;
Piece outcome = obj.getWinner();
ASSERT_EQ(outcome, Invalid);
}