aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/tests/src')
-rw-r--r--libs/kstd/tests/src/vector.cpp77
1 files changed, 73 insertions, 4 deletions
diff --git a/libs/kstd/tests/src/vector.cpp b/libs/kstd/tests/src/vector.cpp
index edf47d7..a02ebf0 100644
--- a/libs/kstd/tests/src/vector.cpp
+++ b/libs/kstd/tests/src/vector.cpp
@@ -522,16 +522,77 @@ SCENARIO("Vector modifiers", "[vector]")
auto const range = std::views::iota(0, 3);
v.append_range(range);
- THEN("the size and capacity increase and the elements are appended")
+ THEN("the size increases")
{
REQUIRE(v.size() == 3);
+ }
+
+ THEN("the capacity increases")
+ {
REQUIRE(v.capacity() >= 3);
+ }
+
+ THEN("the elements are appended")
+ {
REQUIRE(v[0] == 0);
REQUIRE(v[1] == 1);
REQUIRE(v[2] == 2);
}
}
+ WHEN("appending from an input range")
+ {
+ auto const arr = std::array<int, 3>{1, 2, 3};
+ auto const first = kstd::tests::test_input_iterator{arr.data(), arr.size()};
+ auto const last = kstd::tests::test_input_iterator{};
+
+ v.append_range(std::ranges::subrange{first, last});
+
+ THEN("the size increases")
+ {
+ REQUIRE(v.size() == 3);
+ }
+
+ THEN("the capacity increases")
+ {
+ REQUIRE(v.capacity() >= 3);
+ }
+
+ THEN("the elements are appended")
+ {
+ REQUIRE(v[0] == 1);
+ REQUIRE(v[1] == 2);
+ REQUIRE(v[2] == 3);
+ }
+ }
+
+ WHEN("appending from an input range with sufficient capacity")
+ {
+ v.reserve(3);
+ auto const arr = std::array<int, 3>{1, 2, 3};
+ auto const first = kstd::tests::test_input_iterator{arr.data(), arr.size()};
+ auto const last = kstd::tests::test_input_iterator{};
+
+ v.append_range(std::ranges::subrange{first, last});
+
+ THEN("the size increases")
+ {
+ REQUIRE(v.size() == 3);
+ }
+
+ THEN("the capacity stays the same")
+ {
+ REQUIRE(v.capacity() == 3);
+ }
+
+ THEN("the elements are appended")
+ {
+ REQUIRE(v[0] == 1);
+ REQUIRE(v[1] == 2);
+ REQUIRE(v[2] == 3);
+ }
+ }
+
WHEN("resizing the vector to a greater size")
{
v.resize(3);
@@ -881,10 +942,18 @@ SCENARIO("Vector modifiers", "[vector]")
auto initial_size = v.size();
v.append_range(std::views::iota(0, 3));
- THEN("capacity and size are increased and the elements are appended")
+ THEN("capacity is increased")
{
REQUIRE(v.capacity() >= initial_capacity);
+ }
+
+ THEN("size is increased")
+ {
REQUIRE(v.size() == initial_size + 3);
+ }
+
+ THEN("the elements are appended")
+ {
REQUIRE(v[initial_size + 0] == 0);
REQUIRE(v[initial_size + 1] == 1);
REQUIRE(v[initial_size + 2] == 2);
@@ -1290,8 +1359,8 @@ SCENARIO("Vector advanced construction", "[vector]")
WHEN("constructing from input iterators")
{
auto const arr = std::array<int, 3>{1, 2, 3};
- auto const first = kstd::tests::test_input_iterator{arr.data()};
- auto const last = kstd::tests::test_input_iterator{arr.data() + arr.size()};
+ auto const first = kstd::tests::test_input_iterator{arr.data(), arr.size()};
+ auto const last = kstd::tests::test_input_iterator{};
auto v = kstd::vector<int>(first, last);