diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-05-01 11:35:10 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-05-01 11:35:10 +0200 |
| commit | 52b2fd214c8484a55c409c72c90929428e261949 (patch) | |
| tree | 4366d3d177e2224068d7358418e094b7e96200d6 | |
| parent | a958c515e4cfcd5572ac7e2c3a567e832630a12d (diff) | |
| download | kernel-52b2fd214c8484a55c409c72c90929428e261949.tar.xz kernel-52b2fd214c8484a55c409c72c90929428e261949.zip | |
kstd: vector add resize tests
| -rw-r--r-- | libs/kstd/tests/src/vector.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libs/kstd/tests/src/vector.cpp b/libs/kstd/tests/src/vector.cpp index bbbd3d1..edf47d7 100644 --- a/libs/kstd/tests/src/vector.cpp +++ b/libs/kstd/tests/src/vector.cpp @@ -531,6 +531,34 @@ SCENARIO("Vector modifiers", "[vector]") REQUIRE(v[2] == 2); } } + + WHEN("resizing the vector to a greater size") + { + v.resize(3); + + THEN("the size and capacity increase and the elements are value initialized") + { + REQUIRE(v.size() == 3); + REQUIRE(v.capacity() >= 3); + REQUIRE(v[0] == 0); + REQUIRE(v[1] == 0); + REQUIRE(v[2] == 0); + } + } + + WHEN("resizing the vector to a greater size with initial value") + { + v.resize(3, 2); + + THEN("the size and capacity increase and the elements are initialized to the given value") + { + REQUIRE(v.size() == 3); + REQUIRE(v.capacity() >= 3); + REQUIRE(v[0] == 2); + REQUIRE(v[1] == 2); + REQUIRE(v[2] == 2); + } + } } GIVEN("A populated vector") @@ -863,6 +891,46 @@ SCENARIO("Vector modifiers", "[vector]") } } + WHEN("resizing the vector to a greater size") + { + auto initial_size = v.size(); + v.resize(initial_size + 3); + + THEN("the size and capacity increase and the elements are value initialized") + { + REQUIRE(v.size() == initial_size + 3); + REQUIRE(v.capacity() >= initial_size + 3); + REQUIRE(v[initial_size + 0] == 0); + REQUIRE(v[initial_size + 1] == 0); + REQUIRE(v[initial_size + 2] == 0); + } + } + + WHEN("resizing the vector to a greater size with initial value") + { + auto initial_size = v.size(); + v.resize(initial_size + 3, 2); + + THEN("the size and capacity increase and the elements are initialized to the given value") + { + REQUIRE(v.size() == initial_size + 3); + REQUIRE(v.capacity() >= initial_size + 3); + REQUIRE(v[initial_size + 0] == 2); + REQUIRE(v[initial_size + 1] == 2); + REQUIRE(v[initial_size + 2] == 2); + } + } + + WHEN("resizing the vector to a smaller size") + { + v.resize(1); + + THEN("the size decreases and the elements are destroyed") + { + REQUIRE(v.size() == 1); + REQUIRE(v[0] == 10); + } + } } } |
