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
|
// SPDX-License-Identifier: GPL-2.0-or-later
#include "stats.h"
#include <gtest/gtest.h>
std::ostream& operator <<(std::ostream& os, PLAYER_STATS const& ps)
{
os << "PLAYER_STATS{"
<< ps.countries_won << ", "
<< ps.armies_killed
<< ", {";
const char* sep="";
for(auto const turn: ps.continents_turn) {
os << sep << turn;
sep = ", ";
}
os << "}, "
<< ps.players_killed << ", "
<< ps.score << "}";
return os;
}
bool operator == (const PLAYER_STATS &a, const PLAYER_STATS& b)
{
return memcmp(&a, &b, sizeof(a)) == 0;
}
TEST(Stats, init)
{
PLAYER_STATS ps{.countries_won = 1,
.armies_killed= 2,
.continents_turn = {1, 2, 3, 4, 5, 6},
.players_killed = 4,
.score = 5};
stats_init(&ps);
EXPECT_EQ(PLAYER_STATS{}, ps);
}
TEST(Stats, score)
{
PLAYER_STATS ps{.countries_won = 1,
.armies_killed= 2,
.continents_turn = {1, 2, 3, 4, 5, 6},
.players_killed = 4,
.score = 5};
CONT const continents[CONTINENTE_LAST] {
[CONTINENTE_AMERICASUR] = {.fichas_x_cont=23},
[CONTINENTE_AMERICANORTE] = {.fichas_x_cont=42},
[CONTINENTE_AFRICA] = {.fichas_x_cont=17},
[CONTINENTE_OCEANIA] = {.fichas_x_cont=5},
[CONTINENTE_EUROPA] = {.fichas_x_cont=99},
[CONTINENTE_ASIA] = {.fichas_x_cont=8},
};
PLAYER_STATS const expected{.countries_won = 1,
.armies_killed= 2,
.continents_turn = {1, 2, 3, 4, 5, 6},
.players_killed = 4,
.score = 1*5 // won countries*5
+ 2*2 // kiled armies * 2
// turns a continent was owned
// * extra armies per continent
+ 1*23 + 2*42 + 3*17 + 4*5 + 5*99 + 6*8};
stats_score(&ps, continents);
EXPECT_EQ(expected, ps);
}
|