diff options
Diffstat (limited to 'libs/kstd')
| -rw-r--r-- | libs/kstd/kstd/ring_buffer.hpp | 10 | ||||
| -rw-r--r-- | libs/kstd/kstd/ring_buffer.tests.cpp | 10 |
2 files changed, 16 insertions, 4 deletions
diff --git a/libs/kstd/kstd/ring_buffer.hpp b/libs/kstd/kstd/ring_buffer.hpp index 0ceb634d..63ca94a1 100644 --- a/libs/kstd/kstd/ring_buffer.hpp +++ b/libs/kstd/kstd/ring_buffer.hpp @@ -13,6 +13,16 @@ namespace kstd template<typename ValueType, std::size_t Capacity> struct ring_buffer { + using size_type = std::size_t; + + //! Get the maximum number of elements this ring buffer can hold. + //! + //! @return The number of elements that can fit in this ring buffer. + [[nodiscard]] constexpr auto capacity() const noexcept -> size_type + { + return Capacity; + } + }; } // namespace kstd diff --git a/libs/kstd/kstd/ring_buffer.tests.cpp b/libs/kstd/kstd/ring_buffer.tests.cpp index 3608d5ce..f661b50e 100644 --- a/libs/kstd/kstd/ring_buffer.tests.cpp +++ b/libs/kstd/kstd/ring_buffer.tests.cpp @@ -2,16 +2,18 @@ #include <catch2/catch_test_macros.hpp> -#include <tuple> - SCENARIO("Ring Buffer initialization and construction", "[ring_buffer]") { GIVEN("An empty context") { - WHEN("constructing by default") + WHEN("constructing by default using a capacity of 5") { auto buffer = kstd::ring_buffer<int, 5>{}; - std::ignore = buffer; + + THEN("the capacity is 5") + { + REQUIRE(buffer.capacity() == 5); + } } } }
\ No newline at end of file |
