-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cpp
173 lines (121 loc) · 4.14 KB
/
Test.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
#include "doctest.h"
#include "sources/player.hpp"
#include "sources/game.hpp"
#include "sources/card.hpp"
using namespace std;
#include <stdexcept>
#include <iostream>
TEST_CASE("Same player is in the same game"){
Player player("Avi");
CHECK_THROWS(Game(player,player));
}
TEST_CASE("Same player is in more than one game"){
Player player1("Avi");
Player player2("Shirel");
Player player3("Eli");
Game game(player1, player2);
CHECK_THROWS(Game{player1,player3});
}
TEST_CASE("correct initialization"){
Player player1("Avi");
Player player2("Eli");
Game game(player1, player2);
CHECK_EQ(player1.stacksize(), 26);
CHECK_EQ(player2.stacksize(), 26);
CHECK_EQ(player1.cardesTaken(), 0);
CHECK_EQ(player2.cardesTaken(), 0);
}
TEST_CASE("number of cards at the end of the game"){
Player player1("Avi");
Player player2("Eli");
Game game(player1, player2);
game.playAll();
CHECK(player1.stacksize() <= 52);
CHECK(player1.stacksize() >= 0);
CHECK(player2.stacksize() <= 52);
CHECK(player2.stacksize() >= 0);
CHECK(player1.cardesTaken() + player2.cardesTaken() == 26);
CHECK_FALSE( !(player1.cardesTaken() < player2.cardesTaken() || player1.cardesTaken() > player2.cardesTaken()) );
}
TEST_CASE("number of turns being played"){
Player player1("Avi");
Player player2("Eli");
Game game(player1, player2);
game.playAll();
CHECK_THROWS(game.playTurn());
CHECK_THROWS(game.playAll());
}
TEST_CASE("number of cards in each turn"){
Player player1("Avi");
Player player2("Eli");
Game game(player1, player2);
int p1_cards = player1.cardesTaken();
int p2_cards = player2.cardesTaken();
for(int i = 0; i<25; i++){
game.playTurn();
if(player1.cardesTaken() == p1_cards && player2.cardesTaken() == p2_cards+1){
p2_cards++;
}
else if(player1.cardesTaken() == p1_cards && player2.cardesTaken() == p2_cards+3){
p2_cards = p2_cards + 3;
}
else if (player1.cardesTaken() == p1_cards+1 && player2.cardesTaken() == p2_cards){
p1_cards++;
}
else if(player1.cardesTaken() == p1_cards+3 && player2.cardesTaken() == p2_cards){
p1_cards = p1_cards + 3;
}
CHECK_EQ(player1.cardesTaken(), p1_cards);
CHECK_EQ(player2.cardesTaken(), p2_cards);
}
}
TEST_CASE("number of cards left in the stack in each turn"){
Player player1("Avi");
Player player2("Eli");
Game game(player1, player2);
for(int i = 0; i<25; i++){
game.playTurn();
CHECK_EQ(player1.stacksize(), player2.stacksize());
}
}
TEST_CASE("checks if not possible to play when one of them has no cards"){
Player player1("Avi");
Player player2("Eli");
Game game(player1, player2);
for(int i = 0; i<25; i++){
if (player1.stacksize() > 0 && player2.stacksize()>0)
{
game.playTurn();
}
else{
CHECK_THROWS(game.playTurn());
}
}
}
TEST_CASE("case of a tie"){
Player player1("Avi");
Player player2("Eli");
Game game(player1, player2);
for(int i = 0; player1.stacksize() == 0 && player2.stacksize() == 0 && i<100 ; i++){
//if there is a winner
if (((player1.cardesTaken() > player2.cardesTaken() || player1.cardesTaken() < player2.cardesTaken()) &&
player1.stacksize() == 0 && player2.stacksize() == 0 ) ||
i==99)
{
std::cout << "Didn't reach the purpose of the test." << endl;
break;
}
//if there is no winner yet
game.playTurn();
//if there's a tie
if (player1.stacksize() == 0 &&
player2.stacksize() == 0 &&
player1.cardesTaken() == player2.cardesTaken())
{
CHECK_THROWS(game.playTurn()); //should take all the cards thrown and divide them evenly to both players, and then they can keep playing
CHECK(player1.stacksize() >= 0);
CHECK(player2.stacksize() >= 0);
CHECK_EQ(player1.stacksize(), player2.stacksize());
}
}
}