From 85157a56c3a7937120ddb4fe4e4850c59dc2bed4 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 22 Nov 2017 17:04:57 -0800 Subject: [PATCH] CircularBuffer now uses an idiomatic interface in C++ and Java (#421) --- .../cpp/Filters/LinearDigitalFilter.cpp | 8 +- .../include/Filters/LinearDigitalFilter.h | 6 +- .../{CircularBuffer.h => circular_buffer.h} | 31 +++-- ...CircularBuffer.inc => circular_buffer.inc} | 72 +++++++++-- .../FRCUserProgram/cpp/CircularBufferTest.cpp | 112 +++++++++--------- .../edu/wpi/first/wpilibj/CircularBuffer.java | 42 ++++++- .../wpilibj/filters/LinearDigitalFilter.java | 8 +- .../wpi/first/wpilibj/CircularBufferTest.java | 96 +++++++-------- 8 files changed, 235 insertions(+), 140 deletions(-) rename wpilibc/src/main/native/include/{CircularBuffer.h => circular_buffer.h} (63%) rename wpilibc/src/main/native/include/{CircularBuffer.inc => circular_buffer.inc} (74%) diff --git a/wpilibc/src/main/native/cpp/Filters/LinearDigitalFilter.cpp b/wpilibc/src/main/native/cpp/Filters/LinearDigitalFilter.cpp index 514eb50215..a2e4eee6c3 100644 --- a/wpilibc/src/main/native/cpp/Filters/LinearDigitalFilter.cpp +++ b/wpilibc/src/main/native/cpp/Filters/LinearDigitalFilter.cpp @@ -95,8 +95,8 @@ double LinearDigitalFilter::Get() const { } void LinearDigitalFilter::Reset() { - m_inputs.Reset(); - m_outputs.Reset(); + m_inputs.reset(); + m_outputs.reset(); } /** @@ -108,7 +108,7 @@ double LinearDigitalFilter::PIDGet() { double retVal = 0.0; // Rotate the inputs - m_inputs.PushFront(PIDGetSource()); + m_inputs.push_front(PIDGetSource()); // Calculate the new value for (size_t i = 0; i < m_inputGains.size(); i++) { @@ -119,7 +119,7 @@ double LinearDigitalFilter::PIDGet() { } // Rotate the outputs - m_outputs.PushFront(retVal); + m_outputs.push_front(retVal); return retVal; } diff --git a/wpilibc/src/main/native/include/Filters/LinearDigitalFilter.h b/wpilibc/src/main/native/include/Filters/LinearDigitalFilter.h index 4d58c90d3b..b5b8bfbbe8 100644 --- a/wpilibc/src/main/native/include/Filters/LinearDigitalFilter.h +++ b/wpilibc/src/main/native/include/Filters/LinearDigitalFilter.h @@ -12,8 +12,8 @@ #include -#include "CircularBuffer.h" #include "Filter.h" +#include "circular_buffer.h" namespace frc { @@ -89,8 +89,8 @@ class LinearDigitalFilter : public Filter { double PIDGet() override; private: - CircularBuffer m_inputs; - CircularBuffer m_outputs; + circular_buffer m_inputs; + circular_buffer m_outputs; std::vector m_inputGains; std::vector m_outputGains; }; diff --git a/wpilibc/src/main/native/include/CircularBuffer.h b/wpilibc/src/main/native/include/circular_buffer.h similarity index 63% rename from wpilibc/src/main/native/include/CircularBuffer.h rename to wpilibc/src/main/native/include/circular_buffer.h index 1559824cb0..aab3b7be9c 100644 --- a/wpilibc/src/main/native/include/CircularBuffer.h +++ b/wpilibc/src/main/native/include/circular_buffer.h @@ -17,16 +17,29 @@ namespace frc { * old values. */ template -class CircularBuffer { +class circular_buffer { public: - explicit CircularBuffer(size_t size); + explicit circular_buffer(size_t size); - void PushFront(T value); - void PushBack(T value); - T PopFront(); - T PopBack(); - void Resize(size_t size); - void Reset(); + typedef T value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef size_t size_type; + typedef std::forward_iterator_tag iterator_category; + typedef std::ptrdiff_t difference_type; + + size_type size() const; + T& front(); + const T& front() const; + T& back(); + const T& back() const; + void push_front(T value); + void push_back(T value); + T pop_front(); + T pop_back(); + void resize(size_t size); + void reset(); T& operator[](size_t index); const T& operator[](size_t index) const; @@ -46,4 +59,4 @@ class CircularBuffer { } // namespace frc -#include "CircularBuffer.inc" +#include "circular_buffer.inc" diff --git a/wpilibc/src/main/native/include/CircularBuffer.inc b/wpilibc/src/main/native/include/circular_buffer.inc similarity index 74% rename from wpilibc/src/main/native/include/CircularBuffer.inc rename to wpilibc/src/main/native/include/circular_buffer.inc index 3e66930c97..c25aea1073 100644 --- a/wpilibc/src/main/native/include/CircularBuffer.inc +++ b/wpilibc/src/main/native/include/circular_buffer.inc @@ -12,14 +12,64 @@ namespace frc { template -CircularBuffer::CircularBuffer(size_t size) : m_data(size, 0) {} +circular_buffer::circular_buffer(size_t size) : m_data(size, 0) {} + +/** + * Returns number of elements in buffer + */ +template +typename circular_buffer::size_type circular_buffer::size() const { + return m_length; +} + +/** + * Returns value at front of buffer + */ +template +T& circular_buffer::front() { + return (*this)[0]; +} + +/** + * Returns value at front of buffer + */ +template +const T& circular_buffer::front() const { + return (*this)[0]; +} + +/** + * Returns value at back of buffer + */ +template +T& circular_buffer::back() { + // If there are no elements in the buffer, do nothing + if (m_length == 0) { + return 0; + } + + return m_data[(m_front + m_length - 1) % m_data.size()]; +} + +/** + * Returns value at back of buffer + */ +template +const T& circular_buffer::back() const { + // If there are no elements in the buffer, do nothing + if (m_length == 0) { + return 0; + } + + return m_data[(m_front + m_length - 1) % m_data.size()]; +} /** * Push new value onto front of the buffer. The value at the back is overwritten * if the buffer is full. */ template -void CircularBuffer::PushFront(T value) { +void circular_buffer::push_front(T value) { if (m_data.size() == 0) { return; } @@ -38,7 +88,7 @@ void CircularBuffer::PushFront(T value) { * if the buffer is full. */ template -void CircularBuffer::PushBack(T value) { +void circular_buffer::push_back(T value) { if (m_data.size() == 0) { return; } @@ -57,7 +107,7 @@ void CircularBuffer::PushBack(T value) { * Pop value at front of buffer. */ template -T CircularBuffer::PopFront() { +T circular_buffer::pop_front() { // If there are no elements in the buffer, do nothing if (m_length == 0) { return 0; @@ -73,7 +123,7 @@ T CircularBuffer::PopFront() { * Pop value at back of buffer. */ template -T CircularBuffer::PopBack() { +T circular_buffer::pop_back() { // If there are no elements in the buffer, do nothing if (m_length == 0) { return 0; @@ -87,7 +137,7 @@ T CircularBuffer::PopBack() { * Resizes internal buffer to given size. */ template -void CircularBuffer::Resize(size_t size) { +void circular_buffer::resize(size_t size) { if (size > m_data.size()) { // Find end of buffer size_t insertLocation = (m_front + m_length) % m_data.size(); @@ -140,7 +190,7 @@ void CircularBuffer::Resize(size_t size) { * Sets internal buffer contents to zero. */ template -void CircularBuffer::Reset() { +void circular_buffer::reset() { std::fill(m_data.begin(), m_data.end(), 0); m_front = 0; m_length = 0; @@ -150,7 +200,7 @@ void CircularBuffer::Reset() { * @return Element at index starting from front of buffer. */ template -T& CircularBuffer::operator[](size_t index) { +T& circular_buffer::operator[](size_t index) { return m_data[(m_front + index) % m_data.size()]; } @@ -158,7 +208,7 @@ T& CircularBuffer::operator[](size_t index) { * @return Element at index starting from front of buffer. */ template -const T& CircularBuffer::operator[](size_t index) const { +const T& circular_buffer::operator[](size_t index) const { return m_data[(m_front + index) % m_data.size()]; } @@ -168,7 +218,7 @@ const T& CircularBuffer::operator[](size_t index) const { * @return The result of the modulo operation. */ template -size_t CircularBuffer::ModuloInc(size_t index) { +size_t circular_buffer::ModuloInc(size_t index) { return (index + 1) % m_data.size(); } @@ -178,7 +228,7 @@ size_t CircularBuffer::ModuloInc(size_t index) { * @return The result of the modulo operation. */ template -size_t CircularBuffer::ModuloDec(size_t index) { +size_t circular_buffer::ModuloDec(size_t index) { if (index == 0) { return m_data.size() - 1; } else { diff --git a/wpilibcIntegrationTests/src/FRCUserProgram/cpp/CircularBufferTest.cpp b/wpilibcIntegrationTests/src/FRCUserProgram/cpp/CircularBufferTest.cpp index 5e333df859..9fa19e4bc3 100644 --- a/wpilibcIntegrationTests/src/FRCUserProgram/cpp/CircularBufferTest.cpp +++ b/wpilibcIntegrationTests/src/FRCUserProgram/cpp/CircularBufferTest.cpp @@ -5,7 +5,7 @@ /* the project. */ /*----------------------------------------------------------------------------*/ -#include "CircularBuffer.h" // NOLINT(build/include_order) +#include "circular_buffer.h" // NOLINT(build/include_order) #include @@ -24,10 +24,10 @@ static const std::array pushBackOut = { 342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913}; TEST(CircularBufferTest, PushFrontTest) { - CircularBuffer queue(8); + circular_buffer queue(8); for (auto& value : values) { - queue.PushFront(value); + queue.push_front(value); } for (size_t i = 0; i < pushFrontOut.size(); i++) { @@ -36,10 +36,10 @@ TEST(CircularBufferTest, PushFrontTest) { } TEST(CircularBufferTest, PushBackTest) { - CircularBuffer queue(8); + circular_buffer queue(8); for (auto& value : values) { - queue.PushBack(value); + queue.push_back(value); } for (size_t i = 0; i < pushBackOut.size(); i++) { @@ -48,12 +48,12 @@ TEST(CircularBufferTest, PushBackTest) { } TEST(CircularBufferTest, PushPopTest) { - CircularBuffer queue(3); + circular_buffer queue(3); // Insert three elements into the buffer - queue.PushBack(1.0); - queue.PushBack(2.0); - queue.PushBack(3.0); + queue.push_back(1.0); + queue.push_back(2.0); + queue.push_back(3.0); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); @@ -64,40 +64,40 @@ TEST(CircularBufferTest, PushPopTest) { * front-most elements. */ - queue.PushBack(4.0); // Overwrite 1 with 4 + queue.push_back(4.0); // Overwrite 1 with 4 // The buffer now contains 2, 3 and 4 EXPECT_EQ(2.0, queue[0]); EXPECT_EQ(3.0, queue[1]); EXPECT_EQ(4.0, queue[2]); - queue.PushBack(5.0); // Overwrite 2 with 5 + queue.push_back(5.0); // Overwrite 2 with 5 // The buffer now contains 3, 4 and 5 EXPECT_EQ(3.0, queue[0]); EXPECT_EQ(4.0, queue[1]); EXPECT_EQ(5.0, queue[2]); - EXPECT_EQ(5.0, queue.PopBack()); // 5 is removed + EXPECT_EQ(5.0, queue.pop_back()); // 5 is removed // The buffer now contains 3 and 4 EXPECT_EQ(3.0, queue[0]); EXPECT_EQ(4.0, queue[1]); - EXPECT_EQ(3.0, queue.PopFront()); // 3 is removed + EXPECT_EQ(3.0, queue.pop_front()); // 3 is removed // Leaving only one element with value == 4 EXPECT_EQ(4.0, queue[0]); } TEST(CircularBufferTest, ResetTest) { - CircularBuffer queue(5); + circular_buffer queue(5); for (size_t i = 1; i < 6; i++) { - queue.PushBack(i); + queue.push_back(i); } - queue.Reset(); + queue.reset(); for (size_t i = 0; i < 5; i++) { EXPECT_EQ(0.0, queue[i]); @@ -105,105 +105,105 @@ TEST(CircularBufferTest, ResetTest) { } TEST(CircularBufferTest, ResizeTest) { - CircularBuffer queue(5); + circular_buffer queue(5); /* Buffer contains {1, 2, 3, _, _} * ^ front */ - queue.PushBack(1.0); - queue.PushBack(2.0); - queue.PushBack(3.0); + queue.push_back(1.0); + queue.push_back(2.0); + queue.push_back(3.0); - queue.Resize(2); + queue.resize(2); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Resize(5); + queue.resize(5); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Reset(); + queue.reset(); /* Buffer contains {_, 1, 2, 3, _} * ^ front */ - queue.PushBack(0.0); - queue.PushBack(1.0); - queue.PushBack(2.0); - queue.PushBack(3.0); - queue.PopFront(); + queue.push_back(0.0); + queue.push_back(1.0); + queue.push_back(2.0); + queue.push_back(3.0); + queue.pop_front(); - queue.Resize(2); + queue.resize(2); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Resize(5); + queue.resize(5); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Reset(); + queue.reset(); /* Buffer contains {_, _, 1, 2, 3} * ^ front */ - queue.PushBack(0.0); - queue.PushBack(0.0); - queue.PushBack(1.0); - queue.PushBack(2.0); - queue.PushBack(3.0); - queue.PopFront(); - queue.PopFront(); + queue.push_back(0.0); + queue.push_back(0.0); + queue.push_back(1.0); + queue.push_back(2.0); + queue.push_back(3.0); + queue.pop_front(); + queue.pop_front(); - queue.Resize(2); + queue.resize(2); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Resize(5); + queue.resize(5); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Reset(); + queue.reset(); /* Buffer contains {3, _, _, 1, 2} * ^ front */ - queue.PushBack(3.0); - queue.PushFront(2.0); - queue.PushFront(1.0); + queue.push_back(3.0); + queue.push_front(2.0); + queue.push_front(1.0); - queue.Resize(2); + queue.resize(2); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Resize(5); + queue.resize(5); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Reset(); + queue.reset(); /* Buffer contains {2, 3, _, _, 1} * ^ front */ - queue.PushBack(2.0); - queue.PushBack(3.0); - queue.PushFront(1.0); + queue.push_back(2.0); + queue.push_back(3.0); + queue.push_front(1.0); - queue.Resize(2); + queue.resize(2); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - queue.Resize(5); + queue.resize(5); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); - // Test PushBack() after resize - queue.PushBack(3.0); + // Test push_back() after resize + queue.push_back(3.0); EXPECT_EQ(1.0, queue[0]); EXPECT_EQ(2.0, queue[1]); EXPECT_EQ(3.0, queue[2]); - // Test PushFront() after resize - queue.PushFront(4.0); + // Test push_front() after resize + queue.push_front(4.0); EXPECT_EQ(4.0, queue[0]); EXPECT_EQ(1.0, queue[1]); EXPECT_EQ(2.0, queue[2]); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/CircularBuffer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/CircularBuffer.java index 889083a4d3..06a0284a99 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/CircularBuffer.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/CircularBuffer.java @@ -31,11 +31,43 @@ public class CircularBuffer { } } + /** + * Returns number of elements in buffer. + * + * @return number of elements in buffer + */ + double size() { + return m_length; + } + + /** + * Get value at front of buffer. + * + * @return value at front of buffer + */ + double getFirst() { + return m_data[m_front]; + } + + /** + * Get value at back of buffer. + * + * @return value at back of buffer + */ + double getLast() { + // If there are no elements in the buffer, do nothing + if (m_length == 0) { + return 0.0; + } + + return m_data[(m_front + m_length - 1) % m_data.length]; + } + /** * Push new value onto front of the buffer. The value at the back is overwritten if the buffer is * full. */ - public void pushFront(double value) { + public void addFirst(double value) { if (m_data.length == 0) { return; } @@ -53,7 +85,7 @@ public class CircularBuffer { * Push new value onto back of the buffer. The value at the front is overwritten if the buffer is * full. */ - public void pushBack(double value) { + public void addLast(double value) { if (m_data.length == 0) { return; } @@ -73,7 +105,7 @@ public class CircularBuffer { * * @return value at front of buffer */ - public double popFront() { + public double removeFirst() { // If there are no elements in the buffer, do nothing if (m_length == 0) { return 0.0; @@ -89,7 +121,7 @@ public class CircularBuffer { /** * Pop value at back of buffer. */ - public double popBack() { + public double removeLast() { // If there are no elements in the buffer, do nothing if (m_length == 0) { return 0.0; @@ -117,7 +149,7 @@ public class CircularBuffer { /** * Sets internal buffer contents to zero. */ - public void reset() { + public void clear() { for (int i = 0; i < m_data.length; i++) { m_data[i] = 0.0; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java index d0fb8c97db..14fca0d724 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/filters/LinearDigitalFilter.java @@ -151,8 +151,8 @@ public class LinearDigitalFilter extends Filter { @Override public void reset() { - m_inputs.reset(); - m_outputs.reset(); + m_inputs.clear(); + m_outputs.clear(); } /** @@ -165,7 +165,7 @@ public class LinearDigitalFilter extends Filter { double retVal = 0.0; // Rotate the inputs - m_inputs.pushFront(pidGetSource()); + m_inputs.addFirst(pidGetSource()); // Calculate the new value for (int i = 0; i < m_inputGains.length; i++) { @@ -176,7 +176,7 @@ public class LinearDigitalFilter extends Filter { } // Rotate the outputs - m_outputs.pushFront(retVal); + m_outputs.addFirst(retVal); return retVal; } diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/CircularBufferTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/CircularBufferTest.java index 0c64228f29..402490727f 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/CircularBufferTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/CircularBufferTest.java @@ -15,9 +15,9 @@ import static org.junit.Assert.assertEquals; public class CircularBufferTest { private double[] m_values = {751.848, 766.366, 342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913}; - private double[] m_pushFrontOut = {799.913, 421.125, 22.727, 445.697, 132.344, + private double[] m_addFirstOut = {799.913, 421.125, 22.727, 445.697, 132.344, 716.126, 234.252, 342.657}; - private double[] m_pushBackOut = {342.657, 234.252, 716.126, 132.344, 445.697, + private double[] m_addLastOut = {342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913}; @BeforeClass @@ -26,28 +26,28 @@ public class CircularBufferTest { } @Test - public void pushFrontTest() { + public void addFirstTest() { CircularBuffer queue = new CircularBuffer(8); for (double value : m_values) { - queue.pushFront(value); + queue.addFirst(value); } - for (int i = 0; i < m_pushFrontOut.length; i++) { - assertEquals(m_pushFrontOut[i], queue.get(i), 0.00005); + for (int i = 0; i < m_addFirstOut.length; i++) { + assertEquals(m_addFirstOut[i], queue.get(i), 0.00005); } } @Test - public void pushBackTest() { + public void addLastTest() { CircularBuffer queue = new CircularBuffer(8); for (double value : m_values) { - queue.pushBack(value); + queue.addLast(value); } - for (int i = 0; i < m_pushBackOut.length; i++) { - assertEquals(m_pushBackOut[i], queue.get(i), 0.00005); + for (int i = 0; i < m_addLastOut.length; i++) { + assertEquals(m_addLastOut[i], queue.get(i), 0.00005); } } @@ -56,9 +56,9 @@ public class CircularBufferTest { CircularBuffer queue = new CircularBuffer(3); // Insert three elements into the buffer - queue.pushBack(1.0); - queue.pushBack(2.0); - queue.pushBack(3.0); + queue.addLast(1.0); + queue.addLast(2.0); + queue.addLast(3.0); assertEquals(1.0, queue.get(0), 0.00005); assertEquals(2.0, queue.get(1), 0.00005); @@ -69,27 +69,27 @@ public class CircularBufferTest { * front-most elements. */ - queue.pushBack(4.0); // Overwrite 1 with 4 + queue.addLast(4.0); // Overwrite 1 with 4 // The buffer now contains 2, 3, and 4 assertEquals(2.0, queue.get(0), 0.00005); assertEquals(3.0, queue.get(1), 0.00005); assertEquals(4.0, queue.get(2), 0.00005); - queue.pushBack(5.0); // Overwrite 2 with 5 + queue.addLast(5.0); // Overwrite 2 with 5 // The buffer now contains 3, 4, and 5 assertEquals(3.0, queue.get(0), 0.00005); assertEquals(4.0, queue.get(1), 0.00005); assertEquals(5.0, queue.get(2), 0.00005); - assertEquals(5.0, queue.popBack(), 0.00005); // 5 is removed + assertEquals(5.0, queue.removeLast(), 0.00005); // 5 is removed // The buffer now contains 3 and 4 assertEquals(3.0, queue.get(0), 0.00005); assertEquals(4.0, queue.get(1), 0.00005); - assertEquals(3.0, queue.popFront(), 0.00005); // 3 is removed + assertEquals(3.0, queue.removeFirst(), 0.00005); // 3 is removed // Leaving only one element with value == 4 assertEquals(4.0, queue.get(0), 0.00005); @@ -100,10 +100,10 @@ public class CircularBufferTest { CircularBuffer queue = new CircularBuffer(5); for (int i = 0; i < 6; i++) { - queue.pushBack(i); + queue.addLast(i); } - queue.reset(); + queue.clear(); for (int i = 0; i < 5; i++) { assertEquals(0.0, queue.get(i), 0.00005); @@ -117,9 +117,9 @@ public class CircularBufferTest { /* Buffer contains {1, 2, 3, _, _} * ^ front */ - queue.pushBack(1.0); - queue.pushBack(2.0); - queue.pushBack(3.0); + queue.addLast(1.0); + queue.addLast(2.0); + queue.addLast(3.0); queue.resize(2); assertEquals(1.0, queue.get(0), 0.00005); @@ -129,16 +129,16 @@ public class CircularBufferTest { assertEquals(1.0, queue.get(0), 0.00005); assertEquals(2.0, queue.get(1), 0.00005); - queue.reset(); + queue.clear(); /* Buffer contains {_, 1, 2, 3, _} * ^ front */ - queue.pushBack(0.0); - queue.pushBack(1.0); - queue.pushBack(2.0); - queue.pushBack(3.0); - queue.popFront(); + queue.addLast(0.0); + queue.addLast(1.0); + queue.addLast(2.0); + queue.addLast(3.0); + queue.removeFirst(); queue.resize(2); assertEquals(1.0, queue.get(0), 0.00005); @@ -148,18 +148,18 @@ public class CircularBufferTest { assertEquals(1.0, queue.get(0), 0.00005); assertEquals(2.0, queue.get(1), 0.00005); - queue.reset(); + queue.clear(); /* Buffer contains {_, _, 1, 2, 3} * ^ front */ - queue.pushBack(0.0); - queue.pushBack(0.0); - queue.pushBack(1.0); - queue.pushBack(2.0); - queue.pushBack(3.0); - queue.popFront(); - queue.popFront(); + queue.addLast(0.0); + queue.addLast(0.0); + queue.addLast(1.0); + queue.addLast(2.0); + queue.addLast(3.0); + queue.removeFirst(); + queue.removeFirst(); queue.resize(2); assertEquals(1.0, queue.get(0), 0.00005); @@ -169,14 +169,14 @@ public class CircularBufferTest { assertEquals(1.0, queue.get(0), 0.00005); assertEquals(2.0, queue.get(1), 0.00005); - queue.reset(); + queue.clear(); /* Buffer contains {3, _, _, 1, 2} * ^ front */ - queue.pushBack(3.0); - queue.pushFront(2.0); - queue.pushFront(1.0); + queue.addLast(3.0); + queue.addFirst(2.0); + queue.addFirst(1.0); queue.resize(2); assertEquals(1.0, queue.get(0), 0.00005); @@ -186,14 +186,14 @@ public class CircularBufferTest { assertEquals(1.0, queue.get(0), 0.00005); assertEquals(2.0, queue.get(1), 0.00005); - queue.reset(); + queue.clear(); /* Buffer contains {2, 3, _, _, 1} * ^ front */ - queue.pushBack(2.0); - queue.pushBack(3.0); - queue.pushFront(1.0); + queue.addLast(2.0); + queue.addLast(3.0); + queue.addFirst(1.0); queue.resize(2); assertEquals(1.0, queue.get(0), 0.00005); @@ -203,14 +203,14 @@ public class CircularBufferTest { assertEquals(1.0, queue.get(0), 0.00005); assertEquals(2.0, queue.get(1), 0.00005); - // Test pushBack() after resize - queue.pushBack(3.0); + // Test addLast() after resize + queue.addLast(3.0); assertEquals(1.0, queue.get(0), 0.00005); assertEquals(2.0, queue.get(1), 0.00005); assertEquals(3.0, queue.get(2), 0.00005); - // Test pushFront() after resize - queue.pushFront(4.0); + // Test addFirst() after resize + queue.addFirst(4.0); assertEquals(4.0, queue.get(0), 0.00005); assertEquals(1.0, queue.get(1), 0.00005); assertEquals(2.0, queue.get(2), 0.00005);