14 #include <gtest/gtest.h> 20 TEST(circular_buffer_tests, EmptyPop)
27 GTEST_FAIL() <<
"Exception was expected but didn't happen!";
29 catch (std::exception&)
34 TEST(circular_buffer_tests, EmptyPopAfterPushes)
36 const size_t LEN = 20;
38 for (
size_t nWr = 0; nWr <
LEN; nWr++)
40 for (
size_t i = 0; i < nWr; i++) cb.
push(12);
42 for (
size_t i = 0; i < nWr; i++) cb.
pop(ret);
47 GTEST_FAIL() <<
"Exception was expected but didn't happen!";
49 catch (std::exception&)
56 TEST(circular_buffer_tests, RandomWriteAndPeek)
58 const size_t LEN = 20;
61 for (
size_t iter = 0; iter < 1000; iter++)
65 for (
size_t i = 0; i < nWr; i++) cb.
push(i);
67 for (
size_t i = 0; i < nWr; i++)
70 EXPECT_EQ(ret,
cb_t(i));
72 for (
size_t i = 0; i < nWr; i++)
75 EXPECT_EQ(ret,
cb_t(i));
79 TEST(circular_buffer_tests, RandomWriteManyAndPeek)
81 const size_t LEN = 20;
83 std::vector<cb_t> dum_buf;
85 for (
size_t iter = 0; iter < 1000; iter++)
94 for (
size_t i = 0; i < nWr; i++) ret = cb.
peek(i);
104 TEST(circular_buffer_tests, RandomWriteAndPeekOverrun)
106 const size_t LEN = 20;
109 for (
size_t iter = 0; iter < 100; iter++)
113 for (
size_t i = 0; i < nWr; i++) cb.
push(i);
115 for (
unsigned k = 0; k < 5; k++)
119 ret = cb.
peek(nWr + k);
120 GTEST_FAIL() <<
"Exception was expected but didn't happen!";
122 catch (std::exception&)
127 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...
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.
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.