Try and catch more edge cases where setIndex would be invalid.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-04-17 16:31:03 +02:00
parent 8f9f2b2b8d
commit 13df99a6cc
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 13 additions and 4 deletions

View File

@ -25,6 +25,9 @@ namespace CreatureLib::Battling {
_index++;
while (HasNext()) {
if (_scripts[_index].HasValue()) {
if (_scripts[_index].IsSet()) {
_setIndex = -1;
}
return;
}
_index++;

View File

@ -132,24 +132,30 @@ TEST_CASE("Script Aggregator properly iterates multiple script sets.") {
BattleScript* script1 = new TestScript("test");
BattleScript* script2 = new TestScript("test2");
BattleScript* script3 = new TestScript("test3");
BattleScript* script4 = new TestScript("test4");
auto ran = 0;
auto set1 = ScriptSet();
set1.Add(script2);
set1.Add(script3);
auto set2 = ScriptSet();
set2.Add(script1);
set2.Add(script4);
auto vec = ArbUt::List<ScriptWrapper>{
ScriptWrapper::FromSet(&set1),
ScriptWrapper::FromSet(&set2),
};
auto aggr = ScriptAggregator(vec);
auto ran = 0;
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
next.value().As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 4);
CHECK(ran == 3);
aggr.Reset();
ran = 0;
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
next.value().As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
}
TEST_CASE("Script Aggregator properly iterates when empty.") {