aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-10-02 14:41:59 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-10-02 14:41:59 +0200
commit9b789956ff8013d21d6b4074de488f1eb5eb4625 (patch)
tree8b25375442ae05321122e98bb9fdf74168b437eb
parent88c9a78261fe1d54e297c7ac8bd4c052c19985fc (diff)
downloadkernel-9b789956ff8013d21d6b4074de488f1eb5eb4625.tar.xz
kernel-9b789956ff8013d21d6b4074de488f1eb5eb4625.zip
kstd: ring_buffer: add more pop_front() tests
-rw-r--r--libs/kstd/kstd/ring_buffer.tests.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/libs/kstd/kstd/ring_buffer.tests.cpp b/libs/kstd/kstd/ring_buffer.tests.cpp
index 479283ed..767e7422 100644
--- a/libs/kstd/kstd/ring_buffer.tests.cpp
+++ b/libs/kstd/kstd/ring_buffer.tests.cpp
@@ -1341,4 +1341,47 @@ SCENARIO("Ring Buffer modifiers", "[kstd][ring_buffer]")
REQUIRE_FALSE(buffer.try_push_back(kstd::tests::static_copy_move_tracker{}));
}
}
+
+ GIVEN("A ring buffer with a capacity of 3 that has wrapped around")
+ {
+ auto buffer = kstd::ring_buffer<int, 3>{};
+ buffer.push_back(1);
+ buffer.push_back(2);
+ buffer.push_back(3);
+ buffer.push_back(4);
+
+ WHEN("popping an element")
+ {
+ buffer.pop_front();
+
+ THEN("the size is 2")
+ {
+ REQUIRE(buffer.size() == 2);
+ }
+
+ THEN("the remaining elements are the two newest, in order")
+ {
+ REQUIRE(buffer.at(0) == 3);
+ REQUIRE(buffer.at(1) == 4);
+ }
+ }
+
+ WHEN("popping an element and then pushing a new one")
+ {
+ buffer.pop_front();
+ buffer.push_back(5);
+
+ THEN("the size is back to 3")
+ {
+ REQUIRE(buffer.size() == 3);
+ }
+
+ THEN("the content reflects the pop and the push")
+ {
+ REQUIRE(buffer.at(0) == 3);
+ REQUIRE(buffer.at(1) == 4);
+ REQUIRE(buffer.at(2) == 5);
+ }
+ }
+ }
} \ No newline at end of file