aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/tests/src/vector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/tests/src/vector.cpp')
-rw-r--r--libs/kstd/tests/src/vector.cpp44
1 files changed, 41 insertions, 3 deletions
diff --git a/libs/kstd/tests/src/vector.cpp b/libs/kstd/tests/src/vector.cpp
index 02b8786..913427c 100644
--- a/libs/kstd/tests/src/vector.cpp
+++ b/libs/kstd/tests/src/vector.cpp
@@ -475,6 +475,20 @@ SCENARIO("Vector modifiers", "[vector]")
REQUIRE(it == v.begin());
}
}
+
+ WHEN("inserting an lvalue element")
+ {
+ auto const value = 42;
+ auto it = v.insert(v.cbegin(), value);
+
+ THEN("the size and capacity increase and the element is inserted")
+ {
+ REQUIRE(v.size() == 1);
+ REQUIRE(v.capacity() >= 1);
+ REQUIRE(v[0] == 42);
+ REQUIRE(it == v.begin());
+ }
+ }
}
GIVEN("A populated vector")
@@ -597,6 +611,22 @@ SCENARIO("Vector modifiers", "[vector]")
}
}
+ WHEN("inserting an lvalue at the end")
+ {
+ auto const value = 40;
+ auto it = v.insert(v.cend(), value);
+
+ THEN("the element is inserted at the back")
+ {
+ REQUIRE(v.size() == 4);
+ REQUIRE(v[0] == 10);
+ REQUIRE(v[1] == 20);
+ REQUIRE(v[2] == 30);
+ REQUIRE(v[3] == 40);
+ REQUIRE(it == v.begin() + 3);
+ }
+ }
+
WHEN("inserting when capacity is sufficient")
{
v.reserve(10);
@@ -722,6 +752,14 @@ SCENARIO("Vector modifiers", "[vector]")
REQUIRE(it == v.end());
}
}
+
+ WHEN("erasing the end() iterator")
+ {
+ THEN("a panic is triggered")
+ {
+ REQUIRE_THROWS_AS(v.erase(v.end()), kstd::tests::os_panic);
+ }
+ }
}
}
@@ -944,7 +982,7 @@ SCENARIO("Vector modifier move semantics", "[vector]")
WHEN("erasing an element in the middle")
{
- for (auto& elem : v)
+ for (auto & elem : v)
{
elem.was_copied = false;
elem.was_moved = false;
@@ -955,7 +993,7 @@ SCENARIO("Vector modifier move semantics", "[vector]")
THEN("the subsequent elements are move-assigned leftwards")
{
REQUIRE(v.size() == 2);
-
+
REQUIRE(v[0].value == 10);
REQUIRE_FALSE(v[0].was_moved);
REQUIRE_FALSE(v[0].was_copied);
@@ -970,7 +1008,7 @@ SCENARIO("Vector modifier move semantics", "[vector]")
WHEN("erasing the last element")
{
- for (auto& elem : v)
+ for (auto & elem : v)
{
elem.was_copied = false;
elem.was_moved = false;