Arbutils/tests/UniquePtrListTests.cpp

53 lines
1.2 KiB
C++
Raw Normal View History

#ifdef TESTS_BUILD
2022-02-05 12:37:47 +00:00
#include <doctest.h>
#include "../src/Memory/__UniquePtrList.hpp"
using namespace ArbUt;
2020-05-31 14:40:33 +00:00
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);
}
2020-05-31 14:40:33 +00:00
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);
}
2020-05-31 14:40:33 +00:00
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;
2020-05-31 14:40:33 +00:00
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