CreatureLib/tests/BattleTests/TurnOrderTests.cpp

117 lines
4.4 KiB
C++

#ifdef TESTS_BUILD
#include "../../extern/catch.hpp"
#include "../../src/Battling/Flow/TurnOrdering.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
auto choice1 = new PassTurnChoice(nullptr);
auto choice2 = new AttackTurnChoice(nullptr, nullptr, CreatureIndex(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Arbutils::Random();
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
delete choice1;
delete choice2;
}
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
auto l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("standard"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("highPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Arbutils::Random();
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
delete choice1;
delete choice2;
delete a1;
delete a2;
}
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
auto l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("highPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("higherPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Arbutils::Random();
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
delete choice1;
delete choice2;
delete a1;
delete a2;
}
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
auto l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("lowPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("higherPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Arbutils::Random();
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
delete choice1;
delete choice2;
delete a1;
delete a2;
}
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
auto l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("lowPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("standard"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Arbutils::Random();
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
delete choice1;
delete choice2;
delete a1;
delete a2;
}
#endif