4#include "../../catch2/catch.hpp"
9#define MX_NO_ERROR_REPORTS
21TEST_CASE(
"creating a circular buffer with branching",
"[sigproc::circularBuffer::circularBufferBranch]" )
23 GIVEN(
"a circular buffer" )
25 WHEN(
"adding exactly max entries worth" )
35 REQUIRE( cb[0] == 0 );
36 REQUIRE( cb[1] == 1 );
37 REQUIRE( cb[2] == 2 );
38 REQUIRE( cb[3] == 3 );
39 REQUIRE( cb[4] == 4 );
42 REQUIRE( cb[-1] == 4 );
43 REQUIRE( cb[-2] == 3 );
44 REQUIRE( cb[-3] == 2 );
45 REQUIRE( cb[-4] == 1 );
48 REQUIRE( cb.
at(cb.
latest(),0) == 4 );
51 WHEN(
"adding new values past the end" )
63 REQUIRE( cb[0] == 2 );
64 REQUIRE( cb[1] == 3 );
65 REQUIRE( cb[2] == 4 );
66 REQUIRE( cb[3] == 5 );
67 REQUIRE( cb[4] == 6 );
70 REQUIRE( cb[-1] == 6 );
71 REQUIRE( cb[-2] == 5 );
72 REQUIRE( cb[-3] == 4 );
73 REQUIRE( cb[-4] == 3 );
76 REQUIRE( cb.
at(cb.
latest(),0) == 6 );
79 WHEN(
"wrapping when not full" )
88 REQUIRE( cb[0] == 0 );
89 REQUIRE( cb[1] == 1 );
90 REQUIRE( cb[2] == 2 );
91 REQUIRE( cb[3] == 3 );
92 REQUIRE( cb[4] == 0 );
95 REQUIRE( cb[-1] == 3 );
96 REQUIRE( cb[-2] == 2 );
97 REQUIRE( cb[-3] == 1 );
98 REQUIRE( cb[-4] == 0 );
111TEST_CASE(
"creating a circular buffer with indexing",
"[sigproc::circularBuffer::circularBufferIndex]" )
113 GIVEN(
"a circular buffer" )
115 WHEN(
"adding exactly max entries worth" )
125 REQUIRE( cb[0] == 0 );
126 REQUIRE( cb[1] == 1 );
127 REQUIRE( cb[2] == 2 );
128 REQUIRE( cb[3] == 3 );
129 REQUIRE( cb[4] == 4 );
132 REQUIRE( cb[-1] == 4 );
133 REQUIRE( cb[-2] == 3 );
134 REQUIRE( cb[-3] == 2 );
135 REQUIRE( cb[-4] == 1 );
137 REQUIRE( cb.at(cb.earliest(),0) == 0 );
138 REQUIRE( cb.at(cb.latest(),0) == 4 );
141 WHEN(
"adding new values past the end" )
153 REQUIRE( cb[0] == 2 );
154 REQUIRE( cb[1] == 3 );
155 REQUIRE( cb[2] == 4 );
156 REQUIRE( cb[3] == 5 );
157 REQUIRE( cb[4] == 6 );
160 REQUIRE( cb[-1] == 6 );
161 REQUIRE( cb[-2] == 5 );
162 REQUIRE( cb[-3] == 4 );
163 REQUIRE( cb[-4] == 3 );
165 REQUIRE( cb.at(cb.earliest(),0) == 2 );
166 REQUIRE( cb.at(cb.latest(),0) == 6 );
void maxEntries(indexT maxEnt)
Set the maximum size of the buffer.
indexT earliest()
Returns the index of the earliest entry.
indexT latest()
Returns the index of the latest entry.
void nextEntry(const storedT &newEnt)
Add the next entry to the circular buffer.
Circular buffer which wraps with an if statement (branching) [faster than mod, less memory than index...
storedT & at(indexT refEntry, indexT idx)
Interface implementation for entry access.
Circular buffer which wraps with a pre-populated indices array [generally fastest].
TEST_CASE("creating a circular buffer with branching", "[sigproc::circularBuffer::circularBufferBranch]")