aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-03-26 18:19:52 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-03-27 07:02:35 +0100
commit096d7505cfc2d60e58a6dd4d80fd7f3638c9bb94 (patch)
tree9af50bb4c8f0ed134fa6ab47c347140fcfa0ef8a
parentf6100699cd93606147ebe94a777b6e4aff7c5f50 (diff)
downloadteachos-096d7505cfc2d60e58a6dd4d80fd7f3638c9bb94.tar.xz
teachos-096d7505cfc2d60e58a6dd4d80fd7f3638c9bb94.zip
kstd/vector: increase test coverage
-rw-r--r--.lcovrc2
-rw-r--r--libs/kstd/include/kstd/vector7
-rw-r--r--libs/kstd/tests/src/vector.cpp44
3 files changed, 48 insertions, 5 deletions
diff --git a/.lcovrc b/.lcovrc
index d19e80d..07da866 100644
--- a/.lcovrc
+++ b/.lcovrc
@@ -1,5 +1,5 @@
exclude = /usr/include/*
-exclude = build/_deps/*
+exclude = build/bht/_deps/*
exclude = tests/*
ignore_errors = unused,empty,inconsistent \ No newline at end of file
diff --git a/libs/kstd/include/kstd/vector b/libs/kstd/include/kstd/vector
index 74aefa9..771fc87 100644
--- a/libs/kstd/include/kstd/vector
+++ b/libs/kstd/include/kstd/vector
@@ -548,7 +548,6 @@ namespace kstd
if (new_capacity > max_size())
{
kstd::os::panic("[kstd:vector] Tried to reserve more space than theoretically possible.");
- return;
}
auto new_data = allocate_n(new_capacity);
@@ -690,6 +689,12 @@ namespace kstd
return begin() + prefix_size;
}
+ //! Erase an element at a given position.
+ //!
+ //! @note This function will panic if position == end()
+ //!
+ //! @param position An interator pointing to the element to delete
+ //! @return An iterator pointing to the element after the deleted element
constexpr auto erase(const_iterator position) -> iterator
{
if (position == end())
diff --git a/libs/kstd/tests/src/vector.cpp b/libs/kstd/tests/src/vector.cpp
index 02b8786..913427c 100644
--- a/libs/kstd/tests/src/vector.cpp
+++ b/libs/kstd/tests/src/vector.cpp
@@ -475,6 +475,20 @@ SCENARIO("Vector modifiers", "[vector]")
REQUIRE(it == v.begin());
}
}
+
+ WHEN("inserting an lvalue element")
+ {
+ auto const value = 42;
+ auto it = v.insert(v.cbegin(), value);
+
+ THEN("the size and capacity increase and the element is inserted")
+ {
+ REQUIRE(v.size() == 1);
+ REQUIRE(v.capacity() >= 1);
+ REQUIRE(v[0] == 42);
+ REQUIRE(it == v.begin());
+ }
+ }
}
GIVEN("A populated vector")
@@ -597,6 +611,22 @@ SCENARIO("Vector modifiers", "[vector]")
}
}
+ WHEN("inserting an lvalue at the end")
+ {
+ auto const value = 40;
+ auto it = v.insert(v.cend(), value);
+
+ THEN("the element is inserted at the back")
+ {
+ REQUIRE(v.size() == 4);
+ REQUIRE(v[0] == 10);
+ REQUIRE(v[1] == 20);
+ REQUIRE(v[2] == 30);
+ REQUIRE(v[3] == 40);
+ REQUIRE(it == v.begin() + 3);
+ }
+ }
+
WHEN("inserting when capacity is sufficient")
{
v.reserve(10);
@@ -722,6 +752,14 @@ SCENARIO("Vector modifiers", "[vector]")
REQUIRE(it == v.end());
}
}
+
+ WHEN("erasing the end() iterator")
+ {
+ THEN("a panic is triggered")
+ {
+ REQUIRE_THROWS_AS(v.erase(v.end()), kstd::tests::os_panic);
+ }
+ }
}
}
@@ -944,7 +982,7 @@ SCENARIO("Vector modifier move semantics", "[vector]")
WHEN("erasing an element in the middle")
{
- for (auto& elem : v)
+ for (auto & elem : v)
{
elem.was_copied = false;
elem.was_moved = false;
@@ -955,7 +993,7 @@ SCENARIO("Vector modifier move semantics", "[vector]")
THEN("the subsequent elements are move-assigned leftwards")
{
REQUIRE(v.size() == 2);
-
+
REQUIRE(v[0].value == 10);
REQUIRE_FALSE(v[0].was_moved);
REQUIRE_FALSE(v[0].was_copied);
@@ -970,7 +1008,7 @@ SCENARIO("Vector modifier move semantics", "[vector]")
WHEN("erasing the last element")
{
- for (auto& elem : v)
+ for (auto & elem : v)
{
elem.was_copied = false;
elem.was_moved = false;