70 lines
2.5 KiB
C++
70 lines
2.5 KiB
C++
#ifdef TESTS_BUILD
|
|
#include <doctest.h>
|
|
#include "../../src/Battling/Models/Battle.hpp"
|
|
#include "../../src/Battling/Models/CreateCreature.hpp"
|
|
#include "../TestLibrary/TestLibrary.hpp"
|
|
|
|
using namespace CreatureLib::Battling;
|
|
TEST_CASE("Create basic creature") {
|
|
auto library = TestLibrary::Get();
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Get creature species") {
|
|
auto library = TestLibrary::Get();
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1"_cnc);
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Get creature level") {
|
|
auto library = TestLibrary::Get();
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
REQUIRE(creature->GetLevel() == 1);
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Get creature variant when unset") {
|
|
auto library = TestLibrary::Get();
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
REQUIRE(creature->GetVariant()->GetName() == "default");
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Get creature nickname when unset") {
|
|
auto library = TestLibrary::Get();
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).WithNickname("foo").Create();
|
|
REQUIRE(creature->GetNickname() == "foo");
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Increase creature stat boost") {
|
|
auto library = TestLibrary::Get();
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
creature->ChangeStatBoost(CreatureLib::Library::Statistic::PhysicalAttack, 6);
|
|
REQUIRE(creature->GetStatBoost(CreatureLib::Library::Statistic::PhysicalAttack) == 6);
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Override Creature talent") {
|
|
auto library = TestLibrary::Get();
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
creature->OverrideActiveTalent("foobar");
|
|
REQUIRE(creature->GetActiveTalent()->GetName() == "foobar"_cnc);
|
|
delete creature;
|
|
}
|
|
|
|
TEST_CASE("Creature can be deleted before battle is deleted") {
|
|
// This should not happen during normal battle executions, but can happen for certain GC solutions. We should not
|
|
// segfault in this case, but deal with it properly.
|
|
auto library = TestLibrary::Get();
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
auto battle = new Battle(library, {});
|
|
auto side = battle->GetSides()[0];
|
|
side->SetCreature(creature, 0);
|
|
delete creature;
|
|
delete battle;
|
|
}
|
|
|
|
#endif |