From 2f4591dbb173d602368437e1dd8c788b0bedd4aa Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 14 Apr 2026 13:23:52 +0200 Subject: kstd: add basic flat_map::try_insert --- libs/kstd/tests/src/vector.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'libs/kstd/tests/src') 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(); -- cgit v1.2.3