2020-05-31 14:37:49 +00:00
|
|
|
#ifdef TESTS_BUILD
|
2022-02-05 12:37:47 +00:00
|
|
|
#include <doctest.h>
|
2020-12-11 14:29:27 +00:00
|
|
|
#include "../src/Memory/__UniquePtrList.hpp"
|
2020-05-31 14:37:49 +00:00
|
|
|
using namespace ArbUt;
|
|
|
|
|
2020-05-31 14:40:33 +00:00
|
|
|
TEST_CASE("Create Unique Ptr list, append") {
|
2020-05-31 14:37:49 +00:00
|
|
|
auto ls = UniquePtrList<uint32_t>();
|
2020-05-31 14:40:33 +00:00
|
|
|
auto v1 = new uint32_t(100);
|
|
|
|
auto v2 = new uint32_t(5000);
|
2020-05-31 14:37:49 +00:00
|
|
|
ls.Append(v1);
|
|
|
|
ls.Append(v2);
|
|
|
|
}
|
|
|
|
|
2020-05-31 14:40:33 +00:00
|
|
|
TEST_CASE("Create Unique Ptr list, append, retrieve") {
|
2020-05-31 14:37:49 +00:00
|
|
|
auto ls = UniquePtrList<uint32_t>();
|
2020-05-31 14:40:33 +00:00
|
|
|
auto v1 = new uint32_t(100);
|
|
|
|
auto v2 = new uint32_t(5000);
|
2020-05-31 14:37:49 +00:00
|
|
|
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") {
|
2020-05-31 14:37:49 +00:00
|
|
|
auto ls = UniquePtrList<uint32_t>();
|
2020-05-31 14:40:33 +00:00
|
|
|
auto v1 = new uint32_t(100);
|
|
|
|
auto v2 = new uint32_t(5000);
|
2020-05-31 14:37:49 +00:00
|
|
|
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);
|
2020-05-31 14:37:49 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Test unique ptr list out of bounds") {
|
2020-06-26 13:56:00 +00:00
|
|
|
auto ls = UniquePtrList<uint32_t>();
|
|
|
|
auto v1 = new uint32_t(100);
|
|
|
|
auto v2 = new uint32_t(5000);
|
|
|
|
ls.Append(v1);
|
|
|
|
ls.Append(v2);
|
|
|
|
REQUIRE_THROWS(ls.At(2));
|
|
|
|
}
|
|
|
|
|
2020-05-31 14:37:49 +00:00
|
|
|
#endif
|