Circular buffer - basic unit test

pull/36/head
D.R.racer 2021-05-21 07:57:32 +02:00 committed by DRracer
parent 5a4903a2ff
commit f81ecf1294
3 changed files with 36 additions and 1 deletions

View File

@ -1 +1 @@
#
add_subdirectory(circular_buffer)

View File

@ -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)

View File

@ -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());
}