CreatureLib/tests/BattleTests/ScriptTests/ScriptSetTests.cpp

87 lines
2.4 KiB
C++
Raw Normal View History

2019-11-17 09:27:18 +00:00
#ifdef TESTS_BUILD
#include <utility>
#include "../../../extern/catch.hpp"
#include "../../../src/Battling/ScriptHandling/ScriptSet.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
class TestScript : public Script {
private:
std::string _name;
public:
explicit TestScript(std::string name) : _name(std::move(name)){};
const std::string& GetName() const override { return _name; }
};
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {
2019-11-17 09:27:18 +00:00
auto set = ScriptSet();
REQUIRE(set.Count() == 0);
}
TEST_CASE("Add script to script set", "[Battling, Scripting]") {
2019-11-17 09:27:18 +00:00
auto set = ScriptSet();
auto s = new TestScript("foobar");
2019-11-17 09:27:18 +00:00
set.Add(s);
REQUIRE(set.Count() == 1);
}
TEST_CASE("Add script to script set, then retrieve it", "[Battling, Scripting]") {
2019-11-17 09:27:18 +00:00
auto set = ScriptSet();
auto s = new TestScript("foobar");
2019-11-17 09:27:18 +00:00
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", "[Battling, Scripting]") {
2019-11-17 09:27:18 +00:00
auto set = ScriptSet();
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);
}
TEST_CASE("Add two scripts to script set, then retrieve them", "[Battling, Scripting]") {
2019-11-17 09:27:18 +00:00
auto set = ScriptSet();
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);
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", "[Battling, Scripting]") {
2019-11-17 09:27:18 +00:00
auto set = ScriptSet();
auto s = new TestScript("foobar");
2019-11-17 09:27:18 +00:00
set.Add(s);
REQUIRE(set.Count() == 1);
set.Remove("foobar");
REQUIRE(set.Count() == 0);
auto it = set.GetIterator();
REQUIRE(it->empty());
}
TEST_CASE("Add two scripts to script set, then remove them", "[Battling, Scripting]") {
2019-11-17 09:27:18 +00:00
auto set = ScriptSet();
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);
set.Remove("foobar");
REQUIRE(set.Count() == 1);
auto it = set.GetIterator();
REQUIRE(it->at(0)->GetName() == "foobar2");
}
#endif