42#include <gtest/gtest.h>
76 class Count_Value_Probe
81 Count_Value_Probe() =
default;
83 Count_Value_Probe(
const size_t n,
const T &
value) : items(n,
value) {}
85 T & append(
const T & item) {
return items.
append(item); }
87 template <
class Operation>
90 [[nodiscard]]
const Array<T> & get_items() const noexcept {
return items; }
101 explicit Bare_Iterator(
const int * p) noexcept : pos(p) {}
103 const int &
operator * () const noexcept {
return *pos; }
105 Bare_Iterator & operator ++ () noexcept
111 bool operator != (
const Bare_Iterator & other)
const noexcept
113 return pos != other.pos;
117 static_assert(not std::input_iterator<Bare_Iterator>,
118 "the probe must be weaker than std::input_iterator");
121 template <
class C,
typename I =
int>
122 constexpr bool accepts_integer_pair =
123 std::is_constructible_v<C, I, I> or std::is_constructible_v<C, I &, I &>;
130 static_assert(not accepts_integer_pair<ArrayQueue<int>>);
131 static_assert(not accepts_integer_pair<FixedQueue<int>>);
132 static_assert(not accepts_integer_pair<ArrayStack<int>>);
133 static_assert(not accepts_integer_pair<FixedStack<int>>);
134 static_assert(not accepts_integer_pair<ArrayHeap<int>>);
135 static_assert(not accepts_integer_pair<DynDlist<int>>);
138 static_assert(not accepts_integer_pair<DynList<int>>);
139 static_assert(not accepts_integer_pair<DynListQueue<int>>);
140 static_assert(not accepts_integer_pair<DynListStack<int>>);
141 static_assert(not accepts_integer_pair<DynSetTree<int>>);
142 static_assert(not accepts_integer_pair<DynSetHash<int>>);
143 static_assert(not accepts_integer_pair<HashSet<int>>);
144 static_assert(not accepts_integer_pair<ODhashTable<int>>);
145 static_assert(not accepts_integer_pair<OLhashTable<int>>);
146 static_assert(not accepts_integer_pair<DynIntervalTree<int>>);
147 static_assert(not accepts_integer_pair<Polygon>);
149 static_assert(not accepts_integer_pair<ArrayQueue<size_t>,
size_t>);
150 static_assert(not accepts_integer_pair<DynDlist<size_t>,
size_t>);
151 static_assert(not accepts_integer_pair<DynList<size_t>,
size_t>);
152 static_assert(not accepts_integer_pair<DynSetTree<size_t>,
size_t>);
153 static_assert(not accepts_integer_pair<OLhashTable<size_t>,
size_t>);
157 static_assert(accepts_integer_pair<DynArray<int>>);
158 static_assert(accepts_integer_pair<DynArray<size_t>,
size_t>);
172 static_assert(not std::is_constructible_v<DynBinHeap<int>, int,
int>);
173 static_assert(not std::is_constructible_v<DynArrayHeap<int>, int,
int>);
177 EXPECT_EQ(bin_heap.
size(), 2u);
178 EXPECT_EQ(array_heap.
size(), 2u);
183 const Count_Value_Probe<int> literals(3, 7);
184 EXPECT_EQ(literals.get_items(), (
Array<int>{7, 7, 7}));
186 int n = 2,
value = 9;
187 const Count_Value_Probe<int> lvalues(n,
value);
188 EXPECT_EQ(lvalues.get_items(), (
Array<int>{9, 9}));
190 const size_t m = 2, v = 5;
191 const Count_Value_Probe<size_t> same_type(
m, v);
197 const int raw[] = {4, 5, 6};
199 const Count_Value_Probe<int> probe(Bare_Iterator(raw), Bare_Iterator(raw + 3));
200 EXPECT_EQ(probe.get_items(), (
Array<int>{4, 5, 6}));
202 DynDlist<int> list(Bare_Iterator(raw), Bare_Iterator(raw + 3));
203 ASSERT_EQ(list.
size(), 3u);
210 const std::vector<int> vec = {3, 1, 2};
211 const int raw[] = {3, 1, 2};
217 for (
const DynDlist<int> * list : {&from_vector, &from_pointers, &from_aleph})
219 ASSERT_EQ(list->size(), 3u);
220 EXPECT_EQ(list->get_first(), 3);
221 EXPECT_EQ(list->get_last(), 2);
225 ASSERT_EQ(array.
size(), 3u);
226 EXPECT_EQ(array(0), 3);
227 EXPECT_EQ(array(2), 2);
230 ASSERT_EQ(queue.
size(), 3u);
231 EXPECT_EQ(queue.
front(), 3);
232 EXPECT_EQ(queue.
rear(), 2);
235 ASSERT_EQ(set.
size(), 3u);
236 EXPECT_EQ(set.
min(), 1);
237 EXPECT_EQ(set.
max(), 3);
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
size_t size_t int32_t value
Queue implemented with a single dynamic array.
T & front(const size_t i=0)
Return the i-th oldest item of the queue.
T & rear(const size_t i=0)
Return the i-th youngest item of the queue.
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Dynamic heap (priority queue) backed by DynArray.
constexpr size_t size() const noexcept
Return the number of elements.
size_t size() const noexcept
Return the current dimension of array.
Dynamic heap of elements of type T ordered by a comparison functor.
Dynamic doubly linked list with O(1) size and bidirectional access.
const size_t & size() const noexcept
Return the number of elements (constant time)
T & get_first()
Return a modifiable reference to first item in the list.
T & get_last()
Return a modifiable reference to last item in 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.
Dynamic set backed by balanced binary search trees with automatic memory management.
const Key & min() const
Returns the smallest key contained in the set according to the criterion comparison given.
const size_t & size() const
Returns the cardinality of the set.
const Key & max() const
Returns the largest key contained in the set according to the criteria comparison given.
Dynamic ordered set implemented with a Skip List.
bool is_empty() const noexcept
Return true if the set is empty.
const size_t & size() const noexcept
size_t size() const noexcept
Return the number of elements.
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
bool operator!=(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
DynList< T > repeated(const Container< T > &c)
Return elements that appear more than once in the container.
std::decay_t< typename HeadC::Item_Type > T
Matrix< Trow, Tcol, NumType > operator*(const NumType &scalar, const Matrix< Trow, Tcol, NumType > &m)
Scalar-matrix multiplication (scalar * matrix).
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
2D polygon representation and geometric operations.
Special constructors common to Aleph-w ( ) containers.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Fixed-capacity binary heap and heapsort algorithms.
Circular queue implementations backed by arrays.
Stack implementations backed by dynamic or fixed arrays.
Dynamic array container with automatic resizing.
Array-based dynamic binary heap.
Lazy and scalable dynamic array implementation.
Dynamic binary heap with node-based storage.
Dynamic doubly linked list implementation.
Dynamic queue implementation based on linked lists.
Dynamic stack implementation based on linked lists.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.
Dynamic ordered set implemented with a Skip List.
Unified hash table interface.
Interval tree: augmented BST for overlap/stabbing queries.
Open addressing hash table with double hashing.
Open addressing hash table with linear probing.