75 lines
1.6 KiB
C++
75 lines
1.6 KiB
C++
#ifdef TESTS_BUILD
|
|
#include <doctest.h>
|
|
#include "../src/Collections/List.hpp"
|
|
using namespace ArbUt;
|
|
|
|
TEST_CASE("Create List, insert values") {
|
|
auto ls = List<int>();
|
|
ls.Append(5);
|
|
ls.Append(100);
|
|
ls.Append(200);
|
|
ls.Append(500);
|
|
}
|
|
|
|
TEST_CASE("Create List from initializer list") {
|
|
auto ls = List<int>({5, 200, 1500, -500});
|
|
CHECK(ls.At(0) == 5);
|
|
CHECK(ls.At(1) == 200);
|
|
CHECK(ls.At(2) == 1500);
|
|
CHECK(ls.At(3) == -500);
|
|
}
|
|
|
|
TEST_CASE("Create List, insert values, retrieve values") {
|
|
auto ls = List<int>();
|
|
ls.Append(5);
|
|
ls.Append(100);
|
|
ls.Append(200);
|
|
ls.Append(500);
|
|
|
|
CHECK(ls.At(0) == 5);
|
|
CHECK(ls.At(1) == 100);
|
|
CHECK(ls.At(2) == 200);
|
|
CHECK(ls.At(3) == 500);
|
|
}
|
|
|
|
TEST_CASE("Create List, insert values, iterate over values") {
|
|
auto ls = List<int>();
|
|
ls.Append(5);
|
|
ls.Append(100);
|
|
ls.Append(200);
|
|
ls.Append(500);
|
|
|
|
for (auto v : ls) {
|
|
CHECK(ls.Contains(v));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Create const List, iterate over values") {
|
|
const auto& ls = List<int>({10, 100, 50});
|
|
|
|
for (auto v : ls) {
|
|
CHECK(ls.Contains(v));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Create list of bools, assign to it") {
|
|
auto ls = List<bool>({false, false, false});
|
|
|
|
ls[1] = true;
|
|
CHECK(ls[1]);
|
|
}
|
|
|
|
TEST_CASE("Test IndexOf") {
|
|
auto ls = List<int>({5, 200, 1500, -500, 5, 300, -500});
|
|
CHECK(ls.IndexOf(5) == 0);
|
|
CHECK(ls.IndexOf(1500) == 2);
|
|
CHECK(ls.IndexOf(300) == 5);
|
|
CHECK_FALSE(ls.IndexOf(684).has_value());
|
|
}
|
|
|
|
TEST_CASE("Test list out of bounds") {
|
|
auto ls = List<int>({5, 200, 1500, -500, 5, 300, -500});
|
|
REQUIRE_THROWS(ls.At(7));
|
|
}
|
|
|
|
#endif |