-
Notifications
You must be signed in to change notification settings - Fork 0
/
PiezasTest.cpp
112 lines (102 loc) · 2.32 KB
/
PiezasTest.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
/**
* Unit Tests for Piezas
**/
#include <gtest/gtest.h>
#include "Piezas.h"
class PiezasTest : public ::testing::Test
{
protected:
PiezasTest(){} //constructor runs before each test
virtual ~PiezasTest(){} //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(PiezasTest, sanityCheck)
{
ASSERT_TRUE(true);
}
TEST(PiezasTest, resetTest)
{
Piezas tBoard;
for(int i=0; i<BOARD_ROWS; i++){
for(int j=0; j<BOARD_COLS; j++){
tBoard.dropPiece(j);
}
}
tBoard.reset();
for(int i=0; i<BOARD_ROWS; i++){
for(int j=0; j<BOARD_COLS; j++){
ASSERT_TRUE(tBoard.pieceAt(i,j) == Blank);
}
}
}
TEST(PiezasTest, oobDropPieceTest)
{
Piezas tBoard;
ASSERT_TRUE(tBoard.dropPiece(-1) == Invalid);
ASSERT_TRUE(tBoard.dropPiece(BOARD_COLS) == Invalid);
}
TEST(PiezasTest, dropPieceandTurnSwapTest)
{
Piezas tBoard;
tBoard.dropPiece(0);
ASSERT_TRUE(tBoard.dropPiece(0) == O);
}
TEST(PiezasTest, oobPieceAtTest)
{
Piezas tBoard;
ASSERT_TRUE(tBoard.pieceAt(-1,0) == Invalid);
ASSERT_TRUE(tBoard.pieceAt(BOARD_ROWS,0) == Invalid);
ASSERT_TRUE(tBoard.pieceAt(0,-1) == Invalid);
ASSERT_TRUE(tBoard.pieceAt(0,BOARD_COLS) == Invalid);
}
TEST(PiezasTest, pieceAtTest)
{
Piezas tBoard;
tBoard.dropPiece(0);
ASSERT_TRUE(tBoard.pieceAt(0,0) == X);
ASSERT_TRUE(tBoard.pieceAt(1,0) == Blank);
}
TEST(PiezasTest, gameStateUnfinishedTest)
{
Piezas tBoard;
ASSERT_TRUE(tBoard.gameState() == Invalid);
}
TEST(PiezasTest, gameStateTieTest)
{
Piezas tBoard;
for(int i=0; i<BOARD_ROWS; i++){
for(int j=0; j<BOARD_COLS; j++){
tBoard.dropPiece(j);
}
}
ASSERT_TRUE(tBoard.gameState() == Blank);
}
TEST(PiezasTest, gameStateVertWinTest)
{
Piezas tBoard;
for(int i=0; i<BOARD_ROWS; i++){
tBoard.dropPiece(0);
tBoard.dropPiece(-1);
}
for(int i=0; i<BOARD_ROWS; i++){
for(int j=1; j<BOARD_COLS; j++){
tBoard.dropPiece(j);
}
}
ASSERT_TRUE(tBoard.gameState() == X);
}
TEST(PiezasTest, gameStateHorizWinTest)
{
Piezas tBoard;
for(int i=0; i<BOARD_COLS; i++){
tBoard.dropPiece(i);
tBoard.dropPiece(-1);
}
for(int i=1; i<BOARD_ROWS; i++){
for(int j=0; j<BOARD_COLS; j++){
tBoard.dropPiece(j);
}
}
ASSERT_TRUE(tBoard.gameState() == X);
}