More defensive programming.
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-08-30 13:14:33 +02:00
parent 32f75f4a47
commit 3233daf9ab
5 changed files with 60 additions and 25 deletions

View File

@@ -17,11 +17,11 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, &learnedAttack, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
auto rand = ArbUt::Random();
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
}
@@ -34,11 +34,11 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]")
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
auto rand = ArbUt::Random();
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
@@ -54,11 +54,11 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
auto rand = ArbUt::Random();
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
delete a1;
@@ -73,11 +73,11 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]")
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
auto rand = ArbUt::Random();
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
@@ -93,11 +93,11 @@ TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
auto rand = ArbUt::Random();
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice2, choice1};
TurnOrdering::OrderChoices(vec, rand);
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);

View File

@@ -56,6 +56,33 @@ TEST_CASE("Use damaging move", "[Integrations]") {
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(Statistic::Health));
}
TEST_CASE("Run more turns", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =
CreateCreature(library, "testSpecies1"_cnc, 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
CreatureParty party1{c1};
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
auto c3 =
CreateCreature(library, "testSpecies1"_cnc, 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown).Create();
CreatureParty party2{c2, c3};
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c2);
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
battle.TrySetChoice(new PassTurnChoice(c2));
REQUIRE(c2->IsFainted());
battle.SwitchCreature(1, 0, c3);
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
battle.TrySetChoice(new PassTurnChoice(c3));
}
TEST_CASE("Finish battle when all battle of one side have fainted", "[Integrations]") {
auto library = TestLibrary::Get();
auto c1 =