aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd')
-rw-r--r--libs/kstd/tests/src/vector.cpp68
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);
+ }
+ }
}
}