38# include <gtest/gtest.h>
60using namespace testing;
66 static constexpr size_t N = 1000;
71 for (
size_t i = 0; i <
N; ++i)
88 EXPECT_TRUE(c.traverse([&
l] (
auto &
k) { l.append(k); return true; }));
90 this->item_list,
sort(
l)));
101 this->item_list,
sort(
l)));
109 auto ptr = c.find_ptr([
N] (
auto &
k) {
return k ==
int(
N); });
111 this->item_list.for_each([&c] (
auto &
k)
113 auto ptr = c.find_ptr([
k] (
auto i) {
return k == i; });
125 auto idx = c.find_index([
N] (
auto &
k) {
return k ==
int(
N); });
128 this->item_list.for_each([&c] (
auto &
k)
130 auto idx = c.find_index([
k] (
auto i) {
return k == i; });
141 auto t = c.find_item([
N] (
auto &
k) {
return k ==
int(
N); });
144 this->item_list.for_each([&c] (
auto &
k)
146 auto t = c.find_item([
k] (
auto i) {
return k == i; });
157 const std::vector<int> v = c.to_vector();
171 for (
auto & item : c)
192 auto ptr = c.find_ptr([
N] (
auto i) {
return i ==
N; });
197 c.nappend(
N + 1,
N + 2,
N + 3);
200 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 1; });
204 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 2; });
208 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 3; });
219 auto ptr = c.find_ptr([
N] (
auto i) {
return i ==
N; });
224 c.ninsert(
N + 1,
N + 2,
N + 3);
227 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 1; });
231 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 2; });
235 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 3; });
247 const bool ret = tbl.contains(i);
259 auto &
l = this->item_list;
261 { return c.exists([i] (auto k) { return i == k; }); }));
268 auto &
l = this->item_list;
269 auto fct = [] (
int i) {
return i + 1; };
271 all([] (
auto & p) {
return p.first == p.second; }));
273 { return i < 7; },
fct))),
274 sort(
l.template maps_if([] (
auto i)
275 {
return i < 7; },
fct))).
276 all([] (
auto & p) {
return p.first == p.second; }));
283 auto sum = c.foldl(0, [] (
auto & a,
auto & i) {
return a + i; });
289 auto fct = [] (
int a,
int i) {
return a + i; };
291 auto sum = c.filter([] (
auto i) {
return i < 8; }).
foldl(0,
fct);
294 auto l = c.
ptr_filter([] (
auto & i) {
return i < 8; });
295 sum =
l.
foldl(0, [] (
auto a,
auto ptr) {
return a + *ptr; });
300 auto p = c.
partition([] (
auto & i) {
return i < 8; });
301 auto S = p.first.foldl(0,
fct) + p.second.foldl(0,
fct);
304 auto t = c.tpartition([] (
auto & i) {
return i < 8; });
310 S = l1.foldl(0,
fct) + l2.foldl(0,
fct);
341 static constexpr size_t N = 10;
348 ptr_2 =
new C({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
364 auto ptr_1 = this->ptr_1;
365 auto ptr_2 = this->ptr_2;
366 auto ptr_3 = this->ptr_3;
377 const auto &
r3 =
r1;
INSTANTIATE_TYPED_TEST_SUITE_P(traverses, Container, Ctypes)
REGISTER_TYPED_TEST_SUITE_P(Container, traverse, for_each, find_ptr, find_index_nth, find_item, iterator_operations, nappend, ninsert, all, exists, maps, foldl, filter_ops)
Types< DynList< int >, DynDlist< int >, DynArray< int >, HashSet< int, ODhashTable >, HashSet< int, OLhashTable >, DynHashTable< int, LhashTable >, DynHashTable< int, LinearHashTable >, DynSetHash< int >, DynSetTree< int, Treap >, DynSetTree< int, Treap_Rk >, DynSetTree< int, Rand_Tree >, DynSetTree< int, Splay_Tree >, DynSetTree< int, Avl_Tree >, DynSetTree< int, Rb_Tree >, Array< int >, ArrayQueue< int >, ArrayStack< int >, DynListQueue< int >, DynListStack< int >, DynArrayHeap< int >, DynBinHeap< int >, FixedQueue< int >, FixedStack< int > > Ctypes
TYPED_TEST_SUITE_P(Container)
TYPED_TEST_P(Container, traverse)
String manipulation utilities.
Zip iterators and functional operations for multiple containers.
Functional programming utilities for Aleph-w containers.
High-level sorting functions for Aleph containers.
Queue implemented with a single dynamic array.
Stack implemented with simple dynamic array and with bounds verification.
Simple dynamic array with automatic resizing and functional operations.
Dynamic heap (priority queue) backed by DynArray.
Dynamic heap of elements of type T ordered by a comparison functor.
Dynamic doubly linked list with O(1) size and bidirectional access.
Self-adjusting dynamic hash table.
Dynamic queue of elements of generic type T based on single linked list.
Dynamic stack of elements of generic type T based on a singly linked list.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
T & get_last() const
Return the last item of the list.
T & get_first() const
Return the first item of the list.
Dynamic set backed by balanced binary search trees with automatic memory management.
Very simple queue implemented with a contiguous array.
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 > to_dynlist() const
Convert container to DynList.
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &op) const
Exclusive partition of container according to a filter criteria.
bool all(Operation &operation) const
Check if all the elements of container satisfy a condition.
Aleph::DynList< const T * > ptr_filter(Operation &operation) const
Filter the elements of a container according to a matching criteria and return a pointer to the match...
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
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.
MapOLhash< int, Foo > tbl
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
bool zip_all(Op &&op, const Cs &... cs)
Return true if op returns true for all tuples and containers have equal length.
DynList< typename Container::Item_Type > to_dynlist(const Container &c)
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
bool traverse(Node *root, Op op)
DynList< std::pair< typename Container1::Item_Type, typename Container2::Item_Type > > zip(const Container1 &a, const Container2 &b)
Zip two containers into a list of pairs.
T foldl(const Container &container, const T &init, Operation operation)
Classic left fold (reduce).
bool exists(Container &container, Operation &operation)
Return true if at least one element satisfies a predicate.
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
Container::Item_Type * find_ptr(Container &container, Pred &pred)
Find the first element satisfying pred.
DynList< T > maps(const C &c, Op op)
Classic map operation.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
static constexpr size_t N
static constexpr size_t N
Fixed-capacity binary heap and heapsort algorithms.
Circular queue implementations backed by arrays.
Array-based dynamic binary heap.
Lazy and scalable dynamic array implementation.
Dynamic binary heap with node-based storage.
Dynamic doubly linked list implementation.
Dynamic stack implementation based on linked lists.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.
Unified hash table interface.
Random access queue (bag) with O(1) random pop.