CreatureLib/tests/BattleTests/TurnOrderTests.cpp

103 lines
4.5 KiB
C++
Raw Normal View History

#ifdef TESTS_BUILD
#include "../../extern/doctest.hpp"
#include "../../src/Battling/Flow/TurnOrdering.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.hpp"
2019-10-31 11:31:31 +00:00
using namespace CreatureLib;
using namespace CreatureLib::Battling;
TEST_CASE("Turn ordering: Attack before pass") {
2020-03-22 12:42:26 +00:00
auto lib = TestLibrary::Get();
2020-04-09 16:19:21 +00:00
auto learnedAttack =
LearnedAttack(lib->GetAttackLibrary()->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
2020-06-02 11:06:24 +00:00
auto choice1 = std::make_shared<PassTurnChoice>(nullptr);
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, &learnedAttack, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2020-06-02 11:06:24 +00:00
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
}
TEST_CASE("Turn ordering: High priority goes before no priority") {
2020-05-24 17:01:47 +00:00
const auto& l = TestLibrary::Get()->GetAttackLibrary();
2020-04-09 16:19:21 +00:00
auto a1 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
2020-06-02 11:06:24 +00:00
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
2019-10-31 12:03:41 +00:00
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2020-06-02 11:06:24 +00:00
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec);
2019-10-31 12:03:41 +00:00
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2019-10-31 12:33:32 +00:00
delete a1;
delete a2;
2019-10-31 12:03:41 +00:00
}
TEST_CASE("Turn ordering: Higher priority goes before high priority") {
2020-05-24 17:01:47 +00:00
const auto& l = TestLibrary::Get()->GetAttackLibrary();
2020-04-09 16:19:21 +00:00
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
2020-06-02 11:06:24 +00:00
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
2019-10-31 12:03:41 +00:00
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2020-06-02 11:06:24 +00:00
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec);
2019-10-31 12:03:41 +00:00
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2019-10-31 12:33:32 +00:00
delete a1;
delete a2;
2019-10-31 12:03:41 +00:00
}
TEST_CASE("Turn ordering: High priority goes before low priority") {
2020-05-24 17:01:47 +00:00
const auto& l = TestLibrary::Get()->GetAttackLibrary();
2020-04-09 16:19:21 +00:00
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
2020-06-02 11:06:24 +00:00
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
2019-10-31 12:03:41 +00:00
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2020-06-02 11:06:24 +00:00
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec);
2019-10-31 12:03:41 +00:00
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2019-10-31 12:33:32 +00:00
delete a1;
delete a2;
2019-10-31 12:03:41 +00:00
}
TEST_CASE("Turn ordering: No priority goes before low priority") {
2020-05-24 17:01:47 +00:00
const auto& l = TestLibrary::Get()->GetAttackLibrary();
2020-04-09 16:19:21 +00:00
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
2020-06-02 11:06:24 +00:00
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
2019-10-31 12:03:41 +00:00
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2020-06-02 11:06:24 +00:00
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec);
2019-10-31 12:03:41 +00:00
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
2019-10-31 12:33:32 +00:00
delete a1;
delete a2;
2019-10-31 12:03:41 +00:00
}
#endif