forked from Ferdi265/cxx-ring-buffer
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
#include <array>
|
|
#include <ring-buffer.h>
|
|
|
|
template <typename T, size_t N>
|
|
constexpr bool array_equal(const std::array<T, N>& a, const std::array<T, N>& b) {
|
|
for (size_t i = 0; i < N; i++) {
|
|
if (a[i] != b[i]) return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
constexpr bool test() {
|
|
ring_buffer<int, 4> buf;
|
|
|
|
buf.push_back(1);
|
|
buf.push_back(2);
|
|
buf.push_back(3);
|
|
buf.push_back(4);
|
|
buf.push_back(5);
|
|
buf.push_back(6);
|
|
|
|
{
|
|
std::array<int, 4> expected{13, 14, 15, 16};
|
|
std::array<int, 4> actual;
|
|
int actual_index = 0;
|
|
for (int& i : buf) {
|
|
i += 10;
|
|
actual[actual_index++] = i;
|
|
}
|
|
if (!array_equal(actual, expected)) return false;
|
|
}
|
|
|
|
buf.push_back(7);
|
|
|
|
{
|
|
std::array<int, 4> expected{24, 25, 26, 17};
|
|
std::array<int, 4> actual;
|
|
int actual_index = 0;
|
|
for (int& i : buf) {
|
|
i += 10;
|
|
actual[actual_index++] = i;
|
|
}
|
|
if (!array_equal(actual, expected)) return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static_assert(test());
|
|
|
|
int main() {}
|