-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cpp
67 lines (51 loc) · 1.58 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
#include <iostream>
#include <stdexcept>
#include <string>
#include "doctest.h"
#include "sources/player.hpp"
#include "sources/game.hpp"
#include "sources/card.hpp"
using namespace std;
using namespace ariel;
TEST_CASE("Test 1 - checking for valids and invalid initializations") {
//valid initializations
CHECK_NOTHROW( Player p1("Maor"));
CHECK_NOTHROW(Player p2("Or"));
CHECK_NOTHROW(Game(Player("Maor"),Player("Or")));
//invalid initializations
CHECK_THROWS(Game(Player(""),Player("")));
CHECK_THROWS(Game(Player(""),Player("Maor")));
CHECK_THROWS(Game(Player("Maor"),Player("")));
Player p1("Raz");
CHECK_THROWS(Game(p1,p1));
}
TEST_CASE("Test 2 - player's functions") {
Player p1("Maor");
Player p2("Or");
Game game(p1,p2);
CHECK(p1.stacksize() == 26);
CHECK(p2.stacksize() == 26);
CHECK(p1.cardesTaken() == 0);
CHECK(p2.cardesTaken() == 0);
}
TEST_CASE("Test 3 - Game's functions") {
Player p1("Lior");
Player p2("Ely");
Game game(p1,p2);
//a full course of a game should be w/o errors
CHECK_NOTHROW(game.playAll());
CHECK_NOTHROW(game.printWiner());
CHECK_NOTHROW(game.printLog());
CHECK_NOTHROW(game.printStats());
Game game2(p1,p2);
CHECK_THROWS(game2.printLastTurn()); //no turn was yet played
for (int i=0;i<2;i++)
{
game2.playTurn();
CHECK(p1.stacksize() > 0);
CHECK(p2.stacksize() > 0);
}
game2.playAll();
bool res = (p1.stacksize() > 0 || p2.stacksize() > 0);
CHECK(res);
}