-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.cpp
127 lines (112 loc) · 3.96 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
/*
* Email: sam.lazareanu@gmail.com
* ID: ****6281
* @SamuraiPolix - Samuel Lazareanu
*/
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "Catan.hpp"
#include "Player.hpp"
#include "Types.hpp"
#include "Board.hpp"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <ctime>
using std::cout, std::endl, std::vector, std::string, std::rand, std::srand, std::time, std::shuffle, std::default_random_engine, std::invalid_argument, std::cin;
using namespace ariel;
// starting positions for settlements and roads
static const size_t numbers[18] = {29, 29, 30, 20, 20, 21, 33, 33, 34, 24, 24, 25, 10, 10, 9, 41, 41, 42};
size_t setupIndex = 0;
TEST_CASE("Test Catan turn order") {
Player p1("Sam");
Player p2("John");
Player p3("Jane");
ariel::Catan game(p1, p2, p3);
game.ChooseStartingPlayer(0);
CHECK(game.getCurrentPlayer().getSimpleName() == "Sam");
game.nextPlayer();
CHECK(game.getCurrentPlayer().getSimpleName() == "John");
game.nextPlayer();
CHECK(game.getCurrentPlayer().getSimpleName() == "Jane");
game.nextPlayer();
CHECK(game.getCurrentPlayer().getSimpleName() == "Sam");
}
TEST_CASE("Test Catan giveResources") {
Player p1("Sam");
Player p2("John");
Player p3("Jane");
ariel::Catan game(p1, p2, p3);
game.ChooseStartingPlayer(0);
// make sure everyone starts with 0 resources
for (Player* player : game.getPlayers()) {
CHECK(player->numOfResources() == 0);
}
// amounts shouldnt change because no settlements
game.giveResources(2);
for (int i = 3; i < 6+6; i++) {
if (i == 7) continue;
game.giveResources(i); // roll everything except 7
}
for (Player* player : game.getPlayers()) {
CHECK(player->numOfResources() == 0);
}
// set each player with 1 settlement and road - still no change in resources if no rolls (second settlment gives starting resources)
setupIndex = 0;
Player* player;
for (int i = 0; i < 3; i++) {
player = &game.getCurrentPlayer();
player->placeSettlement(numbers[setupIndex], game.getBoard());
setupIndex++;
player->placeRoad(numbers[setupIndex], numbers[setupIndex+1], game.getBoard());
setupIndex += 2;
player->endTurn(game);
}
for (Player* player : game.getPlayers()) {
CHECK(player->numOfResources() == 0);
}
// set second settlement for each player
for (int i = 0; i < 3; i++) {
player = &game.getCurrentPlayer();
player->placeSettlement(numbers[setupIndex], game.getBoard());
setupIndex++;
player->placeRoad(numbers[setupIndex], numbers[setupIndex+1], game.getBoard());
setupIndex += 2;
player->endTurn(game);
}
for (Player* player : game.getPlayers()) {
cout << player->getSimpleName() << " has " << player->numOfResources() << " resources" << endl;
CHECK(player->numOfResources() != 0);
}
}
TEST_CASE("Test winner"){
Player p1("Sam");
Player p2("John");
Player p3("Jane");
ariel::Catan game(p1, p2, p3);
game.ChooseStartingPlayer(0);
// set each player with 1 settlement and road
setupIndex = 0;
Player* player;
for (int i = 0; i < 3; i++) {
player = &game.getCurrentPlayer();
player->placeSettlement(numbers[setupIndex], game.getBoard());
setupIndex++;
player->placeRoad(numbers[setupIndex], numbers[setupIndex+1], game.getBoard());
setupIndex += 2;
player->endTurn(game);
}
game.getCurrentPlayer().addVictoryPoints(9);
// set second settlement for each player
for (int i = 0; i < 3; i++) {
player = &game.getCurrentPlayer();
player->placeSettlement(numbers[setupIndex], game.getBoard());
setupIndex++;
player->placeRoad(numbers[setupIndex], numbers[setupIndex+1], game.getBoard());
setupIndex += 2;
player->endTurn(game);
}
CHECK(game.printWinner() == 0);
}