20 lines
613 B
C++
20 lines
613 B
C++
#include "harness.hpp"
|
|
#include <plot/data/ring_buffer.hpp>
|
|
|
|
PLOT_TEST(ring_wraps_and_keeps_latest) {
|
|
plot::data::RingBuffer<f32> r(8); // capacity rounded up to a power of two
|
|
for (int i = 0; i < 20; ++i) r.push(f32(i));
|
|
PLOT_CHECK(r.size() == 8);
|
|
PLOT_CHECK_NEAR(r[0], 12.0); // oldest retained
|
|
PLOT_CHECK_NEAR(r[7], 19.0); // newest
|
|
}
|
|
PLOT_TEST(ring_clear_resets) {
|
|
plot::data::RingBuffer<f32> r(8);
|
|
for (int i = 0; i < 5; ++i) r.push(f32(i));
|
|
r.clear();
|
|
PLOT_CHECK(r.size() == 0);
|
|
r.push(42.0f);
|
|
PLOT_CHECK(r.size() == 1);
|
|
PLOT_CHECK_NEAR(r[0], 42.0);
|
|
}
|