38 #include <gtest/gtest.h>
44 TEST(CircularQueueTest, Empty)
46 const auto cq_size = 8;
50 ASSERT_EQ(cq.
size(), 0);
51 ASSERT_TRUE(cq.
empty());
56 TEST(CircularQueueTest, HeadTailEmpty)
58 const auto cq_size = 8;
69 TEST(CircularQueueTest, AddingElements)
71 const auto cq_size = 8;
74 const auto first_element = 0xAAAAAAAA;
76 ASSERT_EQ(cq.
front(), first_element);
77 ASSERT_EQ(cq.
back(), first_element);
79 const auto second_element = 0x55555555;
81 ASSERT_EQ(cq.
front(), first_element);
82 ASSERT_EQ(cq.
back(), second_element);
84 ASSERT_EQ(cq.
size(), 2);
92 TEST(CircularQueueTest, RemovingElements)
94 const auto cq_size = 8;
98 const auto first_element = 0xAAAAAAAA;
102 const auto second_element = 0x55555555;
105 auto initial_head = cq.
head();
106 auto initial_tail = cq.
tail();
110 ASSERT_EQ(cq.
head(), initial_head + 1);
111 ASSERT_EQ(cq.
tail(), initial_tail);
114 ASSERT_EQ(cq.
head(), initial_head + 2);
115 ASSERT_EQ(cq.
tail(), initial_tail);
117 ASSERT_EQ(cq.
size(), 0);
118 ASSERT_TRUE(cq.
empty());
129 const auto cq_size = 8;
132 const auto value = 0xAAAAAAAA;
133 for (
auto idx = 0; idx < cq_size; idx++) {
137 ASSERT_TRUE(cq.
full());
138 ASSERT_EQ(cq.
head(), cq.
tail() + 1);
147 TEST(CircularQueueTest, BeginEnd)
149 const auto cq_size = 8;
155 const auto first_value = 0xAAAAAAAA;
156 const auto second_value = 0x55555555;
162 ASSERT_EQ(cq.
begin() + 2, cq.
end());
170 TEST(CircularQueueTest, BeginFrontEndBack)
172 const auto cq_size = 8;
175 const auto front_value = 0xAAAAAAAA;
176 const auto back_value = 0x55555555;
182 ASSERT_EQ(*(cq.
end() - 1), cq.
back());
189 TEST(CircularQueueTest, IteratorsOp)
191 const auto cq_size = 8;
194 const auto first_value = 0xAAAAAAAA;
195 const auto second_value = 0x55555555;
199 auto negative_offset = -(cq_size + 1);
200 auto it_1 = cq.
begin();
201 auto it_2 = cq.
begin() + 1;
202 auto it_3 = cq.
begin() - negative_offset;
205 ASSERT_TRUE(it_1 != it_2);
206 ASSERT_FALSE(it_1 == it_2);
207 ASSERT_FALSE(it_1 > it_2);
208 ASSERT_FALSE(it_1 >= it_2);
209 ASSERT_TRUE(it_1 < it_2);
210 ASSERT_TRUE(it_1 <= it_2);
211 ASSERT_EQ(*it_1, first_value);
212 ASSERT_EQ(it_1 + 1, it_2);
213 ASSERT_EQ(it_1, it_2 - 1);
214 ASSERT_EQ(it_2 - it_1, 1);
215 ASSERT_EQ(it_1 - it_2, -1);
216 ASSERT_EQ(it_3._round, 1);
219 ASSERT_EQ(++temp_it, it_2);
220 ASSERT_EQ(--temp_it, it_1);
221 ASSERT_EQ(temp_it++, it_1);
222 ASSERT_EQ(temp_it, it_2);
223 ASSERT_EQ(temp_it--, it_2);
224 ASSERT_EQ(temp_it, it_1);
233 TEST(CircularQueueTest, FullLoop)
235 const auto cq_size = 8;
240 auto starting_it = cq.
begin();
241 auto ending_it = starting_it + cq_size;
243 ASSERT_EQ(starting_it._idx, ending_it._idx);
244 ASSERT_TRUE(starting_it != ending_it);
253 TEST(CircularQueueTest, MultipleRound)
255 const auto cq_size = 8;
259 auto items_added = cq_size * 3;
260 for (
auto idx = 0; idx < items_added; idx++) {
264 auto starting_it = cq.
begin();
265 auto ending_it = cq.
end();
267 ASSERT_EQ(starting_it._round + 1, ending_it._round);
268 ASSERT_EQ(ending_it - starting_it, cq_size);