diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-03-26 18:09:15 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-03-27 07:02:35 +0100 |
| commit | f6100699cd93606147ebe94a777b6e4aff7c5f50 (patch) | |
| tree | 128faa6e8e9f065d47aa4910fe4f58a6a76cfb4b | |
| parent | 4b094e2bd5a8e60ec1018d6aa90aa9da4adf49c9 (diff) | |
| download | teachos-f6100699cd93606147ebe94a777b6e4aff7c5f50.tar.xz teachos-f6100699cd93606147ebe94a777b6e4aff7c5f50.zip | |
kstd/vector: add missing tests for insert
| -rw-r--r-- | libs/kstd/tests/src/vector.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libs/kstd/tests/src/vector.cpp b/libs/kstd/tests/src/vector.cpp index 3ff041f..02b8786 100644 --- a/libs/kstd/tests/src/vector.cpp +++ b/libs/kstd/tests/src/vector.cpp @@ -650,6 +650,40 @@ SCENARIO("Vector modifiers", "[vector]") } } + WHEN("inserting an rvalue reference to an existing element with reallocation") + { + v.shrink_to_fit(); + REQUIRE(v.capacity() == v.size()); + auto it = v.insert(v.cbegin() + 1, std::move(v[2])); + + THEN("the element is correctly moved and inserted") + { + REQUIRE(v.size() == 4); + REQUIRE(v[0] == 10); + REQUIRE(v[1] == 30); + REQUIRE(v[2] == 20); + REQUIRE(v[3] == 30); + REQUIRE(it == v.begin() + 1); + } + } + + WHEN("inserting an rvalue reference to an existing element without reallocation") + { + v.reserve(10); + REQUIRE(v.capacity() > v.size()); + auto it = v.insert(v.cbegin() + 1, std::move(v[2])); + + THEN("the element is correctly moved and inserted") + { + REQUIRE(v.size() == 4); + REQUIRE(v[0] == 10); + REQUIRE(v[1] == 30); + REQUIRE(v[2] == 20); + REQUIRE(v[3] == 30); + REQUIRE(it == v.begin() + 1); + } + } + WHEN("erasing the first element") { auto it = v.erase(v.cbegin()); |
