Arbutils/tests/UniquePtrListTests.cpp

53 lines
1.2 KiB
C++

#ifdef TESTS_BUILD
#include <doctest.h>
#include "../src/Memory/__UniquePtrList.hpp"
using namespace ArbUt;
TEST_CASE("Create Unique Ptr list, append") {
auto ls = UniquePtrList<u32>();
auto v1 = new u32(100);
auto v2 = new u32(5000);
ls.Append(v1);
ls.Append(v2);
}
TEST_CASE("Create Unique Ptr list, append, retrieve") {
auto ls = UniquePtrList<u32>();
auto v1 = new u32(100);
auto v2 = new u32(5000);
ls.Append(v1);
ls.Append(v2);
REQUIRE(ls.Count() == 2);
CHECK(ls.At(0) == v1);
CHECK(ls.At(1) == v2);
CHECK(ls[0] == v1);
CHECK(ls[1] == v2);
}
TEST_CASE("Create Unique Ptr list, append, iterate") {
auto ls = UniquePtrList<u32>();
auto v1 = new u32(100);
auto v2 = new u32(5000);
ls.Append(v1);
ls.Append(v2);
REQUIRE(ls.Count() == 2);
auto i = 0;
for (const auto& v : ls) {
if (i == 0)
CHECK(v == v1);
else if (i == 1)
CHECK(v == v2);
i++;
}
}
TEST_CASE("Test unique ptr list out of bounds") {
auto ls = UniquePtrList<u32>();
auto v1 = new u32(100);
auto v2 = new u32(5000);
ls.Append(v1);
ls.Append(v2);
REQUIRE_THROWS(ls.At(2));
}
#endif