48# include <gtest/gtest.h>
60using namespace testing;
67constexpr size_t N = 17;
78 for (
size_t i = 0; i <
N; ++i, ++
n)
91 for (
size_t i = 0; i <
N; ++i, ++
n)
92 s.push({ int(i), 0, 1, 2, int(i) });
120 other.moved_from =
true;
125 other.moved_from =
true;
259 for (
size_t i = 0; i < n; ++i)
444 string value =
"test";
456 string value =
"test";
458 s.
push(std::move(value));
482 for (
int i = 0; i < 10; ++i)
485 for (
int i = 9; i >= 0; --i)
775 int* ptr = s.search(5);
783 int* ptr = s.search(999);
799 const int* ptr =
cs.search(5);
807 string* ptr = s.search(
"second");
861 auto it = s.get_it();
863 for (
size_t i = 0; it.has_curr(); it.next(), ++i)
864 ASSERT_EQ(it.get_curr(),
int(n - i - 1));
870 for (
auto it = s.get_it(); it.has_curr(); it.next())
878 vector<int> elements;
880 for (
const auto& item : s)
881 elements.push_back(item);
884 for (
size_t i = 0; i < n; ++i)
892 for (
size_t i = 0; it.has_curr(); it.next(), ++i)
894 const auto& list = it.get_curr();
895 ASSERT_EQ(list.get_first(),
int(n - i - 1));
896 ASSERT_EQ(list.get_last(),
int(n - i - 1));
907 bool result = s.traverse([&
count](
int) { ++
count;
return true; });
916 bool result = s.traverse([&
count](
int)
929 s.traverse([&i,
this](
int value)
942 bool result = s.
traverse([&called](
int) { called =
true;
return true; });
964 auto doubled = s.
maps([](
int x) {
return x * 2; });
969 for (
size_t i = 0; it.has_curr(); it.next(), ++i)
970 EXPECT_EQ(it.get_curr(),
int((n - i - 1) * 2));
986 auto evens = s.
filter([](
int x) {
return x % 2 == 0; });
988 for (
auto it =
evens.
get_it(); it.has_curr(); it.next())
994 auto result = s.
filter([](
int x) {
return x > 1000; });
1001 int sum = s.foldl(0, [](
int acc,
int x) {
return acc + x; });
1019 bool result = s.all([](
int x) {
return x >= 0; });
1025 bool result = s.all([](
int x) {
return x < 10; });
1031 bool result = s.exists([](
int x) {
return x == 5; });
1037 bool result = s.exists([](
int x) {
return x == 999; });
1044 s.for_each([&
sum](
int x) {
sum += x; });
1073 for (
int i = 0; i < 100; ++i)
1086 for (
int i = 0; i < 50; ++i)
1120 s.
push(std::move(c));
1149 for (
int i = 0; i < 100; ++i)
1154 for (
int i = 99; i >= 0; --i)
1186 for (
size_t i = 0; i <
LARGE_N; ++i)
1191 for (
size_t i = 0; i <
LARGE_N; ++i)
1201 for (
size_t i = 0; i < 1000; ++i)
1206 for (
size_t i = 999; i !=
size_t(-1); --i)
1214 for (
size_t i = 0; i <
LARGE_N; ++i)
1224 auto it2 =
copy.get_it();
1225 while (it1.has_curr() && it2.has_curr())
1227 ASSERT_EQ(it1.get_curr(), it2.get_curr());
1246 throw runtime_error(
"Copy failed");
1283 [](
int acc,
int x) {
return std::max(
acc, x); });
1289 [](
int acc,
int x) {
return std::min(
acc, x); });
1314 for (
auto it = s.
get_it(); it.has_curr(); it.next())
1322 for (
auto it = s.
get_it(); it.has_curr(); it.next())
1334 ::testing::InitGoogleTest(&
argc,
argv);
Functional programming utilities for Aleph-w containers.
T & push(const T &data)
Push into stack a copy of data
Dynamic stack of elements of generic type T based on a singly linked list.
T & append(const T &data)
Alias for push() - required by Special_Ctors macro.
void clear() noexcept
Alias for empty() - removes all elements.
T & top()
Return a modifiable reference to the top item of the stack.
bool is_empty() const noexcept
Check if the stack is empty.
constexpr size_t size() const noexcept
Return the number of elements in the stack.
T & emplace(Args &&... args)
Construct an item in place at the top of the stack.
void swap(DynListStack &other) noexcept
Swap the contents of this stack with another.
T * search(const T &key) noexcept
Search for an item in the stack using equality comparison.
T get()
Alias for pop() - removes and returns the top item.
bool traverse(Operation &operation)
Traverse all elements from top to bottom.
bool contains(const T &key) const noexcept
Check if the stack contains a specific value.
T & put(const T &data)
Alias for push() - for compatibility with queue-like interfaces.
T & insert(const T &data)
Alias for push() - for STL-like insert semantics.
T pop()
Remove and return the top item of the stack.
T & push(const T &data)
Push an item by copy onto the top of the stack.
void empty() noexcept
Remove all elements from the stack.
T & get_first() const
Return the first item of the list.
DynList & swap(DynList &l) noexcept
Swap this with l.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
__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.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
TEST_F(SimpleStack, copy_constructor_creates_independent_copy)
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
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.
Fixture with a stack of complex objects (DynList<int>)
ArrayStack< DynList< int > > s
Type that counts constructions/destructions.
Counted & operator=(Counted &&other) noexcept
Counted & operator=(const Counted &other)
Counted(Counted &&other) noexcept
bool operator==(const Counted &other) const
Counted(const Counted &other)
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Move-only type for testing move semantics.
bool operator==(const MoveOnly &other) const
MoveOnly(MoveOnly &&other) noexcept
MoveOnly & operator=(const MoveOnly &)=delete
MoveOnly & operator=(MoveOnly &&other) noexcept
MoveOnly(const MoveOnly &)=delete
Fixture with a stack of integers.
Fixture with a stack of strings.
ThrowOnCopy(const ThrowOnCopy &other)
ThrowOnCopy & operator=(ThrowOnCopy &&)=default
ThrowOnCopy(ThrowOnCopy &&)=default
ThrowOnCopy & operator=(const ThrowOnCopy &)=default
Dynamic stack implementation based on linked lists.