101 lines
2.7 KiB
C++
101 lines
2.7 KiB
C++
#ifdef TESTS_BUILD
|
|
|
|
#include <doctest.h>
|
|
#include "../../../src/Battling/ScriptHandling/ScriptSet.hpp"
|
|
|
|
using namespace CreatureLib;
|
|
using namespace CreatureLib::Battling;
|
|
|
|
class TestScript : public BattleScript {
|
|
private:
|
|
ArbUt::StringView _name;
|
|
|
|
public:
|
|
explicit TestScript(const ArbUt::StringView& name) : BattleScript(nullptr), _name(name){};
|
|
const ArbUt::StringView& GetName() const noexcept override { return _name; }
|
|
|
|
BattleScript* Clone(const ArbUt::OptionalBorrowedPtr<void>&) override { return new TestScript(_name); }
|
|
};
|
|
|
|
TEST_CASE("Empty script set count == 0") {
|
|
auto set = ScriptSet();
|
|
REQUIRE(set.Count() == 0);
|
|
}
|
|
|
|
TEST_CASE("Add script to script set") {
|
|
auto set = ScriptSet();
|
|
auto s = new TestScript("foobar");
|
|
set.Add(s);
|
|
REQUIRE(set.Count() == 1);
|
|
}
|
|
|
|
TEST_CASE("Add script to script set, then retrieve it") {
|
|
auto set = ScriptSet();
|
|
auto s = new TestScript("foobar");
|
|
set.Add(s);
|
|
REQUIRE(set.Count() == 1);
|
|
auto get = set.GetIterator().At(0);
|
|
REQUIRE(get->GetName() == "foobar");
|
|
}
|
|
|
|
TEST_CASE("Add two scripts to script set") {
|
|
auto set = ScriptSet();
|
|
auto s = new TestScript("foobar");
|
|
auto s2 = new TestScript("foobar2");
|
|
set.Add(s);
|
|
set.Add(s2);
|
|
REQUIRE(set.Count() == 2);
|
|
}
|
|
|
|
TEST_CASE("Add two scripts to script set, then retrieve them") {
|
|
auto set = ScriptSet();
|
|
auto s = new TestScript("foobar");
|
|
auto s2 = new TestScript("foobar2");
|
|
set.Add(s);
|
|
set.Add(s2);
|
|
REQUIRE(set.Count() == 2);
|
|
auto get1 = set.GetIterator().At(0);
|
|
auto get2 = set.GetIterator().At(1);
|
|
REQUIRE(get1->GetName() == "foobar");
|
|
REQUIRE(get2->GetName() == "foobar2");
|
|
}
|
|
|
|
TEST_CASE("Add script to script set, then remove it") {
|
|
auto set = ScriptSet();
|
|
auto s = new TestScript("foobar");
|
|
set.Add(s);
|
|
REQUIRE(set.Count() == 1);
|
|
set.Remove("foobar"_cnc.GetHash());
|
|
REQUIRE(set.Count() == 0);
|
|
auto& it = set.GetIterator();
|
|
REQUIRE(it.Count() == 0);
|
|
}
|
|
|
|
TEST_CASE("Add two scripts to script set, then remove them") {
|
|
auto set = ScriptSet();
|
|
auto s = new TestScript("foobar");
|
|
auto s2 = new TestScript("foobar2");
|
|
set.Add(s);
|
|
set.Add(s2);
|
|
REQUIRE(set.Count() == 2);
|
|
set.Remove("foobar"_cnc.GetHash());
|
|
REQUIRE(set.Count() == 1);
|
|
auto& it = set.GetIterator();
|
|
REQUIRE(it.At(0)->GetName() == "foobar2");
|
|
}
|
|
|
|
TEST_CASE("Add two scripts to script set, remove the first, get second by name") {
|
|
auto set = ScriptSet();
|
|
auto s = new TestScript("foobar");
|
|
auto s2 = new TestScript("foobar2");
|
|
set.Add(s);
|
|
set.Add(s2);
|
|
REQUIRE(set.Count() == 2);
|
|
set.Remove("foobar"_cnc.GetHash());
|
|
REQUIRE(set.Count() == 1);
|
|
auto retrieved = set.Get("foobar2"_cnc);
|
|
REQUIRE(retrieved == s2);
|
|
}
|
|
|
|
#endif
|