diff --git a/tests/BattleTests/TurnOrderTests.cpp b/tests/BattleTests/TurnOrderTests.cpp index fb4cdc1..cba2231 100644 --- a/tests/BattleTests/TurnOrderTests.cpp +++ b/tests/BattleTests/TurnOrderTests.cpp @@ -25,4 +25,78 @@ TEST_CASE( "Turn ordering: Attack before pass", "[Battling]" ) { delete choice2; } +TEST_CASE( "Turn ordering: High priority goes before no priority", "[Battling]" ) { + auto l = GetLibrary()->GetAttackLibrary(); + auto choice1 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown)); + auto choice2 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown)); + auto vec = std::vector{choice1, choice2}; + auto rand = Core::Random(); + TurnOrdering::OrderChoices(vec,rand); + CHECK(vec[0] == choice2); + CHECK(vec[1] == choice1); + vec = std::vector{choice2, choice1}; + TurnOrdering::OrderChoices(vec,rand); + CHECK(vec[0] == choice2); + CHECK(vec[1] == choice1); + + delete choice1; + delete choice2; +} + +TEST_CASE( "Turn ordering: Higher priority goes before high priority", "[Battling]" ) { + auto l = GetLibrary()->GetAttackLibrary(); + auto choice1 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown)); + auto choice2 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown)); + auto vec = std::vector{choice1, choice2}; + auto rand = Core::Random(); + TurnOrdering::OrderChoices(vec,rand); + CHECK(vec[0] == choice2); + CHECK(vec[1] == choice1); + vec = std::vector{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 low priority", "[Battling]" ) { + auto l = GetLibrary()->GetAttackLibrary(); + auto choice1 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown)); + auto choice2 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown)); + auto vec = std::vector{choice1, choice2}; + auto rand = Core::Random(); + TurnOrdering::OrderChoices(vec,rand); + CHECK(vec[0] == choice2); + CHECK(vec[1] == choice1); + vec = std::vector{choice2, choice1}; + TurnOrdering::OrderChoices(vec,rand); + CHECK(vec[0] == choice2); + CHECK(vec[1] == choice1); + + delete choice1; + delete choice2; +} + +TEST_CASE( "Turn ordering: No priority goes before low priority", "[Battling]" ) { + auto l = GetLibrary()->GetAttackLibrary(); + auto choice1 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown)); + auto choice2 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown)); + auto vec = std::vector{choice1, choice2}; + auto rand = Core::Random(); + TurnOrdering::OrderChoices(vec,rand); + CHECK(vec[0] == choice2); + CHECK(vec[1] == choice1); + vec = std::vector{choice2, choice1}; + TurnOrdering::OrderChoices(vec,rand); + CHECK(vec[0] == choice2); + CHECK(vec[1] == choice1); + + delete choice1; + delete choice2; +} + + + #endif \ No newline at end of file diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 95bb5f8..99310b1 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -20,6 +20,14 @@ static SpeciesLibrary* BuildSpeciesLibrary(){ static AttackLibrary* BuildAttackLibrary(){ auto l = new AttackLibrary(); + l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical, + 20, 100, 30, AttackTarget::AdjacentOpponent,0, {})); + l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical, + 20, 100, 30, AttackTarget::AdjacentOpponent,1, {})); + l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical, + 20, 100, 30, AttackTarget::AdjacentOpponent,2, {})); + l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical, + 20, 100, 30, AttackTarget::AdjacentOpponent,-1, {})); return l; }