37# include <gtest/gtest.h>
48using namespace testing;
55 EXPECT_TRUE(domain.is_empty());
57 for (
size_t i = 0; i < 10; ++i)
60 EXPECT_FALSE(domain.contains(-1));
61 EXPECT_FALSE(domain.contains(10));
63 EXPECT_TRUE(domain.all([] (
auto i) { return i >= 0 and i < 10; }));
80 EXPECT_THROW(
IntRange(0, 3, 0), std::domain_error);
81 EXPECT_THROW(
IntRange(0, 3, -1), std::domain_error);
82 EXPECT_THROW(
IntRange(5, 3, 0), std::domain_error);
93 EXPECT_EQ(keys_of(
r), (std::vector<int>{INT_MAX - 2, INT_MAX - 1, INT_MAX}));
95 const IntRange s(INT_MAX - 3, INT_MAX, 2);
96 EXPECT_EQ(keys_of(s), (std::vector<int>{INT_MAX - 3, INT_MAX - 1}));
98 const IntRange t(INT_MIN, INT_MIN + 1);
99 EXPECT_EQ(keys_of(t), (std::vector<int>{INT_MIN, INT_MIN + 1}));
106 EXPECT_THROW(
IntRange(
static_cast<size_t>(INT_MAX) + 2), std::domain_error);
107 EXPECT_THROW(
IntRange(
static_cast<size_t>(-1)), std::domain_error);
109 EXPECT_EQ(keys_of(
IntRange(
size_t(3))), (std::vector<int>{0, 1, 2}));
118 EXPECT_EQ(keys_of(d), (std::vector<int>{1, 3}));
121 EXPECT_EQ(keys_of(d), (std::vector<int>{1, 2, 3}));
124 EXPECT_EQ(keys_of(d), (std::vector<int>{2, 3}));
127 EXPECT_EQ(keys_of(d), (std::vector<int>{0, 2, 3}));
130 EXPECT_EQ(keys_of(d), (std::vector<int>{0, 2, 3, 5}));
133 EXPECT_EQ(keys_of(d), (std::vector<int>{0, 2, 3, 4, 5}));
136 EXPECT_EQ(keys_of(d), (std::vector<int>{0, 2, 4, 5}));
139 EXPECT_EQ(keys_of(d), (std::vector<int>{0, 2, 4, 5, 6, 7}));
143 EXPECT_EQ(keys_of(e), (std::vector<int>{9}));
145 EXPECT_EQ(keys_of(d), (std::vector<int>{9}));
146 EXPECT_EQ(keys_of(e), (std::vector<int>{0, 2, 4, 5, 6, 7}));
149 EXPECT_TRUE(keys_of(e).empty());
152 EXPECT_TRUE(keys_of(e).empty());
160 for (
int i = 0; i < 5; ++i)
162 EXPECT_EQ(keys_of(d).
size(), 5u);
164 auto it = d.get_it();
165 const int removed = it.get_curr();
169 for (
int i = 0; i < 5; ++i)
180 EXPECT_EQ(keys_of(d), (std::vector<int>{1, 2}));
184 EXPECT_EQ(keys_of(c), (std::vector<int>{0, 1, 2}));
185 EXPECT_EQ(keys_of(d), (std::vector<int>{1, 2}));
Integer domain classes for sparse data structures.
Generic domain class based on hash set.
T * insert(const T &key)
Insert key, as HashSet::insert(), and forget the sorted keys.
void swap(AlDomain &other) noexcept
Swap the keys, and the sorted keys, with other.
T * search_or_insert(const T &key)
Search or insert key, as HashSet::search_or_insert(), and forget the sorted keys.
void add(const DynList< T > &l)
Insert the keys of l, as HashSet::add(), and forget the sorted keys.
T * append(const T &key)
Insert key, as HashSet::append(), and forget the sorted keys.
void clear()
Remove every key, as HashSet::clear(), and forget the sorted keys.
const DynList< T > & keys() const
Get sorted list of all elements in the domain.
void remove(const T &key)
Remove key, as HashSet::remove(), and forget the sorted keys.
void remove_ptr(T *key)
Remove the key that key points to, as HashSet::remove_ptr(), and forget the sorted keys.
std::pair< T *, bool > contains_or_insert(const T &key)
Search or insert key, as HashSet::contains_or_insert(), and forget the sorted keys.
void empty()
Remove every key, as HashSet::empty(), and forget the sorted keys.
Doubly-linked list (defined in tpl_dynList.H).
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.
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
@ Domain
Preserve the order emitted by for_each_successor().
Integer range domain [start, end] with optional step.