2020-03-22 16:09:25 +00:00
|
|
|
#ifdef TESTS_BUILD
|
2022-02-05 12:37:47 +00:00
|
|
|
#include <doctest.h>
|
2020-03-22 16:09:25 +00:00
|
|
|
#include "../src/Collections/List.hpp"
|
2020-05-26 15:36:39 +00:00
|
|
|
using namespace ArbUt;
|
2020-03-22 16:09:25 +00:00
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Create List, insert values") {
|
2020-03-22 16:09:25 +00:00
|
|
|
auto ls = List<int>();
|
|
|
|
ls.Append(5);
|
|
|
|
ls.Append(100);
|
|
|
|
ls.Append(200);
|
|
|
|
ls.Append(500);
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Create List from initializer list") {
|
2020-03-22 16:09:25 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Create List, insert values, retrieve values") {
|
2020-03-22 16:09:25 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Create List, insert values, iterate over values") {
|
2020-03-22 16:09:25 +00:00
|
|
|
auto ls = List<int>();
|
|
|
|
ls.Append(5);
|
|
|
|
ls.Append(100);
|
|
|
|
ls.Append(200);
|
|
|
|
ls.Append(500);
|
|
|
|
|
2020-04-28 14:55:00 +00:00
|
|
|
for (auto v : ls) {
|
2020-03-22 16:09:25 +00:00
|
|
|
CHECK(ls.Contains(v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Create const List, iterate over values") {
|
2020-03-22 17:15:13 +00:00
|
|
|
const auto& ls = List<int>({10, 100, 50});
|
|
|
|
|
2020-04-28 14:55:00 +00:00
|
|
|
for (auto v : ls) {
|
2020-03-22 17:15:13 +00:00
|
|
|
CHECK(ls.Contains(v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Create list of bools, assign to it") {
|
2020-03-22 17:44:50 +00:00
|
|
|
auto ls = List<bool>({false, false, false});
|
|
|
|
|
|
|
|
ls[1] = true;
|
|
|
|
CHECK(ls[1]);
|
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Test IndexOf") {
|
2020-03-24 21:56:40 +00:00
|
|
|
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);
|
2022-03-23 09:53:02 +00:00
|
|
|
CHECK_FALSE(ls.IndexOf(684).has_value());
|
2020-03-24 21:56:40 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Test list out of bounds") {
|
2020-06-26 13:56:00 +00:00
|
|
|
auto ls = List<int>({5, 200, 1500, -500, 5, 300, -500});
|
|
|
|
REQUIRE_THROWS(ls.At(7));
|
|
|
|
}
|
|
|
|
|
2020-03-22 16:09:25 +00:00
|
|
|
#endif
|