12 #include <gtest/gtest.h> 16 TEST(circular_buffer_tests, EmptyPop)
22 GTEST_FAIL() <<
"Exception was expected but didn't happen!";
23 }
catch (std::exception &) {
27 TEST(circular_buffer_tests, EmptyPopAfterPushes)
29 const size_t LEN = 20;
31 for (
size_t nWr=0;nWr<
LEN;nWr++)
33 for (
size_t i=0;i<nWr;i++) cb.
push(12);
35 for (
size_t i=0;i<nWr;i++) cb.
pop(ret);
39 GTEST_FAIL() <<
"Exception was expected but didn't happen!";
40 }
catch (std::exception &) {
46 TEST(circular_buffer_tests, RandomWriteAndPeek)
48 const size_t LEN = 20;
51 for (
size_t iter=0;iter<1000;iter++)
54 for (
size_t i=0;i<nWr;i++) cb.
push(i);
56 for (
size_t i=0;i<nWr;i++) {
58 EXPECT_EQ(ret,
cb_t(i));
60 for (
size_t i=0;i<nWr;i++) {
62 EXPECT_EQ(ret,
cb_t(i));
66 TEST(circular_buffer_tests, RandomWriteManyAndPeek)
68 const size_t LEN = 20;
70 std::vector<cb_t> dum_buf;
72 for (
size_t iter=0;iter<1000;iter++)
79 for (
size_t i=0;i<nWr;i++) ret=cb.
peek(i);
87 TEST(circular_buffer_tests, RandomWriteAndPeekOverrun)
89 const size_t LEN = 20;
92 for (
size_t iter=0;iter<100;iter++)
95 for (
size_t i=0;i<nWr;i++) cb.
push(i);
97 for (
unsigned k=0;k<5;k++) {
100 GTEST_FAIL() <<
"Exception was expected but didn't happen!";
101 }
catch (std::exception &) {
105 for (
size_t i=0;i<nWr;i++) cb.
pop(ret);
uint32_t drawUniform32bit()
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, in the whole range of 32-bit integers.
T peek() const
Peek (see without modifying) what is to be read from the buffer if pop() was to be called...
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
TEST(circular_buffer_tests, EmptyPop)
void pop_many(T *out_array, size_t count)
Pop a number of elements into a user-provided array.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
T pop()
Retrieve an element from the buffer.
A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the...
void push(T d)
Insert a copy of the given element in the buffer.
void peek_many(T *out_array, size_t count) const
Like peek(), for multiple elements, storing a number of elements into a user-provided array...
void push_many(T *array_elements, size_t count)
Insert an array of elements in the buffer.