From 3a2c9f4c61a304b983b3de91aa4eb75b48026df5 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 17 Nov 2019 10:27:18 +0100 Subject: [PATCH] Adds tests for ScriptSets --- .../ScriptTests/ScriptSetTests.cpp | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/BattleTests/ScriptTests/ScriptSetTests.cpp diff --git a/tests/BattleTests/ScriptTests/ScriptSetTests.cpp b/tests/BattleTests/ScriptTests/ScriptSetTests.cpp new file mode 100644 index 0000000..ed78521 --- /dev/null +++ b/tests/BattleTests/ScriptTests/ScriptSetTests.cpp @@ -0,0 +1,92 @@ +#ifdef TESTS_BUILD + +#include + +#include "../../../extern/catch.hpp" +#include "../../../src/Battling/ScriptHandling/ScriptSet.hpp" + +using namespace CreatureLib; +using namespace CreatureLib::Battling; + + +TEST_CASE( "Empty script set count == 0", "[Battling, Scripting]" ) { + auto set = ScriptSet(); + REQUIRE(set.Count() == 0); +} + +TEST_CASE( "Add script to script set", "[Battling, Scripting]" ) { + auto set = ScriptSet(); + auto s = new Script("foobar"); + set.Add(s); + REQUIRE(set.Count() == 1); + delete s; +} + +TEST_CASE( "Add script to script set, then retrieve it", "[Battling, Scripting]" ) { + auto set = ScriptSet(); + auto s = new Script("foobar"); + set.Add(s); + REQUIRE(set.Count() == 1); + auto get = set.GetIterator()->at(0); + REQUIRE(get->GetName() == "foobar"); + delete s; +} + +TEST_CASE( "Add two scripts to script set", "[Battling, Scripting]" ) { + auto set = ScriptSet(); + auto s = new Script("foobar"); + auto s2 = new Script("foobar2"); + set.Add(s); + set.Add(s2); + REQUIRE(set.Count() == 2); + delete s; + delete s2; +} + +TEST_CASE( "Add two scripts to script set, then retrieve them", "[Battling, Scripting]" ) { + auto set = ScriptSet(); + auto s = new Script("foobar"); + auto s2 = new Script("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"); + delete s; + delete s2; +} + +TEST_CASE( "Add script to script set, then remove it", "[Battling, Scripting]" ) { + auto set = ScriptSet(); + auto s = new Script("foobar"); + set.Add(s); + REQUIRE(set.Count() == 1); + set.Remove("foobar"); + REQUIRE(set.Count() == 0); + auto it = set.GetIterator(); + REQUIRE(it->empty()); + delete s; +} + +TEST_CASE( "Add two scripts to script set, then remove them", "[Battling, Scripting]" ) { + auto set = ScriptSet(); + auto s = new Script("foobar"); + auto s2 = new Script("foobar2"); + 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"); + delete s; +} + + + +#endif + + +