38# include <gtest/gtest.h>
44using namespace testing;
47constexpr size_t N = 17;
55 for (
size_t i = 0; i <
N; ++i, ++
n)
66 for (
size_t i = 0; i <
N; ++i, ++
n)
67 s.push({ int(i), 0, 1, 2, int(i) });
85 for (
size_t i = 0; i < n; ++i)
89 for (
size_t i = 0; i < m; ++i)
93 for (
size_t i = 0; i < m; ++i)
98 for (
size_t i = 0; i < m; ++i)
104 for (
size_t i = 0; i < n; ++i)
111 for (
size_t i = 0; i < n; ++i)
114 for (
size_t i = 0; i < n; ++i)
121 for (
size_t i = 0; i < m; ++i)
135 for (
size_t i = 0; i < n; ++i)
137 EXPECT_EQ(s.top(i).get_first(), n - i - 1);
138 EXPECT_EQ(s.top(i).get_last(), n - i - 1);
142 const size_t m = 100;
143 for (
size_t i = 0; i < m; ++i)
145 EXPECT_EQ(s.push({int(i), 0, 1, int(i)}).get_first(), i);
153 for (
size_t i = 0; i < m; ++i)
164 for (
size_t i = 0; i < m; ++i)
176 for (
size_t i = 0; i < n; ++i)
188 auto &
ll = s.pushn(n);
192 for (
size_t i = 0; i < n; ++i)
193 s.top(i) = {
int(i), 0, 1,
int(i) };
195 for (
size_t i = 0; i < n; ++i)
214 for (
size_t i = 0; i < m; ++i)
240 auto it = s.get_it();
241 for (
size_t i = 0; it.has_curr(); it.next(), ++i)
245 for (
size_t i = 0; it.has_curr(); it.prev(), ++i)
251 auto it = s.get_it();
252 for (
size_t i = 0; it.has_curr(); it.next(), ++i)
261 for (
size_t i = 0; it.has_curr(); it.prev(), ++i)
263 EXPECT_EQ(it.get_curr().get_first(), n - i -1);
264 EXPECT_EQ(it.get_curr().get_last(), n - i -1);
277 for (; i <
sc.
size(); ++i)
288 for (; i <
sc.
size(); ++i)
300 for (; i <
sc.
size(); ++i)
309 for (; i < s.size(); ++i)
321 for (; i <
sc.
size(); ++i)
332 for (; i <
sc.
size(); ++i)
344 for (; i <
sc.
size(); ++i)
358 for (; i < s.size(); ++i)
360 EXPECT_EQ(s.top(i).get_first(), n - i - 1);
361 EXPECT_EQ(s.top(i).get_last(), n - i - 1);
Functional programming utilities for Aleph-w containers.
TEST_F(SimpleStack, push_pop)
Stack implemented with simple dynamic array and with bounds verification.
T & top() const
Return a modifiable reference to youngest element of stack (called the top)
bool is_empty() const noexcept
Return true if stack is empty.
size_t size() const noexcept
Return the number of elements stored in the stack.
T & push(const T &data)
Push into stack a copy of data
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.
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.
Type & nth(const size_t n)
Return the n-th item of container.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
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.
bool traverse(Node *root, Op op)
DynList< T > maps(const C &c, Op op)
Classic map operation.
Fixture with a stack of complex objects (DynList<int>)
ArrayStack< DynList< int > > s
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Fixture with a stack of integers.
Stack implementations backed by dynamic or fixed arrays.