38# include <gtest/gtest.h>
47using namespace testing;
57 for (
size_t i = 0; i < 25; ++i, ++
n)
92 EXPECT_EQ(list.
size(), 3);
96 EXPECT_EQ(list.
size(), 2);
100 EXPECT_EQ(list.
size(), 1);
108 EXPECT_EQ(list.
size(), 0);
110 EXPECT_THROW(list.
rotate_left(1), std::domain_error);
121 EXPECT_EQ(list.
size(), 3);
125 EXPECT_EQ(list.
size(), 0);
129 EXPECT_EQ(list.
size(), 1);
143 EXPECT_TRUE(
l1 ==
l2);
144 EXPECT_FALSE(
l1 !=
l2);
146 EXPECT_FALSE(
l1 ==
l3);
147 EXPECT_TRUE(
l1 !=
l3);
149 EXPECT_FALSE(
l1 == l4);
150 EXPECT_TRUE(
l1 != l4);
153 EXPECT_TRUE(empty1 == empty2);
160 list.
append(std::move(laux));
166 list.
insert(std::move(laux));
168 EXPECT_EQ(list.
size(), 2);
173TEST(DynListAlgorithms, InPlaceUnique)
184 ASSERT_EQ(list.
size(), 3u);
186 ASSERT_TRUE(it.has_curr()); EXPECT_EQ(it.get_curr(), 3); it.next();
187 ASSERT_TRUE(it.has_curr()); EXPECT_EQ(it.get_curr(), 1); it.next();
188 ASSERT_TRUE(it.has_curr()); EXPECT_EQ(it.get_curr(), 2); it.next();
189 EXPECT_FALSE(it.has_curr());
195 EXPECT_EQ(empty_list.
size(), 0u);
196 EXPECT_FALSE(empty_list.
get_it().has_curr());
203 EXPECT_EQ(single_list.
size(), 1u);
213 EXPECT_EQ(all_equal.
size(), 1u);
220 EXPECT_EQ(list.get_first(), 1);
221 EXPECT_EQ(list.get_last(), 25);
222 EXPECT_EQ(list.size(), 25);
223 EXPECT_FALSE(list.is_empty());
224 EXPECT_FALSE(list.is_unitarian());
225 EXPECT_FALSE(list.is_unitarian_or_empty());
231 for (
auto it = list.get_it(); it.has_curr(); it.next(), ++i)
233 EXPECT_EQ(it.get_curr(), i);
234 EXPECT_EQ(it.get_pos(), i - 1);
243 EXPECT_TRUE(list.is_empty());
244 EXPECT_EQ(
l.
size(), 13);
245 EXPECT_EQ(
r.size(), 12);
248 EXPECT_EQ(
r.get_first(), 14);
249 EXPECT_EQ(
r.get_last(), 25);
252 for (
auto it =
l.
get_it(); it.has_curr(); it.next(), ++i)
253 EXPECT_EQ(it.get_curr(), i);
255 for (
auto it =
r.get_it(); it.has_curr(); it.
next(), ++i)
256 EXPECT_EQ(it.get_curr(), i);
261 for (
auto it =
l.
get_it(); it.has_curr(); it.next(), ++i)
262 EXPECT_EQ(it.get_curr(), i);
270 EXPECT_TRUE(list.is_empty());
271 EXPECT_EQ(list.size(), 0);
275 for (
auto it = laux.
get_it(); it.has_curr(); it.next(), ++i)
276 EXPECT_EQ(it.get_curr(), i);
283 for (
auto it = list.get_it(); it.has_curr(); it.next(), --i)
284 EXPECT_EQ(it.get_curr(), i);
289 for (
auto it = list.get_it(); it.has_curr(); it.next(), ++i)
290 EXPECT_EQ(it.get_curr(), i);
295 EXPECT_TRUE(
eq(list_cpy.
rev(), rlist));
296 EXPECT_TRUE(
eq(rlist_cpy.
rev(), list));
301 EXPECT_TRUE(list.is_empty());
311 EXPECT_EQ(it.get_curr()->to_data<
int>(), i);
320 auto it = list.get_it();
321 for (
int i = 0, n = 4; i < 3; ++i, ++n, it.next())
322 EXPECT_EQ(it.get_curr(), n);
325 list.rotate_left(22);
327 for (
auto it = list.get_it(); it.has_curr(); it.next(), ++i)
328 EXPECT_EQ(it.get_curr(), i);
333 DynList<int> ll = { 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 };
334 DynList<int> lg = { 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 };
338 list.
insert(std::move(ll));
339 list.append(std::move(lg));
345 for (
auto it = list.get_it(); it.has_curr(); it.next(), ++i)
346 EXPECT_EQ(it.get_curr(), i);
353 auto ret =
m.
traverse([&n] (
int) { ++n;
return true; });
360 EXPECT_TRUE(list.size() > 0);
361 EXPECT_EQ(list.size(), n);
363 auto ret = list.traverse([&
N,
this] (
int i) { ++
N;
return i < n/2; });
368TEST(DynListFunctional, ToArrayHelperPreservesOrder)
374 EXPECT_EQ(arr.size(), 0u);
382 ASSERT_EQ(arr.size(), 1u);
383 EXPECT_EQ(arr(0), 42);
388 for (
int v : {5, 8, 13})
393 ASSERT_EQ(arr.size(), list.
size());
395 for (
auto it = list.
get_it(); it.has_curr(); it.next(), ++i)
396 EXPECT_EQ(arr(i), it.get_curr());
405 static inline int alive = 0;
406 static inline int copies_left = -1;
409 Counted_Copy(
const int v = 0) :
value(v) { ++alive; }
411 Counted_Copy(
const Counted_Copy & other) :
value(other.
value)
413 if (copies_left == 0)
414 throw std::runtime_error(
"the copy of an item");
420 Counted_Copy & operator = (
const Counted_Copy &) =
default;
422 ~Counted_Copy() { --alive; }
432 const std::vector<Counted_Copy> items = {1, 2, 3, 4, 5};
433 const int before = Counted_Copy::alive;
434 for (
int k = 0;
k < 5; ++
k)
436 Counted_Copy::copies_left =
k;
438 EXPECT_EQ(Counted_Copy::alive, before) <<
"the copy, at the item " <<
k;
440 Counted_Copy::copies_left =
k;
443 EXPECT_EQ(Counted_Copy::alive, before) <<
"the range, at the item " <<
k;
445 Counted_Copy::copies_left =
k;
448 EXPECT_EQ(Counted_Copy::alive, before) <<
"the initializer list, at the item " <<
k;
452 Counted_Copy::copies_left = 5;
454 EXPECT_EQ(
copy.size(), 5u);
455 EXPECT_EQ(
copy.get_last().value, 5);
456 Counted_Copy::copies_left = -1;
Conversion utilities between Aleph-w and STL container types.
Deduplicate sequential Aleph containers in-place.
size_t size_t int32_t value
Doubly-linked list (defined in tpl_dynList.H).
T & get_first()
Return the first item of the list.
T & append(const T &item)
T & insert(const T &item)
T & get_last()
Return the last item of the list.
void clear() noexcept
Empties the container.
T remove_first()
See remove().
size_t size() const noexcept
Return the number of items of the list, in constant time.
DynList & reverse() noexcept
DynList & swap(DynList &l) noexcept
std::uint32_t next() noexcept
bool has_curr() const noexcept
constexpr bool is_empty() const noexcept
void rotate_left(size_t n)
Rotate to left the list n positions.
bool is_unitarian() const noexcept
Return true if the list contains exactly just one.
bool is_unitarian_or_empty() const noexcept
Return true if list contains one element or is empty.
Number Theoretic Transform over Z / MOD Z.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
bool contains(const Type &item) const
Test if an item is present in the container using equality.
TEST_F(List_of_25_items, Basic_operations)
bool traverse(Node *root, Op op)
See infix_traverse().
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
Array< typename C::Item_Type > to_array(const C &c)
Convenience wrapper identical to to_Array (copy contents).
void in_place_unique(Container &c, Compare cmp={})
Remove duplicates in-place preserving first occurrence order.
void reverse(Itor beg, Itor end)
Reverse elements in a range.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
T & swap(T &t1, T &t2)
Generic swap using object's swap method.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
void rotate_left(T *ptr, const size_t n, size_t m) noexcept
Rotate array elements left by m positions.
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation, typename Aleph::concepts_detail::traverse_arg< Container, Operation >::type, Container & >())
Traverse the container via its iterator and performs a conditioned operation on each item.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)