Switch from Catch2 to DocTest for unit tests.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
51c7ba1c50
commit
3e9fd2bea8
|
@ -14,7 +14,7 @@ steps:
|
||||||
- cmake -GNinja -DCMAKE_BUILD_TYPE=Debug . -B build-debug -DSTATICC=ON -DTESTS=ON
|
- cmake -GNinja -DCMAKE_BUILD_TYPE=Debug . -B build-debug -DSTATICC=ON -DTESTS=ON
|
||||||
- cmake --build build-debug --target all -- -j 4
|
- cmake --build build-debug --target all -- -j 4
|
||||||
- cd build-debug
|
- cd build-debug
|
||||||
- ./ArbutilsTests -s --durations yes --use-colour yes
|
- ./ArbutilsTests -s --duration=true --force-colour=true
|
||||||
- name: test-release-linux
|
- name: test-release-linux
|
||||||
image: deukhoofd/linux64builder
|
image: deukhoofd/linux64builder
|
||||||
environment:
|
environment:
|
||||||
|
@ -26,8 +26,8 @@ steps:
|
||||||
- cmake -GNinja -DCMAKE_BUILD_TYPE=Release . -B build-release -DSTATICC=ON -DTESTS=ON
|
- cmake -GNinja -DCMAKE_BUILD_TYPE=Release . -B build-release -DSTATICC=ON -DTESTS=ON
|
||||||
- cmake --build build-release --target all -- -j 4
|
- cmake --build build-release --target all -- -j 4
|
||||||
- cd build-debug
|
- cd build-debug
|
||||||
- ./ArbutilsTests -s --durations yes --use-colour yes
|
- ./ArbutilsTests -s --duration=true --force-colour=true
|
||||||
- valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no --error-exitcode=1 ./ArbutilsTests exclude:"Throw exception get stack trace"
|
- valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no --error-exitcode=1 ./ArbutilsTests --test-case-exclude="Throw exception get stack trace"
|
||||||
- name: test-release-windows
|
- name: test-release-windows
|
||||||
image: deukhoofd/windowsbuilder
|
image: deukhoofd/windowsbuilder
|
||||||
commands:
|
commands:
|
||||||
|
@ -38,7 +38,7 @@ steps:
|
||||||
- cmake -GNinja -DCMAKE_BUILD_TYPE=Release . -B build-release-windows -D CMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc -D CMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DWINDOWS=ON -DSTATICC=ON -DTESTS=ON
|
- cmake -GNinja -DCMAKE_BUILD_TYPE=Release . -B build-release-windows -D CMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc -D CMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DWINDOWS=ON -DSTATICC=ON -DTESTS=ON
|
||||||
- cmake --build build-release-windows --target all -- -j 4
|
- cmake --build build-release-windows --target all -- -j 4
|
||||||
- export WINEARCH=win64
|
- export WINEARCH=win64
|
||||||
- wine build-release-windows/ArbutilsTests.exe -s exclude:"Throw exception get stack trace"
|
- wine build-release-windows/ArbutilsTests.exe -s --duration=true --force-colour=true --test-case-exclude="Throw exception get stack trace"
|
||||||
- name: style-check
|
- name: style-check
|
||||||
image: deukhoofd/linux64builder
|
image: deukhoofd/linux64builder
|
||||||
failure: ignore
|
failure: ignore
|
||||||
|
|
|
@ -55,8 +55,8 @@ target_link_libraries(Arbutils ${LINKS})
|
||||||
if (TESTS)
|
if (TESTS)
|
||||||
# If we want a tests executable, grab all tests source files
|
# If we want a tests executable, grab all tests source files
|
||||||
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
|
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
|
||||||
# And create an executable from it. Also include catch.hpp.
|
# And create an executable from it. Also include doctest.hpp.
|
||||||
add_executable(ArbutilsTests ${TEST_FILES} extern/catch.hpp)
|
add_executable(ArbutilsTests ${TEST_FILES} extern/doctest.hpp)
|
||||||
# And finally link the library to the executable.
|
# And finally link the library to the executable.
|
||||||
target_link_libraries(ArbutilsTests Arbutils ${LINKS})
|
target_link_libraries(ArbutilsTests Arbutils ${LINKS})
|
||||||
# Add a compilation definition to the code that we are building a test build.
|
# Add a compilation definition to the code that we are building a test build.
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,13 +1,13 @@
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/doctest.hpp"
|
||||||
#include "../src/Assert.hpp"
|
#include "../src/Assert.hpp"
|
||||||
void TestWrapper(bool wrapperExpression) { Assert(wrapperExpression) }
|
void TestWrapper(bool wrapperExpression) { Assert(wrapperExpression) }
|
||||||
void TestWrapperNotNull(void* value) { AssertNotNull(value) }
|
void TestWrapperNotNull(void* value) { AssertNotNull(value) }
|
||||||
|
|
||||||
TEST_CASE("Assert succeeds if true", "[Utilities]") { REQUIRE_NOTHROW(TestWrapper(true)); }
|
TEST_CASE("Assert succeeds if true") { REQUIRE_NOTHROW(TestWrapper(true)); }
|
||||||
|
|
||||||
TEST_CASE("Assert throws if false", "[Utilities]") { REQUIRE_THROWS(TestWrapper(false)); }
|
TEST_CASE("Assert throws if false") { REQUIRE_THROWS(TestWrapper(false)); }
|
||||||
|
|
||||||
TEST_CASE("Assert throws if false with message", "[Utilities]") {
|
TEST_CASE("Assert throws if false with message") {
|
||||||
try {
|
try {
|
||||||
TestWrapper(false);
|
TestWrapper(false);
|
||||||
} catch (const ArbUt::Exception& e) {
|
} catch (const ArbUt::Exception& e) {
|
||||||
|
@ -17,15 +17,15 @@ TEST_CASE("Assert throws if false with message", "[Utilities]") {
|
||||||
throw ArbUt::Exception("Didn't throw.");
|
throw ArbUt::Exception("Didn't throw.");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Multiple asserts", "[Utilities]") {
|
TEST_CASE("Multiple asserts") {
|
||||||
Assert(true)
|
Assert(true)
|
||||||
Assert(true)
|
Assert(true)
|
||||||
Assert(true)
|
Assert(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }
|
TEST_CASE("AssertNotNull throws if nullptr") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }
|
||||||
|
|
||||||
TEST_CASE("Assert for each", "[Utilities]") {
|
TEST_CASE("Assert for each") {
|
||||||
auto i = {10, 500, 2300, 454};
|
auto i = {10, 500, 2300, 454};
|
||||||
AssertForEach(i, item > 0)
|
AssertForEach(i, item > 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/doctest.hpp"
|
||||||
#include "../src/Collections/Dictionary.hpp"
|
#include "../src/Collections/Dictionary.hpp"
|
||||||
using namespace ArbUt;
|
using namespace ArbUt;
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert values", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert values") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
dic.Insert(2, 100);
|
dic.Insert(2, 100);
|
||||||
dic.Insert(9, 2000);
|
dic.Insert(9, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary with initializer list", "[Utilities]") {
|
TEST_CASE("Create Dictionary with initializer list") {
|
||||||
auto dic = Dictionary<int, int>({{5, 100}, {10, 200}, {50, 2}});
|
auto dic = Dictionary<int, int>({{5, 100}, {10, 200}, {50, 2}});
|
||||||
|
|
||||||
CHECK(dic.Get(5) == 100);
|
CHECK(dic.Get(5) == 100);
|
||||||
|
@ -18,7 +18,7 @@ TEST_CASE("Create Dictionary with initializer list", "[Utilities]") {
|
||||||
CHECK(dic.Get(50) == 2);
|
CHECK(dic.Get(50) == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert values, get values", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert values, get values") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
dic.Insert(2, 100);
|
dic.Insert(2, 100);
|
||||||
|
@ -29,7 +29,7 @@ TEST_CASE("Create Dictionary, insert values, get values", "[Utilities]") {
|
||||||
CHECK(dic.Get(10) == 5);
|
CHECK(dic.Get(10) == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert values twice should throw", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert values twice should throw") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
CHECK_THROWS(dic.Insert(10, 100));
|
CHECK_THROWS(dic.Insert(10, 100));
|
||||||
|
@ -37,7 +37,7 @@ TEST_CASE("Create Dictionary, insert values twice should throw", "[Utilities]")
|
||||||
CHECK(dic.Get(10) == 5);
|
CHECK(dic.Get(10) == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert value, then update value", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert value, then update value") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
dic[10] = 200;
|
dic[10] = 200;
|
||||||
|
@ -45,7 +45,7 @@ TEST_CASE("Create Dictionary, insert value, then update value", "[Utilities]") {
|
||||||
CHECK(dic.Get(10) == 200);
|
CHECK(dic.Get(10) == 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert value, try get value", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert value, try get value") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -53,26 +53,26 @@ TEST_CASE("Create Dictionary, insert value, try get value", "[Utilities]") {
|
||||||
CHECK(result == 5);
|
CHECK(result == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert value, try get non existing value", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert value, try get non existing value") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
CHECK_FALSE(dic.TryGet(10, result));
|
CHECK_FALSE(dic.TryGet(10, result));
|
||||||
CHECK(result == 0);
|
CHECK(result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert value, Has", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert value, Has") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
CHECK(dic.Has(10));
|
CHECK(dic.Has(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, set value", "[Utilities]") {
|
TEST_CASE("Create Dictionary, set value") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Set(5, 100);
|
dic.Set(5, 100);
|
||||||
CHECK(dic.Has(5));
|
CHECK(dic.Has(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert values, get count", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert values, get count") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
dic.Insert(2, 100);
|
dic.Insert(2, 100);
|
||||||
|
@ -81,7 +81,7 @@ TEST_CASE("Create Dictionary, insert values, get count", "[Utilities]") {
|
||||||
CHECK(dic.Count() == 3);
|
CHECK(dic.Count() == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary, insert values, iterate over keys", "[Utilities]") {
|
TEST_CASE("Create Dictionary, insert values, iterate over keys") {
|
||||||
auto dic = Dictionary<int, int>(5);
|
auto dic = Dictionary<int, int>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
dic.Insert(2, 100);
|
dic.Insert(2, 100);
|
||||||
|
@ -95,7 +95,7 @@ TEST_CASE("Create Dictionary, insert values, iterate over keys", "[Utilities]")
|
||||||
CHECK(i == 3);
|
CHECK(i == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create Dictionary with different types, insert values, iterate over keys", "[Utilities]") {
|
TEST_CASE("Create Dictionary with different types, insert values, iterate over keys") {
|
||||||
auto dic = Dictionary<char, char>(5);
|
auto dic = Dictionary<char, char>(5);
|
||||||
dic.Insert(10, 5);
|
dic.Insert(10, 5);
|
||||||
dic.Insert(2, 100);
|
dic.Insert(2, 100);
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/doctest.hpp"
|
||||||
#include "../src/Enum.hpp"
|
#include "../src/Enum.hpp"
|
||||||
#include "../src/MacroUtils.hpp"
|
#include "../src/MacroUtils.hpp"
|
||||||
|
|
||||||
ENUM(TestEnum, uint8_t, Val1, Val2, Val3)
|
ENUM(TestEnum, uint8_t, Val1, Val2, Val3)
|
||||||
|
|
||||||
TEST_CASE("Parse Enum case sensitive", "[Utilities]") {
|
#define STATIC_REQUIRE(expr) \
|
||||||
|
static_assert(expr); \
|
||||||
|
REQUIRE(expr);
|
||||||
|
|
||||||
|
TEST_CASE("Parse Enum case sensitive") {
|
||||||
STATIC_REQUIRE(TestEnumHelper::Parse("Val1") == TestEnum::Val1);
|
STATIC_REQUIRE(TestEnumHelper::Parse("Val1") == TestEnum::Val1);
|
||||||
STATIC_REQUIRE(TestEnumHelper::Parse("Val2") == TestEnum::Val2);
|
STATIC_REQUIRE(TestEnumHelper::Parse("Val2") == TestEnum::Val2);
|
||||||
STATIC_REQUIRE(TestEnumHelper::Parse("Val3") == TestEnum::Val3);
|
STATIC_REQUIRE(TestEnumHelper::Parse("Val3") == TestEnum::Val3);
|
||||||
|
@ -15,7 +19,7 @@ TEST_CASE("Parse Enum case sensitive", "[Utilities]") {
|
||||||
CHECK_THROWS(TestEnumHelper::Parse("val1"));
|
CHECK_THROWS(TestEnumHelper::Parse("val1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Try Parse Enum case sensitive", "[Utilities]") {
|
TEST_CASE("Try Parse Enum case sensitive") {
|
||||||
TestEnum v = static_cast<TestEnum>(255);
|
TestEnum v = static_cast<TestEnum>(255);
|
||||||
REQUIRE(TestEnumHelper::TryParse("Val1", v));
|
REQUIRE(TestEnumHelper::TryParse("Val1", v));
|
||||||
CHECK(v == TestEnum::Val1);
|
CHECK(v == TestEnum::Val1);
|
||||||
|
@ -27,7 +31,7 @@ TEST_CASE("Try Parse Enum case sensitive", "[Utilities]") {
|
||||||
CHECK_FALSE(TestEnumHelper::TryParse("val1", v));
|
CHECK_FALSE(TestEnumHelper::TryParse("val1", v));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse Enum case insensitive", "[Utilities]") {
|
TEST_CASE("Parse Enum case insensitive") {
|
||||||
CHECK(TestEnumHelper::Parse("Val1", true) == TestEnum::Val1);
|
CHECK(TestEnumHelper::Parse("Val1", true) == TestEnum::Val1);
|
||||||
CHECK(TestEnumHelper::Parse("Val2", true) == TestEnum::Val2);
|
CHECK(TestEnumHelper::Parse("Val2", true) == TestEnum::Val2);
|
||||||
CHECK(TestEnumHelper::Parse("Val3", true) == TestEnum::Val3);
|
CHECK(TestEnumHelper::Parse("Val3", true) == TestEnum::Val3);
|
||||||
|
@ -37,7 +41,7 @@ TEST_CASE("Parse Enum case insensitive", "[Utilities]") {
|
||||||
CHECK_THROWS(TestEnumHelper::Parse("Val4", true));
|
CHECK_THROWS(TestEnumHelper::Parse("Val4", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Try Parse Enum case insensitive", "[Utilities]") {
|
TEST_CASE("Try Parse Enum case insensitive") {
|
||||||
TestEnum v = static_cast<TestEnum>(255);
|
TestEnum v = static_cast<TestEnum>(255);
|
||||||
REQUIRE(TestEnumHelper::TryParse("Val1", v, true));
|
REQUIRE(TestEnumHelper::TryParse("Val1", v, true));
|
||||||
CHECK(v == TestEnum::Val1);
|
CHECK(v == TestEnum::Val1);
|
||||||
|
@ -54,7 +58,7 @@ TEST_CASE("Try Parse Enum case insensitive", "[Utilities]") {
|
||||||
CHECK_FALSE(TestEnumHelper::TryParse("Val4", v, true));
|
CHECK_FALSE(TestEnumHelper::TryParse("Val4", v, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Enum To String", "[Utilities]") {
|
TEST_CASE("Enum To String") {
|
||||||
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val1) == "Val1");
|
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val1) == "Val1");
|
||||||
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val2) == "Val2");
|
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val2) == "Val2");
|
||||||
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val3) == "Val3");
|
STATIC_REQUIRE(TestEnumHelper::ToString(TestEnum::Val3) == "Val3");
|
||||||
|
@ -62,7 +66,7 @@ TEST_CASE("Enum To String", "[Utilities]") {
|
||||||
CHECK(TestEnumHelper::ToString((TestEnum)100) == "out of bounds");
|
CHECK(TestEnumHelper::ToString((TestEnum)100) == "out of bounds");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Enum Get Values", "[Utilities]") {
|
TEST_CASE("Enum Get Values") {
|
||||||
auto vec = TestEnumHelper::GetValues();
|
auto vec = TestEnumHelper::GetValues();
|
||||||
REQUIRE(vec.size() == 3);
|
REQUIRE(vec.size() == 3);
|
||||||
CHECK(vec[0] == TestEnum::Val1);
|
CHECK(vec[0] == TestEnum::Val1);
|
||||||
|
@ -70,12 +74,12 @@ TEST_CASE("Enum Get Values", "[Utilities]") {
|
||||||
CHECK(vec[2] == TestEnum::Val3);
|
CHECK(vec[2] == TestEnum::Val3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Enum Get Highest", "[Utilities]") { STATIC_REQUIRE(TestEnumHelper::Highest() == TestEnum::Val3); }
|
TEST_CASE("Enum Get Highest") { STATIC_REQUIRE(TestEnumHelper::Highest() == TestEnum::Val3); }
|
||||||
|
|
||||||
TEST_CASE("Enum Get Lowest", "[Utilities]") { STATIC_REQUIRE(TestEnumHelper::Lowest() == TestEnum::Val1); }
|
TEST_CASE("Enum Get Lowest") { STATIC_REQUIRE(TestEnumHelper::Lowest() == TestEnum::Val1); }
|
||||||
|
|
||||||
TEST_CASE("Enum Get First", "[Utilities]") { STATIC_REQUIRE(TestEnumHelper::First() == TestEnum::Val1); }
|
TEST_CASE("Enum Get First") { STATIC_REQUIRE(TestEnumHelper::First() == TestEnum::Val1); }
|
||||||
|
|
||||||
TEST_CASE("Enum Get Last", "[Utilities]") { STATIC_REQUIRE(TestEnumHelper::Last() == TestEnum::Val3); }
|
TEST_CASE("Enum Get Last") { STATIC_REQUIRE(TestEnumHelper::Last() == TestEnum::Val3); }
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/doctest.hpp"
|
||||||
#include "../src/Exception.hpp"
|
#include "../src/Exception.hpp"
|
||||||
using namespace ArbUt;
|
using namespace ArbUt;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/doctest.hpp"
|
||||||
#include "../src/Collections/List.hpp"
|
#include "../src/Collections/List.hpp"
|
||||||
using namespace ArbUt;
|
using namespace ArbUt;
|
||||||
|
|
||||||
TEST_CASE("Create List, insert values", "[Utilities]") {
|
TEST_CASE("Create List, insert values") {
|
||||||
auto ls = List<int>();
|
auto ls = List<int>();
|
||||||
ls.Append(5);
|
ls.Append(5);
|
||||||
ls.Append(100);
|
ls.Append(100);
|
||||||
|
@ -11,7 +11,7 @@ TEST_CASE("Create List, insert values", "[Utilities]") {
|
||||||
ls.Append(500);
|
ls.Append(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create List from initializer list", "[Utilities]") {
|
TEST_CASE("Create List from initializer list") {
|
||||||
auto ls = List<int>({5, 200, 1500, -500});
|
auto ls = List<int>({5, 200, 1500, -500});
|
||||||
CHECK(ls.At(0) == 5);
|
CHECK(ls.At(0) == 5);
|
||||||
CHECK(ls.At(1) == 200);
|
CHECK(ls.At(1) == 200);
|
||||||
|
@ -19,7 +19,7 @@ TEST_CASE("Create List from initializer list", "[Utilities]") {
|
||||||
CHECK(ls.At(3) == -500);
|
CHECK(ls.At(3) == -500);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create List, insert values, retrieve values", "[Utilities]") {
|
TEST_CASE("Create List, insert values, retrieve values") {
|
||||||
auto ls = List<int>();
|
auto ls = List<int>();
|
||||||
ls.Append(5);
|
ls.Append(5);
|
||||||
ls.Append(100);
|
ls.Append(100);
|
||||||
|
@ -32,7 +32,7 @@ TEST_CASE("Create List, insert values, retrieve values", "[Utilities]") {
|
||||||
CHECK(ls.At(3) == 500);
|
CHECK(ls.At(3) == 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create List, insert values, iterate over values", "[Utilities]") {
|
TEST_CASE("Create List, insert values, iterate over values") {
|
||||||
auto ls = List<int>();
|
auto ls = List<int>();
|
||||||
ls.Append(5);
|
ls.Append(5);
|
||||||
ls.Append(100);
|
ls.Append(100);
|
||||||
|
@ -44,7 +44,7 @@ TEST_CASE("Create List, insert values, iterate over values", "[Utilities]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create const List, iterate over values", "[Utilities]") {
|
TEST_CASE("Create const List, iterate over values") {
|
||||||
const auto& ls = List<int>({10, 100, 50});
|
const auto& ls = List<int>({10, 100, 50});
|
||||||
|
|
||||||
for (auto v : ls) {
|
for (auto v : ls) {
|
||||||
|
@ -52,14 +52,14 @@ TEST_CASE("Create const List, iterate over values", "[Utilities]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create list of bools, assign to it", "[Utilities]") {
|
TEST_CASE("Create list of bools, assign to it") {
|
||||||
auto ls = List<bool>({false, false, false});
|
auto ls = List<bool>({false, false, false});
|
||||||
|
|
||||||
ls[1] = true;
|
ls[1] = true;
|
||||||
CHECK(ls[1]);
|
CHECK(ls[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test IndexOf", "[Utilities]") {
|
TEST_CASE("Test IndexOf") {
|
||||||
auto ls = List<int>({5, 200, 1500, -500, 5, 300, -500});
|
auto ls = List<int>({5, 200, 1500, -500, 5, 300, -500});
|
||||||
CHECK(ls.IndexOf(5) == 0);
|
CHECK(ls.IndexOf(5) == 0);
|
||||||
CHECK(ls.IndexOf(1500) == 2);
|
CHECK(ls.IndexOf(1500) == 2);
|
||||||
|
@ -67,7 +67,7 @@ TEST_CASE("Test IndexOf", "[Utilities]") {
|
||||||
CHECK(ls.IndexOf(684) == -1);
|
CHECK(ls.IndexOf(684) == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test list out of bounds", "[Utilities]") {
|
TEST_CASE("Test list out of bounds") {
|
||||||
auto ls = List<int>({5, 200, 1500, -500, 5, 300, -500});
|
auto ls = List<int>({5, 200, 1500, -500, 5, 300, -500});
|
||||||
REQUIRE_THROWS(ls.At(-1));
|
REQUIRE_THROWS(ls.At(-1));
|
||||||
REQUIRE_THROWS(ls.At(7));
|
REQUIRE_THROWS(ls.At(7));
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#define CATCH_CONFIG_MAIN
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/doctest.hpp"
|
||||||
#include "../src/Random.hpp"
|
#include "../src/Random.hpp"
|
||||||
|
|
||||||
TEST_CASE("Random ints", "[Utilities]") {
|
TEST_CASE("Random ints") {
|
||||||
auto rand = ArbUt::Random(10);
|
auto rand = ArbUt::Random(10);
|
||||||
CHECK(rand.Get() == 1234817989);
|
CHECK(rand.Get() == 1234817989);
|
||||||
CHECK(rand.Get() == 1171957426);
|
CHECK(rand.Get() == 1171957426);
|
||||||
|
@ -18,7 +18,7 @@ TEST_CASE("Random ints", "[Utilities]") {
|
||||||
CHECK(rand.Get() == -1647742638);
|
CHECK(rand.Get() == -1647742638);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Random ints with limit", "[Utilities]") {
|
TEST_CASE("Random ints with limit") {
|
||||||
auto rand = ArbUt::Random(10);
|
auto rand = ArbUt::Random(10);
|
||||||
CHECK(rand.Get(10) == 2);
|
CHECK(rand.Get(10) == 2);
|
||||||
CHECK(rand.Get(10) == 2);
|
CHECK(rand.Get(10) == 2);
|
||||||
|
@ -42,7 +42,7 @@ TEST_CASE("Random ints with limit", "[Utilities]") {
|
||||||
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") {
|
||||||
auto rand = ArbUt::Random(10);
|
auto rand = ArbUt::Random(10);
|
||||||
CHECK(rand.Get(10, 30) == 15);
|
CHECK(rand.Get(10, 30) == 15);
|
||||||
CHECK(rand.Get(10, 30) == 15);
|
CHECK(rand.Get(10, 30) == 15);
|
||||||
|
@ -56,7 +56,7 @@ TEST_CASE("Random ints with upper and bottom", "[Utilities]") {
|
||||||
CHECK(rand.Get(10, 30) == 22);
|
CHECK(rand.Get(10, 30) == 22);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Random distribution (max 0, min 1)", "[Utilities]") {
|
TEST_CASE("Random distribution (max 0, min 1)") {
|
||||||
auto rand = ArbUt::Random(10);
|
auto rand = ArbUt::Random(10);
|
||||||
const int size = 100000;
|
const int size = 100000;
|
||||||
int arr[size];
|
int arr[size];
|
||||||
|
@ -69,7 +69,7 @@ TEST_CASE("Random distribution (max 0, min 1)", "[Utilities]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Random distribution (max 0, min 2)", "[Utilities]") {
|
TEST_CASE("Random distribution (max 0, min 2)") {
|
||||||
auto rand = ArbUt::Random(10);
|
auto rand = ArbUt::Random(10);
|
||||||
const int size = 100000;
|
const int size = 100000;
|
||||||
int arr[size];
|
int arr[size];
|
||||||
|
@ -88,10 +88,10 @@ TEST_CASE("Random distribution (max 0, min 2)", "[Utilities]") {
|
||||||
}
|
}
|
||||||
auto div = static_cast<float>(numZeros) / static_cast<float>(numOnes);
|
auto div = static_cast<float>(numZeros) / static_cast<float>(numOnes);
|
||||||
INFO("Distribution: " << numZeros << "/" << numOnes);
|
INFO("Distribution: " << numZeros << "/" << numOnes);
|
||||||
CHECK(Approx(div).margin(0.01) == 1);
|
CHECK(doctest::Approx(div).epsilon(0.01) == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Random distribution (max 0, min 3)", "[Utilities]") {
|
TEST_CASE("Random distribution (max 0, min 3)") {
|
||||||
auto rand = ArbUt::Random(10);
|
auto rand = ArbUt::Random(10);
|
||||||
const size_t size = 100000;
|
const size_t size = 100000;
|
||||||
int arr[size];
|
int arr[size];
|
||||||
|
@ -112,9 +112,9 @@ TEST_CASE("Random distribution (max 0, min 3)", "[Utilities]") {
|
||||||
numTwos++;
|
numTwos++;
|
||||||
}
|
}
|
||||||
INFO("Distribution: " << numZeros << "/" << numOnes << "/" << numTwos);
|
INFO("Distribution: " << numZeros << "/" << numOnes << "/" << numTwos);
|
||||||
CHECK(Approx(static_cast<float>(numZeros) / static_cast<float>(numOnes)).margin(0.01) == 1);
|
CHECK(doctest::Approx(static_cast<float>(numZeros) / static_cast<float>(numOnes)).epsilon(0.01) == 1);
|
||||||
CHECK(Approx(static_cast<float>(numZeros) / static_cast<float>(numTwos)).margin(0.01) == 1);
|
CHECK(doctest::Approx(static_cast<float>(numZeros) / static_cast<float>(numTwos)).epsilon(0.01) == 1);
|
||||||
CHECK(Approx(static_cast<float>(numOnes) / static_cast<float>(numTwos)).margin(0.01) == 1);
|
CHECK(doctest::Approx(static_cast<float>(numOnes) / static_cast<float>(numTwos)).epsilon(0.01) == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -4,23 +4,23 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/doctest.hpp"
|
||||||
#include "../src/String/BasicStringView.hpp"
|
#include "../src/String/BasicStringView.hpp"
|
||||||
#include "../src/String/StringView.hpp"
|
#include "../src/String/StringView.hpp"
|
||||||
#include "../src/String/StringViewLiteral.hpp"
|
#include "../src/String/StringViewLiteral.hpp"
|
||||||
|
|
||||||
TEST_CASE("Initialize compile time", "[Utilities]") {
|
TEST_CASE("Initialize compile time") {
|
||||||
static_assert("foo"_cnc.Length() == 3);
|
static_assert("foo"_cnc.Length() == 3);
|
||||||
static_assert("bar"_cnc.Length() == 3);
|
static_assert("bar"_cnc.Length() == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Compare compile time", "[Utilities]") { static_assert("foo"_cnc != "bar"_cnc); }
|
TEST_CASE("Compare compile time") { static_assert("foo"_cnc != "bar"_cnc); }
|
||||||
|
|
||||||
TEST_CASE("Compare compile time with CaseInsensitiveStringview", "[Utilities]") {
|
TEST_CASE("Compare compile time with CaseInsensitiveStringview") {
|
||||||
static_assert("foo"_cnc == ArbUt::StringViewLiteral("foo"));
|
static_assert("foo"_cnc == ArbUt::StringViewLiteral("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Use insensitive const string in unordered_map", "[Utilities]") {
|
TEST_CASE("Use insensitive const string in unordered_map") {
|
||||||
std::unordered_map<ArbUt::StringView, int32_t> map;
|
std::unordered_map<ArbUt::StringView, int32_t> map;
|
||||||
map.insert({"foO"_cnc, 1});
|
map.insert({"foO"_cnc, 1});
|
||||||
map.insert({"bAR"_cnc, 5});
|
map.insert({"bAR"_cnc, 5});
|
||||||
|
@ -29,24 +29,24 @@ TEST_CASE("Use insensitive const string in unordered_map", "[Utilities]") {
|
||||||
CHECK(map["foo"_cnc] == 1);
|
CHECK(map["foo"_cnc] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Use case insensitive const string in switch case", "[Utilities]") {
|
TEST_CASE("Use case insensitive const string in switch case") {
|
||||||
auto val = ArbUt::StringView("foobar");
|
auto val = ArbUt::StringView("foobar");
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case "foo"_cnc: FAIL(); break;
|
case "foo"_cnc: FAIL("Wrong case"); break;
|
||||||
case "bar"_cnc: FAIL(); break;
|
case "bar"_cnc: FAIL("Wrong case"); break;
|
||||||
case "FOObAr"_cnc: SUCCEED(); break;
|
case "FOObAr"_cnc: break;
|
||||||
default: FAIL(); break;
|
default: FAIL("Wrong case"); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Literal stringview to non literal, then use", "[Utilities]") {
|
TEST_CASE("Literal stringview to non literal, then use") {
|
||||||
ArbUt::StringView val;
|
ArbUt::StringView val;
|
||||||
{ val = "foobar"_cnc; }
|
{ val = "foobar"_cnc; }
|
||||||
INFO(val.c_str());
|
INFO(val.c_str());
|
||||||
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Pipe stringview into stream", "[Utilities]") {
|
TEST_CASE("Pipe stringview into stream") {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ArbUt::StringView val = "foo";
|
ArbUt::StringView val = "foo";
|
||||||
ss << val;
|
ss << val;
|
||||||
|
@ -74,12 +74,12 @@ TestCreateStringview() {
|
||||||
return ArbUt::StringView(originalVal);
|
return ArbUt::StringView(originalVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Out of scope char* doesn't lose reference", "[Utilities]") {
|
TEST_CASE("Out of scope char* doesn't lose reference") {
|
||||||
ArbUt::StringView val = TestCreateStringview();
|
ArbUt::StringView val = TestCreateStringview();
|
||||||
INFO(val.c_str());
|
INFO(val.c_str());
|
||||||
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Get Empty String", "[Utilities]") { REQUIRE(ArbUt::StringView::EmptyString() == ""_cnc); }
|
TEST_CASE("Get Empty String") { REQUIRE(ArbUt::StringView::EmptyString() == ""_cnc); }
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/doctest.hpp"
|
||||||
#include "../src/Memory/UniquePtrList.hpp"
|
#include "../src/Memory/UniquePtrList.hpp"
|
||||||
using namespace ArbUt;
|
using namespace ArbUt;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ TEST_CASE("Create Unique Ptr list, append, iterate") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test unique ptr list out of bounds", "[Utilities]") {
|
TEST_CASE("Test unique ptr list out of bounds") {
|
||||||
auto ls = UniquePtrList<uint32_t>();
|
auto ls = UniquePtrList<uint32_t>();
|
||||||
auto v1 = new uint32_t(100);
|
auto v1 = new uint32_t(100);
|
||||||
auto v2 = new uint32_t(5000);
|
auto v2 = new uint32_t(5000);
|
||||||
|
|
Loading…
Reference in New Issue