38# include <gtest/gtest.h>
76constexpr auto my_less = [](
const int & a,
const int & b) {
return a < b; };
80using BoolBinFn = bool (*)(
const int &,
const int &);
140 template <
template <
class>
class F,
class T>
141 constexpr bool nothrow2 =
noexcept(
F<T>()(std::declval<const T &>(),
142 std::declval<const T &>()));
144 template <
template <
class>
class F,
class T>
145 constexpr bool nothrow1 =
noexcept(
F<T>()(std::declval<const T &>()));
150static_assert(nothrow2<Aleph::plus, int>
and nothrow2<Aleph::minus, int>
151 and nothrow2<Aleph::multiplies, int>
and nothrow2<Aleph::divides, int>
152 and nothrow2<Aleph::modulus, int>
and nothrow1<Aleph::negate, int>
153 and nothrow2<Aleph::equal_to, int>
and nothrow2<Aleph::not_equal_to, int>
154 and nothrow2<Aleph::greater, int>
and nothrow2<Aleph::less, int>
155 and nothrow2<Aleph::greater_equal, int>
and nothrow2<Aleph::less_equal, int>
156 and nothrow2<Aleph::logical_and, int>
and nothrow2<Aleph::logical_or, int>
157 and nothrow1<Aleph::logical_not, int>);
158static_assert(not nothrow2<Aleph::plus, std::string>);
159static_assert(not nothrow2<Aleph::plus, Throwing_Ops>
and not nothrow2<Aleph::minus, Throwing_Ops>
160 and not nothrow2<Aleph::multiplies, Throwing_Ops>
161 and not nothrow2<Aleph::divides, Throwing_Ops>
162 and not nothrow2<Aleph::modulus, Throwing_Ops>
163 and not nothrow1<Aleph::negate, Throwing_Ops>
164 and not nothrow2<Aleph::equal_to, Throwing_Ops>
165 and not nothrow2<Aleph::not_equal_to, Throwing_Ops>
166 and not nothrow2<Aleph::greater, Throwing_Ops>
167 and not nothrow2<Aleph::less, Throwing_Ops>
168 and not nothrow2<Aleph::greater_equal, Throwing_Ops>
169 and not nothrow2<Aleph::less_equal, Throwing_Ops>
170 and not nothrow2<Aleph::logical_and, Throwing_Ops>
171 and not nothrow2<Aleph::logical_or, Throwing_Ops>
172 and not nothrow1<Aleph::logical_not, Throwing_Ops>);
175static_assert(not nothrow2<Aleph::greater, Bare>
and not nothrow2<Aleph::plus, Bare>);
186TEST(AhConceptsTest, AvlTreeInstantiates)
191 EXPECT_NE(tree.
search(42),
nullptr);
195TEST(AhConceptsTest, ODhashTableInstantiates)
198 EXPECT_EQ(table.
search(42),
nullptr);
200 EXPECT_NE(table.
search(42),
nullptr);
201 EXPECT_NO_THROW(table.
remove(42));
202 EXPECT_EQ(table.
search(42),
nullptr);
226TEST(AlephFillTest, FillDynList)
231 lst.
for_each([](
int v) { EXPECT_EQ(v, 0); });
232 EXPECT_EQ(lst.
size(), 5u);
238 for (
int i = 0; i < 5; ++i) arr.
append(i);
241 for (
size_t i = 0; i < arr.
size(); ++i)
242 EXPECT_EQ(arr[i], 7);
243 EXPECT_EQ(arr.
size(), 5u);
246TEST(AlephFillTest, FillDynDlist)
249 for (
int i = 0; i < 4; ++i) lst.
append(
static_cast<double>(i));
252 lst.
for_each([](
double v) { EXPECT_DOUBLE_EQ(v, 3.14); });
255TEST(AlephFillTest, FillDynArray)
258 for (
int i = 0; i < 6; ++i) arr.
append(i);
261 arr.
for_each([](
int v) { EXPECT_EQ(v, -1); });
262 EXPECT_EQ(arr.
size(), 6u);
265TEST(AlephFillTest, FillEmptyContainerIsNoOp)
268 EXPECT_NO_THROW(
fill(lst, 42));
272TEST(AlephFillTest, FillDoesNotChangeSize)
274 auto lst =
rep(8, 0);
276 EXPECT_EQ(lst.size(), 8u);
283TEST(AlephIotaTest, IotaDynList)
285 auto lst =
rep(5, 0);
295 for (
int i = 0; i < 5; ++i) arr.
append(0);
298 for (
size_t i = 0; i < arr.
size(); ++i)
299 EXPECT_EQ(arr[i],
static_cast<int>(10 + i));
302TEST(AlephIotaTest, IotaDynArray)
305 for (
int i = 0; i < 4; ++i) arr.
append(0);
312TEST(AlephIotaTest, IotaDynDlist)
315 for (
int i = 0; i < 3; ++i) lst.
append(0);
322TEST(AlephIotaTest, IotaEmptyIsNoOp)
325 EXPECT_NO_THROW(
iota(lst, 0));
333TEST(AlephIotaStepTest, EvenNumbers)
335 auto lst =
rep(5, 0);
345TEST(AlephIotaStepTest, DoubleStep)
348 for (
int i = 0; i < 4; ++i) arr.
append(0.0);
352 for (
size_t i = 0; i < arr.
size(); ++i)
359TEST(AlephIotaStepTest, NegativeStep)
361 auto lst =
rep(4, 0);
371TEST(AlephIotaStepTest, SingleElement)
373 auto lst =
rep(1, 0);
375 EXPECT_EQ(lst.get_first(), 42);
382TEST(AlephFillIotaTest, FillThenIota)
384 auto lst =
rep(5, 99);
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
Standard functor implementations and comparison objects.
Functional programming utilities for Aleph-w containers.
bool(*)(const int &, const int &) BoolBinFn
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
T & append(const T &data)
Append a copy of data
size_t size() const noexcept
Return the current dimension of array.
T & append()
Allocate a new entry to the end of array.
Dynamic doubly linked list with O(1) size and bidirectional access.
T & append(const T &item)
Append a copied item at the end of the list.
Doubly-linked list (defined in tpl_dynList.H).
size_t size() const noexcept
Return the number of items of the list, in constant time.
Node * insert(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Insert the node pointed by p in the tree.
Node * remove(const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Remove from an AVL tree the node containing key key.
Node * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a node containing key.
constexpr bool is_empty() const noexcept
Open addressing hash table with double hashing collision resolution.
void remove(const Key &key)
Remove a key from the hash table.
Key * search(const Key &key) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Minimal std::expected-style result type for C++20.
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Concept for Aleph-w mutable sequential containers.
Concept for BST tree policies used by DynSetTree.
A callable that takes two const T& and returns bool.
Equivalence relation constraint for equality comparators.
Strict weak ordering constraint for BST comparators.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
void fill(Itor beg, const Itor &end, const T &value)
Fill a range with a value.
std::decay_t< typename HeadC::Item_Type > T
void iota(C &container, typename C::Item_Type start)
Fill all elements of a container with unit-step sequential values.
DynList< T > rep(const size_t n, const T &item)
Create a sequence of repeated items.
and
Check uniqueness with explicit hash + equality functors.
Throwing_Ops operator-(const Throwing_Ops &, const Throwing_Ops &)
bool operator<=(const Throwing_Ops &, const Throwing_Ops &)
bool operator&&(const Throwing_Ops &, const Throwing_Ops &)
bool operator!(const Throwing_Ops &)
Throwing_Ops operator%(const Throwing_Ops &, const Throwing_Ops &)
bool operator||(const Throwing_Ops &, const Throwing_Ops &)
bool operator<(const Throwing_Ops &, const Throwing_Ops &)
bool operator==(const Throwing_Ops &, const Throwing_Ops &)
Throwing_Ops operator*(const Throwing_Ops &, const Throwing_Ops &)
bool operator!=(const Throwing_Ops &, const Throwing_Ops &)
Throwing_Ops operator+(const Throwing_Ops &, const Throwing_Ops &)
bool operator>(const Throwing_Ops &, const Throwing_Ops &)
Throwing_Ops operator/(const Throwing_Ops &, const Throwing_Ops &)
bool operator>=(const Throwing_Ops &, const Throwing_Ops &)
AVL binary search tree with nodes without a virtual destructor.
bool operator()(int) const
void operator()(int, int) const
Dynamic array container with automatic resizing.
AVL tree implementation (height-balanced BST).
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
Open addressing hash table with double hashing.
Top-down splay tree implementation (without rank support).