forked from ChicoState/TicTacToeBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicTacToeBoardTest.cpp
More file actions
130 lines (122 loc) · 4.14 KB
/
Copy pathTicTacToeBoardTest.cpp
File metadata and controls
130 lines (122 loc) · 4.14 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
124
125
126
127
128
129
130
/**
* 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)
};
TEST(TicTacToeBoardTest, toggleTurn){
TicTacToeBoard testboard;
testboard.toggleTurn();
ASSERT_TRUE(testboard.toggleTurn() == X);
ASSERT_TRUE(testboard.toggleTurn() == O);
}
/*
*BUG: If you place a piece on a spot where there is already a piece it should return the piece already w/ no change to game state
*My implementation will toggle the player turn even if the attempted placement fails due to an existing piece.
*My test catches this bug by making sure the turn does not toggle on duplicate placement (lines 36-39)
*/
TEST(TicTacToeBoardTest, placePiece){
TicTacToeBoard testboard;
ASSERT_TRUE(testboard.placePiece(2,3) == Invalid);
ASSERT_TRUE(testboard.placePiece(3,2) == Invalid);
ASSERT_TRUE(testboard.placePiece(0,0) == X);
ASSERT_TRUE(testboard.placePiece(1,0) == O);
ASSERT_TRUE(testboard.placePiece(0,0) == X);
ASSERT_TRUE(testboard.placePiece(0,1) == X);
ASSERT_TRUE(testboard.placePiece(1,1) == O);
ASSERT_TRUE(testboard.placePiece(0,2) == X);
ASSERT_TRUE(testboard.placePiece(1,2) == Blank);
}
TEST(TicTacToeBoard, getPiece){
TicTacToeBoard testboard;
ASSERT_TRUE(testboard.getPiece(2,3) == Invalid);
ASSERT_TRUE(testboard.getPiece(3,2) == Invalid);
ASSERT_TRUE(testboard.getPiece(0,0) == Blank);
testboard.placePiece(0,0);
ASSERT_TRUE(testboard.getPiece(0,0) == X);
}
TEST(TicTacToeBoardTest, getWinner){
TicTacToeBoard testboardX;
ASSERT_TRUE(testboardX.getWinner() == Invalid);
testboardX.placePiece(0,0);
testboardX.toggleTurn();
testboardX.placePiece(0,1);
testboardX.toggleTurn();
testboardX.placePiece(0,2);
testboardX.toggleTurn();
ASSERT_TRUE(testboardX.getWinner() == X);
TicTacToeBoard testboardO;
ASSERT_TRUE(testboardO.getWinner() == Invalid);
testboardO.toggleTurn();
testboardO.placePiece(0,0);
testboardO.toggleTurn();
testboardO.placePiece(0,1);
testboardO.toggleTurn();
testboardO.placePiece(0,2);
testboardO.toggleTurn();
ASSERT_TRUE(testboardO.getWinner() == O);
TicTacToeBoard testboard2X;
ASSERT_TRUE(testboard2X.getWinner() == Invalid);
testboard2X.placePiece(0,0);
testboard2X.toggleTurn();
testboard2X.placePiece(1,0);
testboard2X.toggleTurn();
testboard2X.placePiece(2,0);
testboard2X.toggleTurn();
ASSERT_TRUE(testboard2X.getWinner() == X);
TicTacToeBoard testboard2O;
ASSERT_TRUE(testboard2O.getWinner() == Invalid);
testboard2O.toggleTurn();
testboard2O.placePiece(0,0);
testboard2O.toggleTurn();
testboard2O.placePiece(1,0);
testboard2O.toggleTurn();
testboard2O.placePiece(2,0);
testboard2O.toggleTurn();
ASSERT_TRUE(testboard2O.getWinner() == O);
TicTacToeBoard testboardX3;
ASSERT_TRUE(testboardX3.getWinner() == Invalid);
testboardX3.placePiece(0,0);
testboardX3.toggleTurn();
testboardX3.placePiece(1,1);
testboardX3.toggleTurn();
testboardX3.placePiece(2,2);
testboardX3.toggleTurn();
ASSERT_TRUE(testboardX3.getWinner() == X);
TicTacToeBoard testboardO3;
ASSERT_TRUE(testboardO3.getWinner() == Invalid);
testboardO3.toggleTurn();
testboardO3.placePiece(0,0);
testboardO3.toggleTurn();
testboardO3.placePiece(1,1);
testboardO3.toggleTurn();
testboardO3.placePiece(2,2);
testboardO3.toggleTurn();
ASSERT_TRUE(testboardO3.getWinner() == O);
TicTacToeBoard testboardX4;
ASSERT_TRUE(testboardX4.getWinner() == Invalid);
testboardX4.placePiece(0,0);
testboardX4.toggleTurn();
testboardX4.placePiece(1,1);
testboardX4.toggleTurn();
testboardX4.placePiece(2,2);
testboardX4.toggleTurn();
ASSERT_TRUE(testboardX4.getWinner() == X);
TicTacToeBoard testboardO4;
ASSERT_TRUE(testboardO4.getWinner() == Invalid);
testboardO4.toggleTurn();
testboardO4.placePiece(0,2);
testboardO4.toggleTurn();
testboardO4.placePiece(1,1);
testboardO4.toggleTurn();
testboardO4.placePiece(2,0);
testboardO4.toggleTurn();
ASSERT_TRUE(testboardO4.getWinner() == O);
}