29 static const size_t SIZE = 8;
30 static int array[SIZE];
46 TEST(Size_whenEmpty) {
49 ASSERT_EQ_MSG(0, testable->
size());
64 TEST(enqueue_firstElement) {
69 ASSERT_EQ_MSG(1, testable->
size());
70 ASSERT_EQ_MSG(value, testable->
peek());
75 TEST(Clear_whenEmpty) {
83 TEST(Clear_withOneElement) {
93 TEST(Peek_doesNotRemoveElement) {
98 ASSERT_EQ_MSG(1, testable->
size());
99 ASSERT_EQ_MSG(value, testable->
peek());
100 ASSERT_EQ_MSG(1, testable->
size());
101 ASSERT_EQ_MSG(value, testable->
peek());
106 TEST(enqueue_twoElements) {
107 const int first = 42;
108 const int second = 13;
112 ASSERT_EQ_MSG(1, testable->
size());
113 ASSERT_EQ_MSG(first, testable->
peek());
116 ASSERT_EQ_MSG(2, testable->
size());
117 ASSERT_EQ_MSG(second, testable->m_array[1]);
122 TEST(Deque_singleElement) {
125 const int value = 42;
129 ASSERT_EQ_MSG(1, testable->
size());
131 const int actual = testable->
dequeue();
132 ASSERT_EQ_MSG(value, actual);
134 ASSERT_EQ_MSG(0, testable->
size());
139 TEST(Deque_twoElements) {
142 const int first = 42;
143 const int second = 13;
148 ASSERT_EQ_MSG(2, testable->
size());
149 ASSERT_EQ_MSG(first, testable->
dequeue());
151 ASSERT_EQ_MSG(1, testable->
size());
152 ASSERT_EQ_MSG(second, testable->
dequeue());
154 ASSERT_EQ_MSG(0, testable->
size());
159 TEST(Deque_multipleElements) {
162 for (
int i = 0; i < 4; ++i)
165 ASSERT_EQ_MSG(4, testable->
size());
168 ASSERT_EQ_MSG(0, testable->
peek());
170 for (
int i = 0; i < 4; ++i)
171 ASSERT_EQ_MSG(i, testable->
dequeue());
180 const size_t TEST_SIZE = SIZE * 2 + 1;
181 for (
unsigned int i = 0; i < TEST_SIZE; ++i) {
184 ASSERT_EQ_MSG(i + 1, testable->
size());
186 ASSERT_EQ_MSG(SIZE, testable->
size());
188 ASSERT_EQ_MSG(i, testable->m_array[testable->m_head]);
192 const size_t DEQUEUE_LOOP_START = TEST_SIZE - SIZE;
193 for (
unsigned int i = DEQUEUE_LOOP_START; i < TEST_SIZE; ++i) {
194 ASSERT_EQ_MSG(i, testable->
dequeue());
201 START(CircularBuffer);
203 RUN_TEST(Constructor);
204 RUN_TEST(Size_whenEmpty);
206 RUN_TEST(enqueue_firstElement);
207 RUN_TEST(Clear_whenEmpty);
208 RUN_TEST(Clear_withOneElement);
209 RUN_TEST(Peek_doesNotRemoveElement);
210 RUN_TEST(enqueue_twoElements);
211 RUN_TEST(Deque_singleElement);
212 RUN_TEST(Deque_twoElements);
213 RUN_TEST(Deque_multipleElements);
214 RUN_TEST(ManyElements);
A basic first-in, first-out queue implementation. The queue will overwrite itself when the maximum si...
T dequeue()
Return and remove the oldest value in the buffer.
Queue & enqueue(const T &value)
Insert an element to the buffer.
Queue & insert(const T &value)
bool is_empty() const
Determine if any elements exist.
size_t size() const
Obtain the number of elements in the queue.
void clear()
Remove all data from the queue.
T peek() const
Return the oldest value in the buffer without removing it from the buffer.