diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-14 13:23:52 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-14 13:23:52 +0200 |
| commit | 2f4591dbb173d602368437e1dd8c788b0bedd4aa (patch) | |
| tree | 2c7a4994e4be60577f144dfc0494175d3dc69c27 /libs/kstd/tests/src | |
| parent | 6253705095086de8c6585acc9400942e6a267a5d (diff) | |
| download | teachos-2f4591dbb173d602368437e1dd8c788b0bedd4aa.tar.xz teachos-2f4591dbb173d602368437e1dd8c788b0bedd4aa.zip | |
kstd: add basic flat_map::try_insert
Diffstat (limited to 'libs/kstd/tests/src')
| -rw-r--r-- | libs/kstd/tests/src/vector.cpp | 45 |
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(); |
