aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/tests')
-rw-r--r--libs/kstd/tests/src/vector.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/libs/kstd/tests/src/vector.cpp b/libs/kstd/tests/src/vector.cpp
index 81bf32f..5faaaff 100644
--- a/libs/kstd/tests/src/vector.cpp
+++ b/libs/kstd/tests/src/vector.cpp
@@ -463,6 +463,33 @@ SCENARIO("Vector modifiers", "[vector]")
}
}
+ WHEN("emplace is called with the end iterator and constructor arguments")
+ {
+ v.emplace(v.end(), 20);
+
+ THEN("the element is appended and the size and capacity increase")
+ {
+ REQUIRE(v.size() == 1);
+ REQUIRE(v.capacity() >= 1);
+ REQUIRE(v.back() == 20);
+ }
+ }
+
+ WHEN("emplace is called while capacity is sufficient")
+ {
+ v.reserve(10);
+ auto const capacity = v.capacity();
+
+ v.emplace(v.end(), 20);
+
+ THEN("the element is appended without reallocation")
+ {
+ REQUIRE(v.size() == 1);
+ REQUIRE(v.capacity() == capacity);
+ REQUIRE(v.back() == 20);
+ }
+ }
+
WHEN("inserting an element")
{
auto it = v.insert(v.cbegin(), 42);
@@ -526,6 +553,24 @@ SCENARIO("Vector modifiers", "[vector]")
}
}
+ WHEN("emplace is called with an iterator and constructor arguments")
+ {
+ auto it = v.emplace(v.begin() + 2, 25);
+
+ THEN("the element is inserted and the size and capacity increase")
+ {
+ REQUIRE(v.size() == 4);
+ REQUIRE(v.capacity() >= initial_capacity);
+ REQUIRE(v.at(2) == 25);
+ }
+
+ THEN("the returned iterator points to the inserted element")
+ {
+ REQUIRE(it == v.cbegin() + 2);
+ REQUIRE(*it == 25);
+ }
+ }
+
WHEN("push_back is called with a reference to an internal element")
{
v.shrink_to_fit();