Used ClangFormat style guide I'm happy with.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-11-28 12:55:22 +01:00
parent 3b685ae782
commit a8730d983f
91 changed files with 946 additions and 1121 deletions

View File

@@ -1,13 +1,13 @@
#ifdef TESTS_BUILD
#include "../TestLibrary/TestLibrary.cpp"
#include "../../src/Battling/Models/BattleSide.hpp"
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.cpp"
using namespace CreatureLib::Battling;
TEST_CASE( "Set Choice one-sized side", "[Battling]" ) {
TEST_CASE("Set Choice one-sized side", "[Battling]") {
auto side = BattleSide(nullptr, 1);
auto c = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
side.SetCreature(c, 0);
@@ -17,7 +17,7 @@ TEST_CASE( "Set Choice one-sized side", "[Battling]" ) {
delete c;
}
TEST_CASE( "Set Choice one-sized side, validate all choices set", "[Battling]" ) {
TEST_CASE("Set Choice one-sized side, validate all choices set", "[Battling]") {
auto side = BattleSide(nullptr, 1);
auto c = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
side.SetCreature(c, 0);
@@ -29,7 +29,7 @@ TEST_CASE( "Set Choice one-sized side, validate all choices set", "[Battling]" )
delete c;
}
TEST_CASE( "Set Choice two-sized side", "[Battling]" ) {
TEST_CASE("Set Choice two-sized side", "[Battling]") {
auto side = BattleSide(nullptr, 2);
auto c1 = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
auto c2 = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
@@ -45,7 +45,7 @@ TEST_CASE( "Set Choice two-sized side", "[Battling]" ) {
delete c2;
}
TEST_CASE( "Set Choice two-sized side, validate all choices set", "[Battling]" ) {
TEST_CASE("Set Choice two-sized side, validate all choices set", "[Battling]") {
auto side = BattleSide(nullptr, 2);
auto c1 = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
auto c2 = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
@@ -64,5 +64,4 @@ TEST_CASE( "Set Choice two-sized side, validate all choices set", "[Battling]" )
delete c2;
}
#endif

View File

@@ -1,31 +1,25 @@
#ifdef TESTS_BUILD
#include <utility>
#include "../../../extern/catch.hpp"
#include "../../../src/Battling/ScriptHandling/ScriptAggregator.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
class TestScript : public Script{
class TestScript : public Script {
public:
explicit TestScript(std::string name) : Script(std::move(name)){};
void TestMethod(int& runCount) {
runCount++;
}
void TestMethod(int& runCount) { runCount++; }
};
TEST_CASE( "Script Aggregator properly iterates containing script.", "[Battling, Scripting]" ) {
TEST_CASE("Script Aggregator properly iterates containing script.", "[Battling, Scripting]") {
Script* script = new TestScript("test");
auto ran = 0;
auto vec = std::vector<ScriptWrapper>{&script};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()){
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
@@ -34,14 +28,14 @@ TEST_CASE( "Script Aggregator properly iterates containing script.", "[Battling,
delete script;
}
TEST_CASE( "Script Aggregator properly iterates multiple scripts.", "[Battling, Scripting]" ) {
TEST_CASE("Script Aggregator properly iterates multiple scripts.", "[Battling, Scripting]") {
Script* script = new TestScript("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
auto ran = 0;
auto vec = std::vector<ScriptWrapper>{&script, &script2, &script3};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()){
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
@@ -52,7 +46,7 @@ TEST_CASE( "Script Aggregator properly iterates multiple scripts.", "[Battling,
delete script3;
}
TEST_CASE( "Script Aggregator properly iterates Script Set.", "[Battling, Scripting]" ) {
TEST_CASE("Script Aggregator properly iterates Script Set.", "[Battling, Scripting]") {
Script* script = new TestScript("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
@@ -62,8 +56,8 @@ TEST_CASE( "Script Aggregator properly iterates Script Set.", "[Battling, Script
set.Add(script2);
set.Add(script3);
auto vec = std::vector<ScriptWrapper>{&set};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()){
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
@@ -74,7 +68,7 @@ TEST_CASE( "Script Aggregator properly iterates Script Set.", "[Battling, Script
delete script3;
}
TEST_CASE( "Script Aggregator properly iterates data of Script Set and Script.", "[Battling, Scripting]" ) {
TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.", "[Battling, Scripting]") {
Script* script = new TestScript("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
@@ -83,8 +77,8 @@ TEST_CASE( "Script Aggregator properly iterates data of Script Set and Script.",
set.Add(script2);
set.Add(script3);
auto vec = std::vector<ScriptWrapper>{&set, &script};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()){
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
@@ -95,7 +89,7 @@ TEST_CASE( "Script Aggregator properly iterates data of Script Set and Script.",
delete script3;
}
TEST_CASE( "Script Aggregator properly iterates data of Script and Script Set.", "[Battling, Scripting]" ) {
TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.", "[Battling, Scripting]") {
Script* script = new TestScript("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
@@ -104,8 +98,8 @@ TEST_CASE( "Script Aggregator properly iterates data of Script and Script Set.",
set.Add(script2);
set.Add(script3);
auto vec = std::vector<ScriptWrapper>{&script, &set};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()){
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
@@ -116,7 +110,7 @@ TEST_CASE( "Script Aggregator properly iterates data of Script and Script Set.",
delete script3;
}
TEST_CASE( "Script Aggregator properly iterates data of Script, Script Set and Script.", "[Battling, Scripting]" ) {
TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Script.", "[Battling, Scripting]") {
Script* script = new TestScript("test");
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
@@ -126,8 +120,8 @@ TEST_CASE( "Script Aggregator properly iterates data of Script, Script Set and S
set.Add(script2);
set.Add(script3);
auto vec = std::vector<ScriptWrapper>{&script, &set, &script4};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()){
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
@@ -139,22 +133,22 @@ TEST_CASE( "Script Aggregator properly iterates data of Script, Script Set and S
delete script4;
}
TEST_CASE( "Script Aggregator properly iterates when empty.", "[Battling, Scripting]" ) {
TEST_CASE("Script Aggregator properly iterates when empty.", "[Battling, Scripting]") {
auto ran = 0;
auto vec = std::vector<ScriptWrapper>{};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()){
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
throw CreatureException("Aggregator returned a script, but should have been empty.");
}
CHECK(ran == 0);
}
TEST_CASE( "Script Aggregator properly iterates empty Script Set.", "[Battling, Scripting]" ) {
TEST_CASE("Script Aggregator properly iterates empty Script Set.", "[Battling, Scripting]") {
auto ran = 0;
auto set = ScriptSet();
auto vec = std::vector<ScriptWrapper>{&set};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()){
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next == nullptr);
ran++;
@@ -162,8 +156,4 @@ TEST_CASE( "Script Aggregator properly iterates empty Script Set.", "[Battling,
CHECK(ran == 1);
}
#endif

View File

@@ -1,20 +1,18 @@
#ifdef TESTS_BUILD
#include <utility>
#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]" ) {
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]" ) {
TEST_CASE("Add script to script set", "[Battling, Scripting]") {
auto set = ScriptSet();
auto s = new Script("foobar");
set.Add(s);
@@ -22,7 +20,7 @@ TEST_CASE( "Add script to script set", "[Battling, Scripting]" ) {
delete s;
}
TEST_CASE( "Add script to script set, then retrieve it", "[Battling, Scripting]" ) {
TEST_CASE("Add script to script set, then retrieve it", "[Battling, Scripting]") {
auto set = ScriptSet();
auto s = new Script("foobar");
set.Add(s);
@@ -32,7 +30,7 @@ TEST_CASE( "Add script to script set, then retrieve it", "[Battling, Scripting]"
delete s;
}
TEST_CASE( "Add two scripts to script set", "[Battling, Scripting]" ) {
TEST_CASE("Add two scripts to script set", "[Battling, Scripting]") {
auto set = ScriptSet();
auto s = new Script("foobar");
auto s2 = new Script("foobar2");
@@ -43,7 +41,7 @@ TEST_CASE( "Add two scripts to script set", "[Battling, Scripting]" ) {
delete s2;
}
TEST_CASE( "Add two scripts to script set, then retrieve them", "[Battling, Scripting]" ) {
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");
@@ -58,7 +56,7 @@ TEST_CASE( "Add two scripts to script set, then retrieve them", "[Battling, Scri
delete s2;
}
TEST_CASE( "Add script to script set, then remove it", "[Battling, Scripting]" ) {
TEST_CASE("Add script to script set, then remove it", "[Battling, Scripting]") {
auto set = ScriptSet();
auto s = new Script("foobar");
set.Add(s);
@@ -70,7 +68,7 @@ TEST_CASE( "Add script to script set, then remove it", "[Battling, Scripting]" )
delete s;
}
TEST_CASE( "Add two scripts to script set, then remove them", "[Battling, Scripting]" ) {
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");
@@ -85,9 +83,4 @@ TEST_CASE( "Add two scripts to script set, then remove them", "[Battling, Script
delete s2;
}
#endif

View File

@@ -1,50 +1,44 @@
#ifdef TESTS_BUILD
#include <utility>
#include "../../../extern/catch.hpp"
#include "../../../src/Battling/ScriptHandling/ScriptSource.hpp"
#include <utility>
#include "../../../extern/catch.hpp"
#include "../../../src/Battling/ScriptHandling/ScriptAggregator.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
class TestScript : public Script{
class TestScript : public Script {
public:
explicit TestScript(std::string name) : Script(std::move(name)){};
void TestMethod(int& runCount) {
runCount++;
}
void TestMethod(int& runCount) { runCount++; }
};
class ScriptSourceWithScriptPtr : public ScriptSource{
class ScriptSourceWithScriptPtr : public ScriptSource {
public:
Script* ScriptPtr = nullptr;
protected:
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override {
scripts.emplace_back(&ScriptPtr);
}
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { scripts.emplace_back(&ScriptPtr); }
};
class ScriptSourceWithScriptSet : public ScriptSource{
class ScriptSourceWithScriptSet : public ScriptSource {
public:
ScriptSet Set;
protected:
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override {
scripts.emplace_back(&Set);
}
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { scripts.emplace_back(&Set); }
};
TEST_CASE( "Script source with unset script ptr.", "[Battling, Scripting]" ) {
TEST_CASE("Script source with unset script ptr.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptPtr();
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
CHECK(first == nullptr);
}
TEST_CASE( "Script source with script ptr being set.", "[Battling, Scripting]" ) {
TEST_CASE("Script source with script ptr being set.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptPtr();
source.ScriptPtr = new Script("foobar");
auto scripts = source.GetScriptIterator();
@@ -53,7 +47,7 @@ TEST_CASE( "Script source with script ptr being set.", "[Battling, Scripting]" )
delete source.ScriptPtr;
}
TEST_CASE( "Script source with script ptr being set after first iteration.", "[Battling, Scripting]" ) {
TEST_CASE("Script source with script ptr being set after first iteration.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptPtr();
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
@@ -65,25 +59,25 @@ TEST_CASE( "Script source with script ptr being set after first iteration.", "[B
delete source.ScriptPtr;
}
TEST_CASE( "Script source with empty script set.", "[Battling, Scripting]" ) {
TEST_CASE("Script source with empty script set.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptSet();
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
CHECK(first == nullptr);
}
TEST_CASE( "Script source with single item script set.", "[Battling, Scripting]" ) {
TEST_CASE("Script source with single item script set.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptSet();
auto s = new Script("foobar");
source.Set.Add(s);
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
CHECK(first != nullptr);
CHECK (first->GetName() == "foobar");
CHECK(first->GetName() == "foobar");
delete s;
}
TEST_CASE( "Script source with multiple item script set.", "[Battling, Scripting]" ) {
TEST_CASE("Script source with multiple item script set.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptSet();
auto s = new Script("foobar");
auto s2 = new Script("foobar2");
@@ -92,14 +86,12 @@ TEST_CASE( "Script source with multiple item script set.", "[Battling, Scripting
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
CHECK(first != nullptr);
CHECK (first->GetName() == "foobar");
CHECK(first->GetName() == "foobar");
auto second = scripts.GetNext();
CHECK(second != nullptr);
CHECK (second->GetName() == "foobar2");
CHECK(second->GetName() == "foobar2");
delete s;
delete s2;
}
#endif

View File

@@ -1,23 +1,23 @@
#ifdef TESTS_BUILD
#include "../TestLibrary/TestLibrary.cpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/Flow/TurnOrdering.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.cpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
TEST_CASE( "Turn ordering: Attack before pass", "[Battling]" ) {
TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
auto choice1 = new PassTurnChoice(nullptr);
auto choice2 = new AttackTurnChoice(nullptr, nullptr, Target(0,0));
auto choice2 = new AttackTurnChoice(nullptr, nullptr, Target(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Core::Random();
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
@@ -25,19 +25,19 @@ TEST_CASE( "Turn ordering: Attack before pass", "[Battling]" ) {
delete choice2;
}
TEST_CASE( "Turn ordering: High priority goes before no priority", "[Battling]" ) {
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
auto l = GetLibrary()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0,0));
auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0,0));
auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0, 0));
auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Core::Random();
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
@@ -47,19 +47,19 @@ TEST_CASE( "Turn ordering: High priority goes before no priority", "[Battling]"
delete a2;
}
TEST_CASE( "Turn ordering: Higher priority goes before high priority", "[Battling]" ) {
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
auto l = GetLibrary()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0,0));
auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0,0));
auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0, 0));
auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Core::Random();
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
@@ -69,19 +69,19 @@ TEST_CASE( "Turn ordering: Higher priority goes before high priority", "[Battlin
delete a2;
}
TEST_CASE( "Turn ordering: High priority goes before low priority", "[Battling]" ) {
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
auto l = GetLibrary()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0,0));
auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0,0));
auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0, 0));
auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Core::Random();
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
@@ -91,19 +91,19 @@ TEST_CASE( "Turn ordering: High priority goes before low priority", "[Battling]"
delete a2;
}
TEST_CASE( "Turn ordering: No priority goes before low priority", "[Battling]" ) {
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
auto l = GetLibrary()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0,0));
auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0,0));
auto choice1 = new AttackTurnChoice(nullptr, a1, Target(0, 0));
auto choice2 = new AttackTurnChoice(nullptr, a2, Target(0, 0));
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
auto rand = Core::Random();
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
vec = std::vector<BaseTurnChoice*>{choice2, choice1};
TurnOrdering::OrderChoices(vec,rand);
TurnOrdering::OrderChoices(vec, rand);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
@@ -113,6 +113,4 @@ TEST_CASE( "Turn ordering: No priority goes before low priority", "[Battling]" )
delete a2;
}
#endif

View File

@@ -3,41 +3,41 @@
#include "../TestLibrary/TestLibrary.cpp"
using namespace CreatureLib::Library;
TEST_CASE( "Create basic creature", "[Library]" ) {
TEST_CASE("Create basic creature", "[Library]") {
auto library = GetLibrary();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
delete creature;
}
TEST_CASE( "Get creature species", "[Library]" ) {
TEST_CASE("Get creature species", "[Library]") {
auto library = GetLibrary();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1");
delete creature;
}
TEST_CASE( "Get creature level", "[Library]" ) {
TEST_CASE("Get creature level", "[Library]") {
auto library = GetLibrary();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
REQUIRE(creature->GetLevel() == 1);
delete creature;
}
TEST_CASE( "Get creature variant when unset", "[Library]" ) {
TEST_CASE("Get creature variant when unset", "[Library]") {
auto library = GetLibrary();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
REQUIRE(creature->GetVariant()->GetName() == "default");
delete creature;
}
TEST_CASE( "Get creature nickname when unset", "[Library]" ) {
TEST_CASE("Get creature nickname when unset", "[Library]") {
auto library = GetLibrary();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
REQUIRE(creature->GetNickname() == "testSpecies1");
delete creature;
}
TEST_CASE( "Get creature stat potentials when unset", "[Library]" ) {
TEST_CASE("Get creature stat potentials when unset", "[Library]") {
auto library = GetLibrary();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto potentials = creature->GetStatPotential();
@@ -50,7 +50,7 @@ TEST_CASE( "Get creature stat potentials when unset", "[Library]" ) {
delete creature;
}
TEST_CASE( "Get creature stat experience when unset", "[Library]" ) {
TEST_CASE("Get creature stat experience when unset", "[Library]") {
auto library = GetLibrary();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto experiences = creature->GetStatExperience();

View File

@@ -4,34 +4,34 @@
#include "../../extern/catch.hpp"
#include "../TestLibrary/TestLibrary.cpp"
TEST_CASE( "Can Create Species Library", "[Library]" ) {
auto l = BuildSpeciesLibrary();
REQUIRE(l != nullptr);
delete l;
TEST_CASE("Can Create Species Library", "[Library]") {
auto l = BuildSpeciesLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE( "Can Create Attack Library", "[Library]" ) {
auto l = BuildAttackLibrary();
REQUIRE(l != nullptr);
delete l;
TEST_CASE("Can Create Attack Library", "[Library]") {
auto l = BuildAttackLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE( "Can Create Item Library", "[Library]" ) {
auto l = BuildItemLibrary();
REQUIRE(l != nullptr);
delete l;
TEST_CASE("Can Create Item Library", "[Library]") {
auto l = BuildItemLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE( "Can Create Growthrate Library", "[Library]" ) {
auto l = BuildGrowthRateLibrary();
REQUIRE(l != nullptr);
delete l;
TEST_CASE("Can Create Growthrate Library", "[Library]") {
auto l = BuildGrowthRateLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE( "Can Create Data Library", "[Library]" ) {
auto l = BuildLibrary();
REQUIRE(l != nullptr);
delete l;
TEST_CASE("Can Create Data Library", "[Library]") {
auto l = BuildLibrary();
REQUIRE(l != nullptr);
delete l;
}
#endif

View File

@@ -1,9 +1,9 @@
#ifdef TESTS_BUILD
#include "../extern/catch.hpp"
#include "../src/Core/Random.hpp"
#include "../src/Core/Exceptions/CreatureException.hpp"
#include "../src/Core/Random.hpp"
TEST_CASE( "Random ints", "[Utilities]" ) {
TEST_CASE("Random ints", "[Utilities]") {
auto rand = CreatureLib::Core::Random(10);
CHECK(rand.Get() == 1656398469);
CHECK(rand.Get() == 641584702);
@@ -17,7 +17,7 @@ TEST_CASE( "Random ints", "[Utilities]" ) {
CHECK(rand.Get() == 1252673902);
}
TEST_CASE( "Random ints with limit", "[Utilities]" ) {
TEST_CASE("Random ints with limit", "[Utilities]") {
auto rand = CreatureLib::Core::Random(10);
CHECK(rand.Get(10) == 7);
CHECK(rand.Get(10) == 2);
@@ -39,10 +39,9 @@ TEST_CASE( "Random ints with limit", "[Utilities]" ) {
CHECK(rand.Get(2) == 0);
CHECK(rand.Get(2) == 0);
CHECK(rand.Get(2) == 0);
}
TEST_CASE( "Random ints with upper and bottom", "[Utilities]" ) {
TEST_CASE("Random ints with upper and bottom", "[Utilities]") {
auto rand = CreatureLib::Core::Random(10);
CHECK(rand.Get(10, 30) == 25);
CHECK(rand.Get(10, 30) == 15);
@@ -56,55 +55,60 @@ TEST_CASE( "Random ints with upper and bottom", "[Utilities]" ) {
CHECK(rand.Get(10, 30) == 21);
}
TEST_CASE( "Random distribution (max 0, min 1)", "[Utilities]" ) {
TEST_CASE("Random distribution (max 0, min 1)", "[Utilities]") {
auto rand = CreatureLib::Core::Random(10);
const int size = 100000;
int arr[size];
for (size_t i = 0; i < size; i++){
for (size_t i = 0; i < size; i++) {
arr[i] = rand.Get(0, 1);
}
for (size_t i = 0; i < size; i++){
for (size_t i = 0; i < size; i++) {
if (arr[i] != 0)
throw CreatureException("We expected a value of 0 here, but got a " + std::to_string(arr[i]));
}
}
TEST_CASE( "Random distribution (max 0, min 2)", "[Utilities]" ) {
TEST_CASE("Random distribution (max 0, min 2)", "[Utilities]") {
auto rand = CreatureLib::Core::Random(10);
const int size = 100000;
int arr[size];
for (size_t i = 0; i < size; i++){
for (size_t i = 0; i < size; i++) {
arr[i] = rand.Get(0, 2);
}
auto numZeros = 0;
auto numOnes = 0;
for (size_t i = 0; i < size; i++){
for (size_t i = 0; i < size; i++) {
if (arr[i] != 0 && arr[i] != 1)
throw CreatureException("We expected a value of 0 or 1 here, but got a " + std::to_string(arr[i]));
if (arr[i] == 0) numZeros++;
else numOnes++;
if (arr[i] == 0)
numZeros++;
else
numOnes++;
}
auto div = static_cast<float>(numZeros) / static_cast<float>(numOnes);
INFO("Distribution: " << numZeros << "/" << numOnes);
CHECK(Approx(div).margin(0.01) == 1);
}
TEST_CASE( "Random distribution (max 0, min 3)", "[Utilities]" ) {
TEST_CASE("Random distribution (max 0, min 3)", "[Utilities]") {
auto rand = CreatureLib::Core::Random(10);
const int size = 100000;
int arr[size];
for (size_t i = 0; i < size; i++){
for (size_t i = 0; i < size; i++) {
arr[i] = rand.Get(0, 3);
}
auto numZeros = 0;
auto numOnes = 0;
auto numTwos = 0;
for (size_t i = 0; i < size; i++){
for (size_t i = 0; i < size; i++) {
if (arr[i] != 0 && arr[i] != 1 && arr[i] != 2)
throw CreatureException("We expected a value between 0 and 2 here, but got a " + std::to_string(arr[i]));
if (arr[i] == 0) numZeros++;
else if (arr[i] == 1) numOnes++;
else numTwos++;
if (arr[i] == 0)
numZeros++;
else if (arr[i] == 1)
numOnes++;
else
numTwos++;
}
INFO("Distribution: " << numZeros << "/" << numOnes << "/" << numTwos);
CHECK(Approx(static_cast<float>(numZeros) / static_cast<float>(numOnes)).margin(0.01) == 1);
@@ -112,6 +116,4 @@ TEST_CASE( "Random distribution (max 0, min 3)", "[Utilities]" ) {
CHECK(Approx(static_cast<float>(numOnes) / static_cast<float>(numTwos)).margin(0.01) == 1);
}
#endif

View File

@@ -7,41 +7,41 @@ using namespace CreatureLib::Library;
using namespace CreatureLib::Battling;
static BattleLibrary* __library = nullptr;
static SpeciesLibrary* BuildSpeciesLibrary(){
static SpeciesLibrary* BuildSpeciesLibrary() {
auto l = new SpeciesLibrary();
l->LoadSpecies("testSpecies1", new CreatureSpecies(0, "testSpecies1",
new SpeciesVariant("default", 1,1, 10, {0, 1},
StatisticSet<uint16_t >(10,10,10,10,10,10),
{"testTalent"}, {"testSecretTalent"},
new LearnableAttacks(100)),
0.5f, "testGrowthRate", 5, 100));
l->LoadSpecies("testSpecies1",
new CreatureSpecies(
0, "testSpecies1",
new SpeciesVariant("default", 1, 1, 10, {0, 1}, StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10),
{"testTalent"}, {"testSecretTalent"}, new LearnableAttacks(100)),
0.5f, "testGrowthRate", 5, 100));
return l;
}
static AttackLibrary* BuildAttackLibrary(){
static AttackLibrary* BuildAttackLibrary() {
auto l = new AttackLibrary();
l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical,
20, 100, 30, AttackTarget::AdjacentOpponent,0, {}));
l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical,
20, 100, 30, AttackTarget::AdjacentOpponent,1, {}));
l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical,
20, 100, 30, AttackTarget::AdjacentOpponent,2, {}));
l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical,
20, 100, 30, AttackTarget::AdjacentOpponent,-1, {}));
l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 0, {}));
l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 1, {}));
l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 2, {}));
l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, -1, {}));
return l;
}
static ItemLibrary* BuildItemLibrary(){
static ItemLibrary* BuildItemLibrary() {
auto l = new ItemLibrary();
return l;
}
static GrowthRateLibrary* BuildGrowthRateLibrary(){
static GrowthRateLibrary* BuildGrowthRateLibrary() {
auto l = new GrowthRateLibrary();
return l;
}
static TypeLibrary* BuildTypeLibrary(){
static TypeLibrary* BuildTypeLibrary() {
auto l = new TypeLibrary();
l->RegisterType("testType1");
l->RegisterType("testType2");
@@ -49,17 +49,16 @@ static TypeLibrary* BuildTypeLibrary(){
return l;
}
static BattleLibrary* BuildLibrary(){
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
auto battleLib = new BattleLibrary(l, new BattleStatCalculator(), new DamageLibrary(),
new CriticalLibrary(), new ScriptResolver());
static BattleLibrary* BuildLibrary() {
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(), BuildItemLibrary(),
BuildGrowthRateLibrary(), BuildTypeLibrary());
auto battleLib = new BattleLibrary(l, new BattleStatCalculator(), new DamageLibrary(), new CriticalLibrary(),
new ScriptResolver());
return battleLib;
}
[[maybe_unused]]
static BattleLibrary* GetLibrary(){
if (__library == nullptr){
[[maybe_unused]] static BattleLibrary* GetLibrary() {
if (__library == nullptr) {
__library = BuildLibrary();
}
return __library;