CreatureLib/tests/BattleTests/CloneTests.cpp

58 lines
1.8 KiB
C++
Raw Normal View History

#ifdef TESTS_BUILD
#include "../../extern/doctest.hpp"
#include "../../src/Battling/History/HistoryElements/AttackUseHistory.hpp"
#include "../../src/Battling/Models/Battle.hpp"
#include "../../src/Battling/Models/BattleSide.hpp"
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace CreatureLib::Battling;
TEST_CASE("Clone battle, test basic functionality") {
auto lib = TestLibrary::Get();
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto party = CreatureParty(6);
party.SwapInto(0, creature);
auto bp = ArbUt::List<BattleParty*>();
bp.Append(new BattleParty(&party, {CreatureIndex(0, 0)}));
auto battle = Battle(lib, bp);
battle.SwitchCreature(0, 0, creature);
auto clone = battle.Clone();
REQUIRE_NE(battle.GetCreature(0, 0), clone->GetCreature(0, 0));
REQUIRE(battle.GetCreature(0, 0).GetValue()->GetSpecies() == clone->GetCreature(0, 0).GetValue()->GetSpecies());
auto clonedParty = clone->GetParties().At(0)->GetParty().GetRaw();
delete clone;
delete clonedParty;
}
TEST_CASE("Clone battle, test history history holder") {
auto lib = TestLibrary::Get();
auto battle = Battle(lib, {});
auto clone = battle.Clone();
clone->RegisterHistoryElement<AttackUseHistory>(nullptr);
clone->RegisterHistoryElement<AttackUseHistory>(nullptr);
delete clone;
}
TEST_CASE("Clone battle, test randomness") {
auto lib = TestLibrary::Get();
auto battle = Battle(lib, {});
auto clone = battle.Clone();
REQUIRE_EQ(battle.GetRandom()->Get(), clone->GetRandom()->Get());
REQUIRE_EQ(battle.GetRandom()->Get(), clone->GetRandom()->Get());
REQUIRE_EQ(battle.GetRandom()->Get(), clone->GetRandom()->Get());
delete clone;
}
#endif