Move several classes from Core to Arbutils.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -13,7 +13,7 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
|
||||
auto choice1 = new PassTurnChoice(nullptr);
|
||||
auto choice2 = new AttackTurnChoice(nullptr, nullptr, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto rand = Core::Random();
|
||||
auto rand = Arbutils::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
@@ -33,7 +33,7 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]")
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto rand = Core::Random();
|
||||
auto rand = Arbutils::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
@@ -55,7 +55,7 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto rand = Core::Random();
|
||||
auto rand = Arbutils::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
@@ -77,7 +77,7 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]")
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto rand = Core::Random();
|
||||
auto rand = Arbutils::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
@@ -99,7 +99,7 @@ TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
auto choice2 = new AttackTurnChoice(nullptr, a2, CreatureIndex(0, 0));
|
||||
auto vec = std::vector<BaseTurnChoice*>{choice1, choice2};
|
||||
auto rand = Core::Random();
|
||||
auto rand = Arbutils::Random();
|
||||
TurnOrdering::OrderChoices(vec, rand);
|
||||
CHECK(vec[0] == choice2);
|
||||
CHECK(vec[1] == choice1);
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include <cstring>
|
||||
#include "../extern/catch.hpp"
|
||||
#include "../src/Core/Enum.hpp"
|
||||
|
||||
ENUM(TestEnum, uint8_t, Val1, Val2, Val3)
|
||||
|
||||
TEST_CASE("Parse Enum case sensitive", "[Utilities]") {
|
||||
CHECK(TestEnumHelper::Parse("Val1") == TestEnum::Val1);
|
||||
CHECK(TestEnumHelper::Parse("Val2") == TestEnum::Val2);
|
||||
CHECK(TestEnumHelper::Parse("Val3") == TestEnum::Val3);
|
||||
CHECK_THROWS(TestEnumHelper::Parse("Val4"));
|
||||
CHECK_THROWS(TestEnumHelper::Parse("val1"));
|
||||
}
|
||||
|
||||
TEST_CASE("Try Parse Enum case sensitive", "[Utilities]") {
|
||||
TestEnum v = static_cast<TestEnum>(255);
|
||||
REQUIRE(TestEnumHelper::TryParse("Val1", v));
|
||||
CHECK(v == TestEnum::Val1);
|
||||
REQUIRE(TestEnumHelper::TryParse("Val2", v));
|
||||
CHECK(v == TestEnum::Val2);
|
||||
REQUIRE(TestEnumHelper::TryParse("Val3", v));
|
||||
CHECK(v == TestEnum::Val3);
|
||||
CHECK_FALSE(TestEnumHelper::TryParse("Val4", v));
|
||||
CHECK_FALSE(TestEnumHelper::TryParse("val1", v));
|
||||
}
|
||||
|
||||
TEST_CASE("Parse Enum case insensitive", "[Utilities]") {
|
||||
CHECK(TestEnumHelper::Parse("Val1", true) == TestEnum::Val1);
|
||||
CHECK(TestEnumHelper::Parse("Val2", true) == TestEnum::Val2);
|
||||
CHECK(TestEnumHelper::Parse("Val3", true) == TestEnum::Val3);
|
||||
CHECK(TestEnumHelper::Parse("val1", true) == TestEnum::Val1);
|
||||
CHECK(TestEnumHelper::Parse("vAL2", true) == TestEnum::Val2);
|
||||
CHECK(TestEnumHelper::Parse("VaL3", true) == TestEnum::Val3);
|
||||
CHECK_THROWS(TestEnumHelper::Parse("Val4", true));
|
||||
}
|
||||
|
||||
TEST_CASE("Try Parse Enum case insensitive", "[Utilities]") {
|
||||
TestEnum v = static_cast<TestEnum>(255);
|
||||
REQUIRE(TestEnumHelper::TryParse("Val1", v, true));
|
||||
CHECK(v == TestEnum::Val1);
|
||||
REQUIRE(TestEnumHelper::TryParse("Val2", v, true));
|
||||
CHECK(v == TestEnum::Val2);
|
||||
REQUIRE(TestEnumHelper::TryParse("Val3", v, true));
|
||||
CHECK(v == TestEnum::Val3);
|
||||
REQUIRE(TestEnumHelper::TryParse("val1", v, true));
|
||||
CHECK(v == TestEnum::Val1);
|
||||
REQUIRE(TestEnumHelper::TryParse("vAL2", v, true));
|
||||
CHECK(v == TestEnum::Val2);
|
||||
REQUIRE(TestEnumHelper::TryParse("VaL3", v, true));
|
||||
CHECK(v == TestEnum::Val3);
|
||||
CHECK_FALSE(TestEnumHelper::TryParse("Val4", v, true));
|
||||
}
|
||||
|
||||
TEST_CASE("Enum To String", "[Utilities]") {
|
||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val1), "Val1") == 0);
|
||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val2), "Val2") == 0);
|
||||
CHECK(strcmp(TestEnumHelper::ToString(TestEnum::Val3), "Val3") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Enum Get Values", "[Utilities]") {
|
||||
auto vec = TestEnumHelper::GetValues();
|
||||
REQUIRE(vec.size() == 3);
|
||||
CHECK(vec[0] == TestEnum::Val1);
|
||||
CHECK(vec[1] == TestEnum::Val2);
|
||||
CHECK(vec[2] == TestEnum::Val3);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,119 +0,0 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include "../extern/catch.hpp"
|
||||
#include "../src/Core/Exceptions/CreatureException.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);
|
||||
}
|
||||
|
||||
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++) {
|
||||
arr[i] = rand.Get(0, 1);
|
||||
}
|
||||
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]") {
|
||||
auto rand = CreatureLib::Core::Random(10);
|
||||
const int size = 100000;
|
||||
int arr[size];
|
||||
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++) {
|
||||
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++;
|
||||
}
|
||||
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]") {
|
||||
auto rand = CreatureLib::Core::Random(10);
|
||||
const int size = 100000;
|
||||
int arr[size];
|
||||
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++) {
|
||||
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++;
|
||||
}
|
||||
INFO("Distribution: " << numZeros << "/" << numOnes << "/" << numTwos);
|
||||
CHECK(Approx(static_cast<float>(numZeros) / static_cast<float>(numOnes)).margin(0.01) == 1);
|
||||
CHECK(Approx(static_cast<float>(numZeros) / static_cast<float>(numTwos)).margin(0.01) == 1);
|
||||
CHECK(Approx(static_cast<float>(numOnes) / static_cast<float>(numTwos)).margin(0.01) == 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user