aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/tests/src/vector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/tests/src/vector.cpp')
-rw-r--r--libs/kstd/tests/src/vector.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/libs/kstd/tests/src/vector.cpp b/libs/kstd/tests/src/vector.cpp
index 0735c9a..3ff041f 100644
--- a/libs/kstd/tests/src/vector.cpp
+++ b/libs/kstd/tests/src/vector.cpp
@@ -649,6 +649,45 @@ SCENARIO("Vector modifiers", "[vector]")
REQUIRE(it == v.begin() + 1);
}
}
+
+ WHEN("erasing the first element")
+ {
+ auto it = v.erase(v.cbegin());
+
+ THEN("the first element is removed and the size decreases")
+ {
+ REQUIRE(v.size() == 2);
+ REQUIRE(v[0] == 20);
+ REQUIRE(v[1] == 30);
+ REQUIRE(it == v.begin());
+ }
+ }
+
+ WHEN("erasing a middle element")
+ {
+ auto it = v.erase(v.cbegin() + 1);
+
+ THEN("the middle element is removed and the size decreases")
+ {
+ REQUIRE(v.size() == 2);
+ REQUIRE(v[0] == 10);
+ REQUIRE(v[1] == 30);
+ REQUIRE(it == v.begin() + 1);
+ }
+ }
+
+ WHEN("erasing the last element")
+ {
+ auto it = v.erase(v.cend() - 1);
+
+ THEN("the last element is removed and the size decreases")
+ {
+ REQUIRE(v.size() == 2);
+ REQUIRE(v[0] == 10);
+ REQUIRE(v[1] == 20);
+ REQUIRE(it == v.end());
+ }
+ }
}
}
@@ -868,6 +907,58 @@ SCENARIO("Vector modifier move semantics", "[vector]")
REQUIRE(v[3].was_moved);
}
}
+
+ WHEN("erasing an element in the middle")
+ {
+ for (auto& elem : v)
+ {
+ elem.was_copied = false;
+ elem.was_moved = false;
+ }
+
+ auto it = v.erase(v.cbegin() + 1);
+
+ 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);
+
+ REQUIRE(v[1].value == 30);
+ REQUIRE(v[1].was_moved);
+ REQUIRE_FALSE(v[1].was_copied);
+
+ REQUIRE(it == v.begin() + 1);
+ }
+ }
+
+ WHEN("erasing the last element")
+ {
+ for (auto& elem : v)
+ {
+ elem.was_copied = false;
+ elem.was_moved = false;
+ }
+
+ auto it = v.erase(v.cend() - 1);
+
+ THEN("no elements are moved, just the last element destroyed")
+ {
+ REQUIRE(v.size() == 2);
+
+ REQUIRE(v[0].value == 10);
+ REQUIRE_FALSE(v[0].was_moved);
+ REQUIRE_FALSE(v[0].was_copied);
+
+ REQUIRE(v[1].value == 20);
+ REQUIRE_FALSE(v[1].was_moved);
+ REQUIRE_FALSE(v[1].was_copied);
+
+ REQUIRE(it == v.end());
+ }
+ }
}
}