File: player_check.cpp

package info (click to toggle)
teg 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,036 kB
  • sloc: cpp: 16,819; xml: 1,313; makefile: 268; sh: 195; ansic: 112
file content (132 lines) | stat: -rw-r--r-- 3,259 bytes parent folder | download
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
128
129
130
131
132
// SPDX-License-Identifier: GPL-2.0-or-later

#include "player.h"
#include "../common/country.h"

#include <gtest/gtest.h>

namespace teg::server
{

TEST(player, init_player)
{
	SPLAYER player{.hizo_canje=true, .turno_conq=12, .tot_countries=5,
	               .tot_armies=323, .tot_cards=8, .tot_exchanges=7,
	               .fichasc_armies=17, .fichasc_conts = 9};
	player_initplayer(&player);
	EXPECT_FALSE(player.hizo_canje);
	EXPECT_EQ(0, player.tot_exchanges);
	EXPECT_EQ(0, player.tot_countries);
	EXPECT_EQ(0, player.tot_cards);
	EXPECT_EQ(0, player.tot_armies);
	EXPECT_EQ(0, player.turno_conq);
	EXPECT_EQ(-1, player.country_src);
	EXPECT_EQ(-1, player.country_dst);
	EXPECT_EQ(-1, player.mission);
	EXPECT_EQ(0, player.fichasc_armies);
	EXPECT_EQ(0, player.fichasc_conts);
}

TEST(player, is_playing)
{
	{
		SPLAYER player{.is_player = false, .estado=PLAYER_STATUS_POSTFICHAS};
		EXPECT_FALSE(player_is_playing(&player));
	}

	{
		SPLAYER player{.is_player = true, .estado=PLAYER_STATUS_HABILITADO};
		EXPECT_FALSE(player_is_playing(&player));
	}

	{
		SPLAYER player{.is_player = true, .estado=PLAYER_STATUS_START};
		EXPECT_TRUE(player_is_playing(&player));
	}

	{
		SPLAYER player{.is_player = true, .estado=PLAYER_STATUS_TURNOEND};
		EXPECT_TRUE(player_is_playing(&player));
	}

	{
		SPLAYER player{.is_player = true, .estado=PLAYER_STATUS_LAST};
		EXPECT_FALSE(player_is_playing(&player));
	}
}

TEST(player, lister_countries)
{
	countries_init();
	g_countries[0].numjug = 23;
	g_countries[1].numjug = 23;
	g_countries[35].numjug = 23;

	SPLAYER player{.numjug = 23};

	int continent_counts[CONTINENTE_LAST] = {0};

	player_listar_countries(&player, continent_counts);

	int const ref[CONTINENTE_LAST] = {
		[CONTINENTE_AMERICASUR] = 2,
		[CONTINENTE_AMERICANORTE] = 0,
		[CONTINENTE_AFRICA] = 0,
		[CONTINENTE_OCEANIA] = 0,
		[CONTINENTE_EUROPA] = 0,
		[CONTINENTE_ASIA] = 1,
	};

	for(std::size_t i=0; i<CONTINENTE_LAST; i++) {
		EXPECT_EQ(ref[i], continent_counts[i]) << "Failed at index " << i;
	}
}

void check_player_count(int countries, int armies)
{
	SPLAYER player{.tot_countries = countries};
	EXPECT_EQ(armies, player_fichasc_cant(&player));
}

TEST(player, army_count)
{
	check_player_count(0, 3);
	check_player_count(6, 3);
	check_player_count(7, 3);
	check_player_count(42, 21);
}

TEST(player, clear_turn)
{
	const int player_number = 42;
	SPLAYER player{.numjug = player_number, .turno_conq = 23,
	               .estado=PLAYER_STATUS_POSTFICHAS2,
	               .country_src=15, .country_dst=51};

	auto const belongs_to_player = [](int country_number)->bool {
		return (country_number==3) || (country_number==7) || (country_number==9);
	};

	for(std::size_t i=0; i<COUNTRIES_CANT; i++) {
		g_countries[i].numjug = belongs_to_player(i)
		                        ? 42
		                        : 14;
		g_countries[i].ejer_reagrupe = i;
	}

	player_clear_turn(&player);
	EXPECT_EQ(0, player.turno_conq);
	EXPECT_EQ(PLAYER_STATUS_IDLE, player.estado);
	EXPECT_EQ(-1, player.country_src);
	EXPECT_EQ(-1, player.country_dst);

	for(std::size_t i=0; i<COUNTRIES_CANT; i++) {
		if(belongs_to_player(i)) {
			EXPECT_EQ(0, g_countries[i].ejer_reagrupe) << i;
		} else {
			EXPECT_EQ(i, g_countries[i].ejer_reagrupe) << i;
		}
	}
}

}