Circular buffer - basic unit test
parent
5a4903a2ff
commit
f81ecf1294
|
|
@ -1 +1 @@
|
|||
#
|
||||
add_subdirectory(circular_buffer)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
# define the test executable
|
||||
add_executable(circular_buffer_tests test_circular_buffer.cpp)
|
||||
|
||||
# define required search paths
|
||||
target_include_directories(circular_buffer_tests PUBLIC ${CMAKE_SOURCE_DIR}/src/hal)
|
||||
|
||||
# tell build system about the test case
|
||||
add_catch_test(circular_buffer_tests)
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "circular_buffer.h"
|
||||
|
||||
using Catch::Matchers::Equals;
|
||||
|
||||
TEST_CASE("circular_buffer::basic", "[circular_buffer]") {
|
||||
|
||||
using CB = CircularBuffer<uint8_t, uint8_t, 32>;
|
||||
|
||||
CB cb;
|
||||
|
||||
// at the beginning the buffer is empty
|
||||
REQUIRE(cb.empty());
|
||||
|
||||
// since its capacity was defined as 32, at least one element must be successfully inserted
|
||||
CHECK(cb.push(1));
|
||||
|
||||
// is the element there?
|
||||
REQUIRE(!cb.empty());
|
||||
CHECK(cb.front() == 1);
|
||||
|
||||
// remove the element
|
||||
uint8_t b = 0;
|
||||
CHECK(cb.pop(b));
|
||||
CHECK(b == 1);
|
||||
CHECK(cb.empty());
|
||||
}
|
||||
Loading…
Reference in New Issue