2019-11-17 09:27:18 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
|
|
|
|
#include <utility>
|
2020-09-25 10:43:08 +00:00
|
|
|
#include "../../../extern/doctest.hpp"
|
2019-11-17 09:27:18 +00:00
|
|
|
#include "../../../src/Battling/ScriptHandling/ScriptSet.hpp"
|
|
|
|
|
|
|
|
using namespace CreatureLib;
|
|
|
|
using namespace CreatureLib::Battling;
|
|
|
|
|
2021-03-07 09:26:41 +00:00
|
|
|
class TestScript : public BattleScript {
|
2020-02-23 11:58:13 +00:00
|
|
|
private:
|
2020-06-26 15:08:23 +00:00
|
|
|
ArbUt::StringView _name;
|
2020-02-23 11:58:13 +00:00
|
|
|
|
|
|
|
public:
|
2021-10-29 19:31:01 +00:00
|
|
|
explicit TestScript(const ArbUt::StringView& name) : BattleScript(nullptr), _name(name){};
|
2020-06-26 15:08:23 +00:00
|
|
|
const ArbUt::StringView& GetName() const noexcept override { return _name; }
|
2021-04-11 13:20:50 +00:00
|
|
|
|
2021-10-29 19:55:49 +00:00
|
|
|
BattleScript* Clone(const ArbUt::OptionalBorrowedPtr<void>&) override { return new TestScript(_name); }
|
2020-02-23 11:58:13 +00:00
|
|
|
};
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Empty script set count == 0") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
|
|
|
REQUIRE(set.Count() == 0);
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Add script to script set") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
REQUIRE(set.Count() == 1);
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Add script to script set, then retrieve it") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
REQUIRE(set.Count() == 1);
|
2020-06-02 13:03:31 +00:00
|
|
|
auto get = set.GetIterator().At(0);
|
2019-11-17 09:27:18 +00:00
|
|
|
REQUIRE(get->GetName() == "foobar");
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Add two scripts to script set") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
|
|
|
auto s2 = new TestScript("foobar2");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
set.Add(s2);
|
|
|
|
REQUIRE(set.Count() == 2);
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Add two scripts to script set, then retrieve them") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
|
|
|
auto s2 = new TestScript("foobar2");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
set.Add(s2);
|
|
|
|
REQUIRE(set.Count() == 2);
|
2020-06-02 13:03:31 +00:00
|
|
|
auto get1 = set.GetIterator().At(0);
|
|
|
|
auto get2 = set.GetIterator().At(1);
|
2019-11-17 09:27:18 +00:00
|
|
|
REQUIRE(get1->GetName() == "foobar");
|
|
|
|
REQUIRE(get2->GetName() == "foobar2");
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Add script to script set, then remove it") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
REQUIRE(set.Count() == 1);
|
2020-04-09 16:19:21 +00:00
|
|
|
set.Remove("foobar"_cnc.GetHash());
|
2019-11-17 09:27:18 +00:00
|
|
|
REQUIRE(set.Count() == 0);
|
2020-06-02 13:03:31 +00:00
|
|
|
auto& it = set.GetIterator();
|
|
|
|
REQUIRE(it.Count() == 0);
|
2019-11-17 09:27:18 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Add two scripts to script set, then remove them") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
|
|
|
auto s2 = new TestScript("foobar2");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
set.Add(s2);
|
|
|
|
REQUIRE(set.Count() == 2);
|
2020-04-09 16:19:21 +00:00
|
|
|
set.Remove("foobar"_cnc.GetHash());
|
2019-11-17 09:27:18 +00:00
|
|
|
REQUIRE(set.Count() == 1);
|
2020-06-02 13:03:31 +00:00
|
|
|
auto& it = set.GetIterator();
|
|
|
|
REQUIRE(it.At(0)->GetName() == "foobar2");
|
2019-11-17 09:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|