Initial commit
This commit is contained in:
66
tests/LibraryTests/CreatureTests.cpp
Normal file
66
tests/LibraryTests/CreatureTests.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include "../../src/Library/CreateCreature.hpp"
|
||||
#include "TestLibrary.cpp"
|
||||
|
||||
using namespace CreatureLib::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]" ) {
|
||||
auto library = GetLibrary();
|
||||
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
|
||||
REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1");
|
||||
delete creature;
|
||||
}
|
||||
|
||||
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]" ) {
|
||||
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]" ) {
|
||||
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]" ) {
|
||||
auto library = GetLibrary();
|
||||
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
|
||||
auto potentials = creature->GetStatPotential();
|
||||
REQUIRE(potentials.GetHealth() == 0);
|
||||
REQUIRE(potentials.GetPhysicalAttack() == 0);
|
||||
REQUIRE(potentials.GetPhysicalDefense() == 0);
|
||||
REQUIRE(potentials.GetMagicalAttack() == 0);
|
||||
REQUIRE(potentials.GetMagicalDefense() == 0);
|
||||
REQUIRE(potentials.GetSpeed() == 0);
|
||||
delete creature;
|
||||
}
|
||||
|
||||
TEST_CASE( "Get creature stat experience when unset", "[Library]" ) {
|
||||
auto library = GetLibrary();
|
||||
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
|
||||
auto experiences = creature->GetStatExperience();
|
||||
REQUIRE(experiences.GetHealth() == 0);
|
||||
REQUIRE(experiences.GetPhysicalAttack() == 0);
|
||||
REQUIRE(experiences.GetPhysicalDefense() == 0);
|
||||
REQUIRE(experiences.GetMagicalAttack() == 0);
|
||||
REQUIRE(experiences.GetMagicalDefense() == 0);
|
||||
REQUIRE(experiences.GetSpeed() == 0);
|
||||
delete creature;
|
||||
}
|
||||
|
||||
#endif
|
||||
51
tests/LibraryTests/TestLibrary.cpp
Normal file
51
tests/LibraryTests/TestLibrary.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include "../../extern/catch.hpp"
|
||||
#include "../../src/Library/DataLibrary.hpp"
|
||||
|
||||
using namespace CreatureLib::Core;
|
||||
using namespace CreatureLib::Library;
|
||||
static DataLibrary* __library = nullptr;
|
||||
|
||||
static SpeciesLibrary* BuildSpeciesLibrary(){
|
||||
auto l = new SpeciesLibrary();
|
||||
l->LoadSpecies("testSpecies1", new CreatureSpecies(0, "testSpecies1",
|
||||
new SpeciesVariant("default", 1,1, 10, {"fire", "water"}, StatisticSet(10,10,10,10,10,10),
|
||||
{"testTalent"}, {"testSecretTalent"}),
|
||||
0.5f, "testGrowthRate", 5, 100));
|
||||
return l;
|
||||
}
|
||||
|
||||
static AttackLibrary* BuildAttackLibrary(){
|
||||
auto l = new AttackLibrary();
|
||||
return l;
|
||||
}
|
||||
|
||||
static ItemLibrary* BuildItemLibrary(){
|
||||
auto l = new ItemLibrary();
|
||||
return l;
|
||||
}
|
||||
|
||||
static GrowthRateLibrary* BuildGrowthRateLibrary(){
|
||||
auto l = new GrowthRateLibrary();
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
static DataLibrary* BuildLibrary(){
|
||||
auto l = new DataLibrary(BuildSpeciesLibrary(), BuildAttackLibrary(), BuildItemLibrary(), BuildGrowthRateLibrary());
|
||||
return l;
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
static DataLibrary* GetLibrary(){
|
||||
if (__library == nullptr){
|
||||
__library = BuildLibrary();
|
||||
}
|
||||
return __library;
|
||||
}
|
||||
|
||||
#ifndef LIBRARY_BUILD_TESTS
|
||||
#define LIBRARY_BUILD_TESTS
|
||||
|
||||
#endif
|
||||
#endif
|
||||
37
tests/LibraryTests/TestLibraryTests.cpp
Normal file
37
tests/LibraryTests/TestLibraryTests.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include "../../extern/catch.hpp"
|
||||
#include "TestLibrary.cpp"
|
||||
|
||||
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 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 Data Library", "[Library]" ) {
|
||||
auto l = BuildLibrary();
|
||||
REQUIRE(l != nullptr);
|
||||
delete l;
|
||||
}
|
||||
|
||||
#endif
|
||||
58
tests/RandomTests.cpp
Normal file
58
tests/RandomTests.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include "../extern/catch.hpp"
|
||||
#include "../src/Core/Random.hpp"
|
||||
|
||||
TEST_CASE( "Random ints", "[Utilities]" ) {
|
||||
auto rand = CreatureLib::Core::Random(10);
|
||||
CHECK(rand.Get() == 1656398469);
|
||||
CHECK(rand.Get() == 641584702);
|
||||
CHECK(rand.Get() == 44564466);
|
||||
CHECK(rand.Get() == 1062123783);
|
||||
CHECK(rand.Get() == 1360749216);
|
||||
CHECK(rand.Get() == 951367352);
|
||||
CHECK(rand.Get() == 1608044094);
|
||||
CHECK(rand.Get() == 1786516046);
|
||||
CHECK(rand.Get() == 1070535660);
|
||||
CHECK(rand.Get() == 1252673902);
|
||||
}
|
||||
|
||||
TEST_CASE( "Random ints with limit", "[Utilities]" ) {
|
||||
auto rand = CreatureLib::Core::Random(10);
|
||||
CHECK(rand.Get(10) == 7);
|
||||
CHECK(rand.Get(10) == 2);
|
||||
CHECK(rand.Get(10) == 0);
|
||||
CHECK(rand.Get(10) == 4);
|
||||
CHECK(rand.Get(10) == 6);
|
||||
CHECK(rand.Get(10) == 4);
|
||||
CHECK(rand.Get(10) == 7);
|
||||
CHECK(rand.Get(10) == 8);
|
||||
CHECK(rand.Get(10) == 4);
|
||||
CHECK(rand.Get(10) == 5);
|
||||
|
||||
CHECK(rand.Get(2) == 0);
|
||||
CHECK(rand.Get(2) == 0);
|
||||
CHECK(rand.Get(2) == 0);
|
||||
CHECK(rand.Get(2) == 1);
|
||||
CHECK(rand.Get(2) == 1);
|
||||
CHECK(rand.Get(2) == 0);
|
||||
CHECK(rand.Get(2) == 0);
|
||||
CHECK(rand.Get(2) == 0);
|
||||
CHECK(rand.Get(2) == 0);
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
CHECK(rand.Get(10, 30) == 10);
|
||||
CHECK(rand.Get(10, 30) == 19);
|
||||
CHECK(rand.Get(10, 30) == 22);
|
||||
CHECK(rand.Get(10, 30) == 18);
|
||||
CHECK(rand.Get(10, 30) == 24);
|
||||
CHECK(rand.Get(10, 30) == 26);
|
||||
CHECK(rand.Get(10, 30) == 19);
|
||||
CHECK(rand.Get(10, 30) == 21);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user