forked from cpp-exercises/CardWar_B
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentTest1.cpp
100 lines (88 loc) · 2.09 KB
/
StudentTest1.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
#include "doctest.h"
#include <stdexcept>
#include "sources/player.hpp"
#include "sources/game.hpp"
#include "sources/card.hpp"
using namespace std;
using namespace ariel;
TEST_CASE("The amount of cards before starting a game")
{
Player p1("Alice");
Player p2("Bob");
CHECK(p1.stacksize() == 0);
CHECK(p2.stacksize() == 0);
CHECK(p1.cardesTaken() == 0);
CHECK(p2.cardesTaken() == 0);
}
TEST_CASE("The amount of cards after starting a game")
{
Player p1("Alice");
Player p2("Bob");
Game game(p1, p2);
CHECK(p1.stacksize() == 26);
CHECK(p2.stacksize() == 26);
CHECK(p1.cardesTaken() == 0);
CHECK(p2.cardesTaken() == 0);
}
TEST_CASE("The card scheme at the end of the game")
{
Player p1("Alice");
Player p2("Bob");
Game game(p1, p2);
game.playAll();
int sum = p1.stacksize() + p1.cardesTaken() + p2.stacksize() + p2.cardesTaken();
CHECK(sum == 52);
}
TEST_CASE("Throwing errors from the functions")
{
Player p1("Alice");
Player p2("Bob");
Game game(p1, p2);
for (int i = 0; i < 5; i++)
{
game.playTurn();
}
CHECK_NOTHROW(game.printLastTurn());
CHECK_NOTHROW(game.printLog());
CHECK_NOTHROW(game.printStats());
CHECK_NOTHROW(game.printWiner());
}
TEST_CASE("Activating another turn after the game is over")
{
Player p1("Alice");
Player p2("Bob");
Game game(p1, p2);
game.playAll();
CHECK(p1.stacksize() == 0);
CHECK(p2.stacksize() == 0);
CHECK_THROWS(game.playTurn());
}
TEST_CASE("One player")
{
Player p1("Alice");
Game game(p1, p1);
CHECK_THROWS(game.playTurn());
}
TEST_CASE("Printing the winner")
{
Player p1("Alice");
Player p2("Bob");
Game game(p1, p2);
game.playAll();
CHECK_NOTHROW(game.printWiner());
}
TEST_CASE("The game ends after at most 26 turns")
{
Player p1("Alice");
Player p2("Bob");
Game game(p1, p2);
int maxTurns = 26;
int i = 0;
for ( ; i < 26 && p1.stacksize()>0; i++ )
{
game.playTurn();
}
CHECK(maxTurns >= i );
CHECK(p1.stacksize() == 0);
CHECK(p2.stacksize() == 0);
}