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
|
// SPDX-License-Identifier: GPL-2.0-or-later
#include "tarjeta.h"
#include <gtest/gtest.h>
#include "country.h"
TEST(Tarjeta, card_belongs_to_player)
{
const std::size_t checkCountry = 15;
const int myself = 23;
const int other = 42;
static_assert(checkCountry < COUNTRIES_CANT);
g_countries[checkCountry].tarjeta.numjug = other;
EXPECT_FALSE(card_belongs_to_player(myself, 0)) << "Players differ";
EXPECT_FALSE(card_belongs_to_player(myself, COUNTRIES_CANT))
<< "Country number out of range";
g_countries[checkCountry].tarjeta.numjug = myself;
EXPECT_TRUE(card_belongs_to_player(myself, checkCountry));
g_countries[checkCountry].tarjeta.numjug = -1;
}
TEST(TARJETA, can_trade_cards)
{
struct TestCase {
bool expectation;
TARJTIPO a, b, c;
};
TestCase const testTable[] = {
{ true, TARJ_GALEON, TARJ_GALEON, TARJ_GALEON}, // only one kind of cards
{false, TARJ_GALEON, TARJ_GALEON, TARJ_CANION}, // no match
{false, TARJ_GALEON, TARJ_GALEON, TARJ_GLOBO}, // no match
{ true, TARJ_GALEON, TARJ_GALEON, TARJ_COMODIN}, // joker
{false, TARJ_GALEON, TARJ_CANION, TARJ_GALEON}, // no match
{false, TARJ_GALEON, TARJ_CANION, TARJ_CANION}, // no match
{ true, TARJ_GALEON, TARJ_CANION, TARJ_GLOBO}, // 3 different cards
{ true, TARJ_GALEON, TARJ_CANION, TARJ_COMODIN}, // joker
{false, TARJ_GALEON, TARJ_GLOBO, TARJ_GALEON}, // no match
{ true, TARJ_GALEON, TARJ_GLOBO, TARJ_CANION}, // 3 different cards
{false, TARJ_GALEON, TARJ_GLOBO, TARJ_GLOBO}, // no match
{ true, TARJ_GALEON, TARJ_GLOBO, TARJ_COMODIN}, // joker
{ true, TARJ_GALEON, TARJ_COMODIN, TARJ_GALEON}, // joker
{ true, TARJ_GALEON, TARJ_COMODIN, TARJ_CANION}, // joker
{ true, TARJ_GALEON, TARJ_COMODIN, TARJ_GLOBO}, // joker
{ true, TARJ_GALEON, TARJ_COMODIN, TARJ_COMODIN}, // joker
{false, TARJ_CANION, TARJ_GALEON, TARJ_GALEON}, // no match
{false, TARJ_CANION, TARJ_GALEON, TARJ_CANION}, // no match
{ true, TARJ_CANION, TARJ_GALEON, TARJ_GLOBO}, // 3 different cards
{ true, TARJ_CANION, TARJ_GALEON, TARJ_COMODIN}, // joker
{false, TARJ_CANION, TARJ_CANION, TARJ_GALEON}, // no match
{ true, TARJ_CANION, TARJ_CANION, TARJ_CANION}, // only one kind of cards
{false, TARJ_CANION, TARJ_CANION, TARJ_GLOBO}, // no match
{ true, TARJ_CANION, TARJ_CANION, TARJ_COMODIN}, // joker
{ true, TARJ_CANION, TARJ_GLOBO, TARJ_GALEON}, // 3 different cards
{false, TARJ_CANION, TARJ_GLOBO, TARJ_CANION}, // no match
{false, TARJ_CANION, TARJ_GLOBO, TARJ_GLOBO}, // no match
{ true, TARJ_CANION, TARJ_GLOBO, TARJ_COMODIN}, // joker
{ true, TARJ_CANION, TARJ_COMODIN, TARJ_GALEON}, // joker
{ true, TARJ_CANION, TARJ_COMODIN, TARJ_CANION}, // joker
{ true, TARJ_CANION, TARJ_COMODIN, TARJ_GLOBO}, // joker
{ true, TARJ_CANION, TARJ_COMODIN, TARJ_COMODIN}, // joker
{false, TARJ_GLOBO, TARJ_GALEON, TARJ_GALEON}, // no match
{ true, TARJ_GLOBO, TARJ_GALEON, TARJ_CANION}, // 3 different cards
{false, TARJ_GLOBO, TARJ_GALEON, TARJ_GLOBO}, // no match
{ true, TARJ_GLOBO, TARJ_GALEON, TARJ_COMODIN}, // joker
{ true, TARJ_GLOBO, TARJ_CANION, TARJ_GALEON}, // 3 different cards
{false, TARJ_GLOBO, TARJ_CANION, TARJ_CANION}, // no match
{false, TARJ_GLOBO, TARJ_CANION, TARJ_GLOBO}, // no match
{ true, TARJ_GLOBO, TARJ_CANION, TARJ_COMODIN}, // joker
{false, TARJ_GLOBO, TARJ_GLOBO, TARJ_GALEON}, // no match
{false, TARJ_GLOBO, TARJ_GLOBO, TARJ_CANION}, // no match
{ true, TARJ_GLOBO, TARJ_GLOBO, TARJ_GLOBO}, // only one kind of cards
{ true, TARJ_GLOBO, TARJ_GLOBO, TARJ_COMODIN}, // joker
{ true, TARJ_GLOBO, TARJ_COMODIN, TARJ_GALEON}, // joker
{ true, TARJ_GLOBO, TARJ_COMODIN, TARJ_CANION}, // joker
{ true, TARJ_GLOBO, TARJ_COMODIN, TARJ_GLOBO}, // joker
{ true, TARJ_GLOBO, TARJ_COMODIN, TARJ_COMODIN}, // joker
{ true, TARJ_COMODIN, TARJ_GALEON, TARJ_GALEON}, // joker
{ true, TARJ_COMODIN, TARJ_GALEON, TARJ_CANION}, // joker
{ true, TARJ_COMODIN, TARJ_GALEON, TARJ_GLOBO}, // joker
{ true, TARJ_COMODIN, TARJ_GALEON, TARJ_COMODIN}, // joker
{ true, TARJ_COMODIN, TARJ_CANION, TARJ_GALEON}, // joker
{ true, TARJ_COMODIN, TARJ_CANION, TARJ_CANION}, // joker
{ true, TARJ_COMODIN, TARJ_CANION, TARJ_GLOBO}, // joker
{ true, TARJ_COMODIN, TARJ_CANION, TARJ_COMODIN}, // joker
{ true, TARJ_COMODIN, TARJ_GLOBO, TARJ_GALEON}, // joker
{ true, TARJ_COMODIN, TARJ_GLOBO, TARJ_CANION}, // joker
{ true, TARJ_COMODIN, TARJ_GLOBO, TARJ_GLOBO}, // joker
{ true, TARJ_COMODIN, TARJ_GLOBO, TARJ_COMODIN}, // joker
{ true, TARJ_COMODIN, TARJ_COMODIN, TARJ_GALEON}, // joker
{ true, TARJ_COMODIN, TARJ_COMODIN, TARJ_CANION}, // joker
{ true, TARJ_COMODIN, TARJ_COMODIN, TARJ_GLOBO}, // joker
{ true, TARJ_COMODIN, TARJ_COMODIN, TARJ_COMODIN}, // only one kind of cards
};
for(const auto& check: testTable) {
EXPECT_EQ(check.expectation, can_trade_cards(check.a, check.b, check.c))
<< "Failed for " << check.a << check.b << check.c;
}
}
|