11#include <boost/test/unit_test.hpp>
18template<
unsigned int N,
typename T>
33 template <
typename A,
typename B>
43 const pretype& const_pre_vector = pre_vector;
46 for (
Size s = 0;
s < real_vector.size();
s++) {
50 local_check(&(pre_vector[
s]) == &*((pre_vector.
end() +
s) - real_vector.size()));
56 for (
const T& v : pre_vector) {
59 for (
const T& v : pre_vector | std::views::reverse) {
62 for (
const T& v : const_pre_vector) {
65 for (
const T& v : const_pre_vector | std::views::reverse) {
73 for (
Size s = 0;
s < ss1.size();
s++) {
80 real_vector.resize(
s);
88 real_vector.reserve(
s);
96 real_vector.insert(real_vector.begin() + position, value);
97 pre_vector.
insert(pre_vector.
begin() + position, value);
102 real_vector.insert(real_vector.begin() + position,
count, value);
109 real_vector.insert(real_vector.begin() + position, first, last);
110 pre_vector.
insert(pre_vector.
begin() + position, first, last);
115 real_vector.erase(real_vector.begin() + position);
116 pre_vector.
erase(pre_vector.
begin() + position);
121 real_vector.erase(real_vector.begin() + first, real_vector.begin() + last);
122 pre_vector.
erase(pre_vector.
begin() + first, pre_vector.
begin() + last);
127 real_vector[pos] = value;
128 pre_vector[pos] = value;
133 real_vector.push_back(value);
139 real_vector.pop_back();
150 real_vector.assign(n, value);
151 pre_vector.
assign(n, value);
155 return real_vector.size();
169 real_vector.swap(real_vector_alt);
170 pre_vector.
swap(pre_vector_alt);
175 real_vector = std::move(real_vector_alt);
176 real_vector_alt.clear();
177 pre_vector = std::move(pre_vector_alt);
178 pre_vector_alt.
clear();
182 real_vector = real_vector_alt;
183 pre_vector = pre_vector_alt;
188 size_t s = real_vector.size() / 2;
189 if (real_vector.capacity() <
s + r) {
190 real_vector.reserve(
s + r);
192 real_vector.resize(
s);
195 real_vector.push_back(v);
197 auto p = pre_vector.
size();
207 BOOST_CHECK_MESSAGE(passed,
"insecure_rand: " + rand_seed.
ToString());
218 for (
int j = 0; j < 64; j++) {
220 for (
int i = 0; i < 2048; i++) {
221 if (m_rng.randbits(2) == 0) {
222 test.
insert(m_rng.randrange(test.size() + 1),
int(m_rng.rand32()));
224 if (test.size() > 0 && m_rng.randbits(2) == 1) {
225 test.erase(m_rng.randrange(test.size()));
227 if (m_rng.randbits(3) == 2) {
228 int new_size = std::max(0, std::min(30, (
int)test.size() + (
int)m_rng.randrange(5) - 2));
229 test.resize(new_size);
231 if (m_rng.randbits(3) == 3) {
232 test.insert(m_rng.randrange(test.size() + 1), 1 + m_rng.randbool(),
int(m_rng.rand32()));
234 if (m_rng.randbits(3) == 4) {
235 int del = std::min<int>(test.size(), 1 + (m_rng.randbool()));
236 int beg = m_rng.randrange(test.size() + 1 - del);
237 test.erase(beg, beg + del);
239 if (m_rng.randbits(4) == 5) {
240 test.push_back(
int(m_rng.rand32()));
242 if (test.size() > 0 && m_rng.randbits(4) == 6) {
245 if (m_rng.randbits(5) == 7) {
247 int num = 1 + (m_rng.randbits(2));
248 for (
int k = 0;
k < num;
k++) {
249 values[
k] = int(m_rng.rand32());
251 test.insert_range(m_rng.randrange(test.size() + 1),
values,
values + num);
253 if (m_rng.randbits(5) == 8) {
254 int del = std::min<int>(test.size(), 1 + (m_rng.randbits(2)));
255 int beg = m_rng.randrange(test.size() + 1 - del);
256 test.erase(beg, beg + del);
258 if (m_rng.randbits(5) == 9) {
259 test.reserve(m_rng.randbits(5));
261 if (m_rng.randbits(6) == 10) {
262 test.shrink_to_fit();
264 if (test.size() > 0) {
265 test.update(m_rng.randrange(test.size()),
int(m_rng.rand32()));
267 if (m_rng.randbits(10) == 11) {
270 if (m_rng.randbits(9) == 12) {
271 test.assign(m_rng.randbits(5),
int(m_rng.rand32()));
273 if (m_rng.randbits(3) == 3) {
276 if (m_rng.randbits(4) == 8) {
279 if (m_rng.randbits(5) == 18) {
282 if (m_rng.randbits(5) == 19) {
283 unsigned int num = 1 + (m_rng.randbits(4));
284 std::vector<int>
values(num);
286 v = int(m_rng.rand32());
288 test.resize_uninitialized(
values);
Double ended buffer combining vector and stream-like interfaces.
void Reseed(const uint256 &seed) noexcept
Reseed with explicit seed (only for testing).
uint256 rand256() noexcept
generate a random uint256.
std::string ToString() const
void erase(Size position)
void update(Size pos, const T &value)
void local_check_equal(A a, B b)
void insert(Size position, Size count, const T &value)
prevector< N, T > pretype
void erase(Size first, Size last)
prevector_tester(FastRandomContext &rng)
void insert(Size position, const T &value)
std::vector< T > realtype
void assign(Size n, const T &value)
void insert_range(Size position, I first, I last)
void resize_uninitialized(realtype values)
void push_back(const T &value)
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
void swap(prevector< N, T, Size, Diff > &other) noexcept
iterator erase(iterator pos)
void reserve(size_type new_capacity)
void resize_uninitialized(size_type new_size)
void resize(size_type new_size)
iterator insert(iterator pos, const T &value)
void assign(size_type n, const T &val)
void push_back(const T &value)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(PrevectorTestInt)
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
Testing setup that configures a complete environment.