42# include <gtest/gtest.h>
54using namespace testing;
67 static constexpr size_t N = 100;
71 for (
size_t i = 0; i <
N; ++i)
95 while (!queue_with_items.is_empty())
106 for (
int i = 0; i < 10; ++i)
116 for (
int i = 0; i < 10; ++i)
131 std::vector<int>
vec = {10, 20, 30, 40, 50};
147 while (!q.
is_empty() && it.has_curr())
163 q = queue_with_items;
185 target = std::move(source);
212 std::string value =
"hello";
214 std::string&
ref = q.
put(std::move(value));
239 for (
int i = 0; i < 10; ++i)
242 for (
int i = 0; i < 10; ++i)
277 EXPECT_EQ(queue_with_items.rear(),
static_cast<int>(
N - 1));
280 EXPECT_EQ(queue_with_items.rear(),
static_cast<int>(
N - 1));
351 queue_with_items.empty();
433 for (
auto it = q.
get_it(); it.has_curr(); it.next())
434 visited.push_back(it.get_curr());
447 for (
const auto& item : q)
472 for (
const auto& item : q)
493 bool result = queue_with_items.traverse([&
sum](
int& item) {
505 bool result = queue_with_items.traverse([&
count](
int&) {
516 bool result = empty_queue.traverse([&called](
int&) {
545 queue_with_items.for_each([&
sum](
const int& item) {
555 auto doubled = q.
maps([](
int i) {
return i * 2; });
566 auto evens = q.
filter([](
int i) {
return i % 2 == 0; });
645 auto ptr = queue_with_items.find_ptr([](
int i) {
return i == 50; });
653 auto ptr = queue_with_items.find_ptr([](
int i) {
return i == 9999; });
660 auto idx = queue_with_items.find_index([](
int i) {
return i == 50; });
667 auto [
found, value] = queue_with_items.find_item([](
int i) {
return i == 50; });
677 EXPECT_EQ(queue_with_items.nth(
N - 1),
static_cast<int>(
N - 1));
683 EXPECT_THROW(queue_with_items.nth(
N + 100), std::out_of_range);
688 auto it = queue_with_items.get_it();
695 auto it = queue_with_items.get_it(50);
707 auto keys = q.
keys();
717 auto items = q.
items();
731 static_assert(std::is_same_v<SetType, DynListQueue<int>>,
732 "Set_Type should be DynListQueue<int>");
733 static_assert(std::is_same_v<ItemType, int>,
734 "Item_Type should be int");
759 q.
put(std::make_unique<int>(1));
760 q.
put(std::make_unique<int>(2));
761 q.
put(std::make_unique<int>(3));
810 throw std::runtime_error(
"Too many constructions");
816 throw std::runtime_error(
"Too many constructions");
832 for (
int i = 0; i < 50; ++i)
844 constexpr size_t LARGE_N = 100000;
847 for (
size_t i = 0; i <
LARGE_N; ++i)
848 q.
put(
static_cast<int>(i));
854 for (
size_t i = 0; i <
LARGE_N; ++i)
871 for (
int i = 0; i < 3; ++i)
875 for (
int i = 0; i < 2; ++i)
900 for (
int i = 0; i < 100; ++i)
934 for (
int i = 0; i < 100; ++i)
962 for (
int i = -100; i <= 100; ++i)
965 for (
int i = -100; i <= 100; ++i)
989 static_assert(
noexcept(q1.
swap(
q2)),
"swap should be noexcept");
995 static_assert(
noexcept(q.
size()),
"size should be noexcept");
1001 static_assert(
noexcept(q.
is_empty()),
"is_empty should be noexcept");
1007 static_assert(
noexcept(q.
empty()),
"empty should be noexcept");
1012 static_assert(std::is_nothrow_move_constructible_v<DynListQueue<int>>,
1013 "Move constructor should be noexcept");
1018 static_assert(std::is_nothrow_move_assignable_v<DynListQueue<int>>,
1019 "Move assignment should be noexcept");
1107 static_assert(
noexcept(q.
clear()),
"clear should be noexcept");
1121 for (
int i = 0; i < 1000; ++i)
1134 for (
int i = 0; i < 1000; ++i)
1142 for (
int i = 0; i < 100; ++i)
1203 bool eq = (q1 ==
q2);
1204 bool neq = (q1 !=
q2);
1214 bool eq = (q1 ==
q2);
1215 bool neq = (q1 !=
q2);
1225 bool eq = (q1 ==
q2);
1226 bool neq = (q1 !=
q2);
1236 bool eq = (q1 ==
q2);
1237 bool neq = (q1 !=
q2);
1248 bool neq = (q != q);
1315 const int* ptr = q.
search(3);
1336 ::testing::InitGoogleTest(&
argc,
argv);
Zip iterators and functional operations for multiple containers.
Functional programming utilities for Aleph-w containers.
Dynamic queue of elements of generic type T based on single linked list.
T & put(const T &data)
The type of element.
constexpr size_t size() const noexcept
Return the number of elements.
T get()
Remove the oldest item of the queue.
void swap(DynListQueue &__q) noexcept
Swap this with __q in constant time.
void empty() noexcept
Empty the queue.
T & front()
Return a modifiable reference to the oldest item in the queue.
void clear() noexcept
Alias for empty() - clears all items from the queue.
T pop()
Alias for get() - removes and returns the front item.
T & insert(const T &data)
T & append(const T &data)
T & emplace(Args &&... args)
Construct an item in place at the rear of the queue.
T Item_Type
The type of set.
T & rear()
Return a modifiable reference to the youngest item in the queue.
T * search(const T &key) noexcept
Search for an item in the queue using equality comparison.
bool is_empty() const noexcept
Return true if this is empty.
T & get_curr() const
Return the current item.
Dynamic singly linked list with functional programming support.
T & get_last() const
Return the last item of the list.
T & get_first() const
Return the first item of the list.
void next()
Move the iterator one item forward.
bool has_curr() const noexcept
Return true if iterator has current item.
size_t size() const noexcept
Count the number of elements of the list.
DynListQueue< int > queue_with_items
DynListQueue< int > empty_queue
static constexpr size_t N
__T foldl(const __T &init, Op &op) const
Fold the elements of the container to a specific result.
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criteria.
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &op) const
Exclusive partition of container according to a filter criteria.
Aleph::DynList< T > take(const size_t n) const
Return a list with the first n elements seen in the container during its traversal.
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criteria.
bool all(Operation &operation) const
Check if all the elements of container satisfy a condition.
Aleph::DynList< T > rev() const
Return a list with the elements of container in reverse order respect to its traversal order.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Aleph::DynList< T > drop(const size_t n) const
Drop the first n elements seen in the container during its traversal.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
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.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
T product(const Container &container, const T &init=T{1})
Compute product of all elements.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Iterator on elements of a queue.
Aleph::DynList< T > keys() const
Aleph::DynList< T > items() const
Return a list of all the elements of a container sorted by traversal order.
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
NonCopyable & operator=(const NonCopyable &)=delete
NonCopyable(const NonCopyable &)=delete
NonCopyable(NonCopyable &&other) noexcept
NonCopyable & operator=(NonCopyable &&other) noexcept
ThrowingType(const ThrowingType &other)
static int construction_count
ThrowingType(ThrowingType &&other) noexcept
Dynamic queue implementation based on linked lists.
TEST_F(DynListQueueTest, DefaultConstruction)