forked from cpp-exercises/CardWar_a
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
69 lines (61 loc) · 2.05 KB
/
Test.cpp
File metadata and controls
69 lines (61 loc) · 2.05 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
#include "doctest.h"
#include "sources/game.hpp"
#include "sources/card.hpp"
#include "sources/player.hpp"
#include <stdexcept>
#include <iostream>
#include <string>
using namespace std;
using namespace ariel;
TEST_CASE("Creation of Player"){
Player p1("Yann"); // After the creation of a player , he got 2 stack(one for his cards and
// the second for the wining card) , also a win_rate and draw_rate
Player p2("David");
CHECK(p1.getName() == "Yann");
CHECK(p2.getName() == "David");
CHECK_FALSE(p1.getName() == "yann");
CHECK(p1.stacksize() == 26);
CHECK(p2.stacksize() == 26);
CHECK(p1.cardesTaken() == 0);
CHECK(p2.cardesTaken() == 0);
string stats = p1.Stat_Player();
CHECK_FALSE(stats.empty()); // check if the string is empty
}
TEST_CASE("Creation of the card"){
Card card_Ten(10, "Heart");
CHECK(card_Ten.get_NumCard() == 10);
CHECK(card_Ten.get_Type() == "Heart");
card_Ten.set_type("Diamond");
CHECK(card_Ten.get_Type() == "Diamond");
card_Ten.set_numCard(8);
CHECK(card_Ten.get_NumCard() == 8);
CHECK_THROWS([](){Card card(18, "House");}()); // Lambda expression to test the constructor of Card
}
TEST_CASE("Creation of a Game"){
Player p1("Alice");
Player p2("Bob");
Game game(p1,p2);
CHECK(game.get_sizeDeck() == 52);
CHECK(p1.stacksize() == 26);
CHECK(p2.stacksize() == 26);
CHECK(p1.cardesTaken() == 0);
CHECK(p2.cardesTaken() == 0);
}
TEST_CASE("During the game"){
Player p1("Alice");
Player p2("Bob");
Game game(p1,p2);
for (int i=0;i<5;i++) {
game.playTurn();
}
// Every player play 5 card or more if there are draws
CHECK(p1.stacksize() <= 21);
CHECK(p2.stacksize() <= 21);
// There is a winner
game.playAll();
// size of deck + size of deck of each player may be equal to 52 == number of card in 1 game
CHECK((game.get_sizeDeck()+p1.stacksize()+p1.cardesTaken()+p2.stacksize()+p2.cardesTaken()) == 52);
CHECK(game.get_sizeDeck() == 0);
CHECK(p1.stacksize() == 0);
CHECK(p2.stacksize() == 0);
}