38# include <gtest/gtest.h>
45using namespace testing;
48constexpr size_t N = 17;
56 for (
size_t i = 0; i <
N; ++i, ++
n)
67 for (
size_t i = 0; i <
N; ++i, ++
n)
68 q.put({ int(i), 0, 1, 2, int(i) });
76 EXPECT_EQ(q.
size(), 0);
77 EXPECT_THROW(q.
front(), underflow_error);
78 EXPECT_THROW(q.
rear(), underflow_error);
83 EXPECT_FALSE(q.is_empty());
84 EXPECT_EQ(q.size(), n);
85 EXPECT_EQ(q.front(), 0);
86 EXPECT_EQ(q.rear(), n - 1);
89 for (
size_t i = 0; i <
m; ++i)
90 ASSERT_EQ(q.put(i), i);
91 EXPECT_EQ(q.size(), n +
m);
93 for (
size_t i = 0; i < n; ++i)
94 ASSERT_EQ(q.get(), i);
96 EXPECT_EQ(q.rear(),
m - 1);
97 EXPECT_EQ(q.front(), 0);
98 EXPECT_EQ(q.size(),
m);
100 for (
size_t i = 0; i <
m; ++i)
101 ASSERT_EQ(q.get(), i);
103 EXPECT_TRUE(q.is_empty());
104 EXPECT_EQ(q.size(), 0);
106 for (
size_t i = 0; i <
m; ++i)
107 EXPECT_EQ(q.put(i), i);
108 EXPECT_EQ(q.size(),
m);
111 EXPECT_TRUE(q.is_empty());
112 EXPECT_EQ(q.size(), 0);
117 EXPECT_FALSE(q.is_empty());
118 EXPECT_EQ(q.size(), n);
119 EXPECT_EQ(q.rear().get_first(), n - 1);
120 EXPECT_EQ(q.front().get_first(), 0);
122 const size_t m = 100;
123 for (
size_t i = 0; i <
m; ++i)
125 ASSERT_EQ(q.put({int(i), 0, 1, int(i)}).get_first(), i);
126 ASSERT_EQ(q.rear().get_first(), i);
127 ASSERT_EQ(q.rear().get_last(), i);
128 ASSERT_EQ(q.rear().nth(1), 0);
129 ASSERT_EQ(q.rear().nth(2), 1);
131 EXPECT_EQ(q.size(), n +
m);
133 for (
size_t i = 0; i < n; ++i)
138 ASSERT_EQ(
l.
nth(1), 0);
139 ASSERT_EQ(
l.
nth(2), 1);
142 EXPECT_EQ(q.rear().get_first(),
m - 1);
143 EXPECT_EQ(q.rear().get_last(),
m - 1);
144 EXPECT_EQ(q.front().get_first(), 0);
145 EXPECT_EQ(q.front().get_last(), 0);
146 EXPECT_EQ(q.size(),
m);
148 for (
size_t i = 0; i <
m; ++i)
153 ASSERT_EQ(
l.
nth(1), 0);
154 ASSERT_EQ(
l.
nth(2), 1);
156 EXPECT_EQ(q.size(), 0);
157 EXPECT_TRUE(q.is_empty());
159 for (
size_t i = 0; i <
m; ++i)
161 auto &
l = q.
put({ int(i), 0, 1, int(i) });
164 EXPECT_EQ(
l.
nth(1), 0);
165 EXPECT_EQ(
l.
nth(2), 1);
167 EXPECT_EQ(q.size(),
m);
170 EXPECT_TRUE(q.is_empty());
171 EXPECT_EQ(q.size(), 0);
178 EXPECT_FALSE(it.has_curr());
179 EXPECT_THROW(it.get_curr(), overflow_error);
180 EXPECT_THROW(it.next(), overflow_error);
185 auto it = q.get_it();
186 for (
size_t i = 0; it.has_curr(); it.next(), ++i)
187 ASSERT_EQ(it.get_curr(), i);
192 auto it = q.get_it();
193 for (
size_t i = 0; it.has_curr(); it.next(), ++i)
195 ASSERT_EQ(it.get_curr().get_first(), i);
196 ASSERT_EQ(it.get_curr().get_last(), i);
197 ASSERT_EQ(it.get_curr().nth(1), 0);
198 ASSERT_EQ(it.get_curr().nth(2), 1);
207 EXPECT_EQ(qc.
size(), n);
208 EXPECT_EQ(q.size(), qc.
size());
211 ASSERT_EQ(qc.
get(), i);
219 EXPECT_EQ(q.size(), qc.
size());
222 ASSERT_EQ(qc.
get(), i);
223 EXPECT_EQ(i, q.size());
229 EXPECT_EQ(qc.
size(), n);
230 EXPECT_EQ(q.size(), 0);
231 EXPECT_TRUE(q.is_empty());
236 ASSERT_EQ(q.rear(), i);
237 ASSERT_EQ(q.front(), 0);
241 EXPECT_EQ(q.size(), n);
246 EXPECT_EQ(qc.
size(), n);
247 EXPECT_TRUE(q.is_empty());
252 ASSERT_EQ(q.rear(), i);
253 ASSERT_EQ(q.front(), 0);
256 EXPECT_EQ(q.size(), n);
265 EXPECT_EQ(q.size(), qc.
size());
266 EXPECT_TRUE(
eq(q.front(), qc.
front()));
267 EXPECT_TRUE(
eq(q.rear(), qc.
rear()));
274 EXPECT_EQ(q.size(), qc.
size());
275 EXPECT_TRUE(
eq(q.rear(), qc.
rear()));
276 EXPECT_TRUE(
eq(q.front(), qc.
front()));
282 EXPECT_EQ(qc.
size(), n);
283 EXPECT_EQ(q.size(), 0);
284 EXPECT_TRUE(q.is_empty());
287 for (
auto it = qc.
get_it(); it.has_curr(); it.next(), ++
k)
289 auto &
l = it.get_curr();
292 ASSERT_EQ(
l.
nth(1), 0);
293 ASSERT_EQ(
l.
nth(2), 1);
296 EXPECT_EQ(qc.
rear().get_first(), n - 1);
297 EXPECT_EQ(qc.
rear().get_last(), n - 1);
298 EXPECT_EQ(qc.
rear().nth(1), 0);
299 EXPECT_EQ(qc.
rear().nth(2), 1);
302 EXPECT_FALSE(q.is_empty());
303 EXPECT_EQ(q.size(), n);
307 for (
auto it = qc.
get_it(); it.has_curr(); it.next(), ++
k)
309 auto &
l = it.get_curr();
312 ASSERT_EQ(
l.
nth(1), 0);
313 ASSERT_EQ(
l.
nth(2), 1);
316 EXPECT_EQ(q.rear().get_first(), n - 1);
317 EXPECT_EQ(q.rear().get_last(), n - 1);
318 EXPECT_EQ(q.rear().nth(1), 0);
319 EXPECT_EQ(q.rear().nth(2), 1);
325 bool ret = q.traverse([&i] (
int k) {
return (
k == i++); });
352 static inline bool fail =
false;
353 static inline int moves = 0;
356 Fragile_Move(
int v = 0) noexcept : value(v) {}
357 Fragile_Move(
const Fragile_Move &) =
default;
358 Fragile_Move(Fragile_Move && c) :
value(c.
value)
362 throw std::runtime_error(
"move failed");
364 Fragile_Move & operator = (
const Fragile_Move &) =
default;
365 Fragile_Move & operator = (Fragile_Move &&) =
default;
374 for (
int i = 1; i <= 3; ++i)
375 queue.
put(Fragile_Move(i));
377 Fragile_Move::fail =
true;
378 EXPECT_THROW((
void) queue.
get(), std::runtime_error);
379 EXPECT_THROW((
void) queue.
pop(), std::runtime_error);
380 Fragile_Move::fail =
false;
382 ASSERT_EQ(queue.
size(), 3u);
383 EXPECT_EQ(queue.
front().value, 1);
384 Fragile_Move::moves = 0;
385 EXPECT_EQ(queue.
get().value, 1);
386 EXPECT_EQ(Fragile_Move::moves, 1);
387 EXPECT_EQ(queue.
size(), 2u);
390 EXPECT_THROW((
void) empty.
get(), std::underflow_error);
391 EXPECT_EQ(empty.
size(), 0u);
400 for (
int i = 1; i <= 3; ++i)
405 EXPECT_EQ(it.
del(), 2);
406 EXPECT_EQ(q.
size(), 2u);
407 EXPECT_EQ(q.
get(), 1);
408 EXPECT_EQ(q.
get(), 3);
409 EXPECT_EQ(q.
size(), 0u);
Functional programming utilities for Aleph-w containers.
size_t size_t int32_t value
T & put(const T &item)
Copy and put an item in the queue.
Dynamic queue of elements of generic type T based on single linked list.
T & put(const T &data)
The type of element.
T get()
Remove the oldest item of the queue.
T & front()
Return a modifiable reference to the oldest item in the queue.
T pop()
Alias for get() - removes and returns the front item.
size_t size() const noexcept
Return the number of elements.
T & rear()
Return a modifiable reference to the youngest item in the queue.
bool is_empty() const noexcept
Return true if this is empty.
T del()
Remove the current item of the iterator.
Doubly-linked list (defined in tpl_dynList.H).
T & get_first()
Return the first item of the list.
T & get_last()
Return the last item of the list.
T & put(const T &item)
See insert(const T & item).
Number Theoretic Transform over Z / MOD Z.
Type & nth(const size_t n)
Return the n-th item of the container.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
TEST_F(SimpleQueue, get_put)
bool traverse(Node *root, Op op)
See infix_traverse().
Main namespace for Aleph-w library functions.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
and
Check uniqueness with explicit hash + equality functors.
Iterator on elements of a queue.
ArrayQueue< DynList< int > > q
DynListQueue< DynList< int > > q
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Dynamic queue implementation based on linked lists.