15constexpr int LEN_BITS = 16;
16constexpr int RANDDATA_BITS = 20;
21std::vector<bool> RANDDATA;
27 for (
size_t i = 0; i < (1U << RANDDATA_BITS) + (1U << LEN_BITS); ++i) {
28 RANDDATA.push_back(ctx.randbool());
40 size_t limitlen = 4 * maxlen;
45 const auto& cdeq = deq;
46 const auto& cbitdeq = bitdeq;
52 bitdeq.push_back(val);
56 const auto iter_limit{maxlen > 6000 ? 90U : 900U};
63 deq = std::deque<bool>{};
64 bitdeq = bitdeque_type{};
81 deq.assign(
count, val);
82 bitdeq.assign(
count, val);
88 deq = std::deque<bool>(
count, val);
89 bitdeq = bitdeque_type(
count, val);
94 deq = std::deque<bool>(
count);
95 bitdeq = bitdeque_type(
count);
100 auto rand_begin = RANDDATA.begin() + ctx.
randbits(RANDDATA_BITS);
101 auto rand_end = rand_begin +
count;
102 deq = std::deque<bool>(rand_begin, rand_end);
103 bitdeq = bitdeque_type(rand_begin, rand_end);
108 auto rand_begin = RANDDATA.begin() + ctx.
randbits(RANDDATA_BITS);
109 auto rand_end = rand_begin +
count;
110 deq.assign(rand_begin, rand_end);
111 bitdeq.assign(rand_begin, rand_end);
116 deq = std::deque<bool>(ilist);
117 bitdeq = bitdeque_type(ilist);
123 bitdeq.assign(ilist);
129 const std::deque<bool> deq2(
count, val);
131 const bitdeque_type bitdeq2(
count, val);
138 std::deque<bool> deq2(
count, val);
139 deq = std::move(deq2);
140 bitdeque_type bitdeq2(
count, val);
141 bitdeq = std::move(bitdeq2);
146 auto rand_begin = RANDDATA.begin() + ctx.
randbits(RANDDATA_BITS);
147 auto rand_end = rand_begin +
count;
148 std::deque<bool> deq2(rand_begin, rand_end);
149 bitdeque_type bitdeq2(rand_begin, rand_end);
151 assert(deq.size() == bitdeq.size());
152 assert(deq2.size() == bitdeq2.size());
154 swap(bitdeq, bitdeq2);
155 assert(deq.size() == bitdeq.size());
156 assert(deq2.size() == bitdeq2.size());
161 auto rand_begin = RANDDATA.begin() + ctx.
randbits(RANDDATA_BITS);
162 auto rand_end = rand_begin +
count;
163 std::deque<bool> deq2(rand_begin, rand_end);
164 bitdeque_type bitdeq2(rand_begin, rand_end);
165 assert(deq.size() == bitdeq.size());
166 assert(deq2.size() == bitdeq2.size());
168 bitdeq.swap(bitdeq2);
169 assert(deq.size() == bitdeq.size());
170 assert(deq2.size() == bitdeq2.size());
182 auto it = deq.begin() + pos1;
183 auto bitit = bitdeq.begin() + pos1;
184 if ((
size_t)pos1 != cdeq.size())
assert(*it == *bitit);
185 assert(it - deq.begin() == pos1);
186 assert(bitit - bitdeq.begin() == pos1);
189 bitit += pos2 - pos1;
192 bitit -= pos1 - pos2;
194 if ((
size_t)pos2 != cdeq.size())
assert(*it == *bitit);
195 assert(deq.end() - it == bitdeq.end() - bitit);
197 if ((
size_t)pos2 != cdeq.size()) {
207 assert(deq.end() - it == bitdeq.end() - bitit);
211 assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
215 assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
219 assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
223 assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
227 assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
231 assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
235 assert(cdeq.size() == cbitdeq.size());
236 assert(cbitdeq.size() <= cbitdeq.max_size());
240 assert(cdeq.empty() == cbitdeq.empty());
246 auto& ref = deq.at(pos);
247 auto bitref = bitdeq.at(pos);
259 bool throw_deq{
false}, throw_bitdeq{
false};
260 bool val_deq{
false}, val_bitdeq{
false};
262 auto& ref = deq.at(pos);
265 }
catch (
const std::out_of_range&) {
269 auto ref = bitdeq.at(pos);
272 }
catch (
const std::out_of_range&) {
275 assert(throw_deq == throw_bitdeq);
276 assert(throw_bitdeq == (pos >= cdeq.size()));
277 if (!throw_deq)
assert(val_deq == val_bitdeq);
282 bool throw_deq{
false}, throw_bitdeq{
false};
283 bool val_deq{
false}, val_bitdeq{
false};
285 auto& ref = cdeq.at(pos);
287 }
catch (
const std::out_of_range&) {
291 auto ref = cbitdeq.at(pos);
293 }
catch (
const std::out_of_range&) {
296 assert(throw_deq == throw_bitdeq);
297 assert(throw_bitdeq == (pos >= cdeq.size()));
298 if (!throw_deq)
assert(val_deq == val_bitdeq);
304 assert(deq[pos] == bitdeq[pos]);
306 deq[pos] = !deq[pos];
315 assert(deq[pos] == bitdeq[pos]);
321 auto& ref = deq.front();
322 auto bitref = bitdeq.front();
333 auto& ref = cdeq.front();
334 auto bitref = cbitdeq.front();
341 auto& ref = deq.back();
342 auto bitref = bitdeq.back();
353 const auto& cdeq = deq;
354 const auto& cbitdeq = bitdeq;
355 auto& ref = cdeq.back();
356 auto bitref = cbitdeq.back();
362 if (cdeq.size() < limitlen) {
366 bitdeq.push_back(val);
369 auto& ref = deq[pos];
370 auto bitref = bitdeq[pos];
373 bitdeq.push_back(val);
380 if (cdeq.size() < limitlen) {
384 bitdeq.push_front(val);
387 auto& ref = deq[pos];
388 auto bitref = bitdeq[pos];
391 bitdeq.push_front(val);
399 if (cdeq.size() == 1) {
404 auto& ref = deq[pos];
405 auto bitref = bitdeq[pos];
416 if (cdeq.size() == 1) {
421 auto& ref = deq[pos];
422 auto bitref = bitdeq[pos];
434 size_t after = cdeq.size() - 1 - before;
435 auto it = deq.erase(cdeq.begin() + before);
436 auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
444 auto it = deq.erase(cdeq.begin(), cdeq.begin() +
count);
445 auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() +
count);
446 assert(it == deq.begin());
447 assert(bitit == bitdeq.begin());
452 auto it = deq.erase(cdeq.end() -
count, cdeq.end());
453 auto bitit = bitdeq.erase(cbitdeq.end() -
count, cbitdeq.end());
455 assert(bitit == bitdeq.end());
461 size_t after = cdeq.size() -
count - before;
462 auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
469 if (cdeq.size() < limitlen) {
473 auto it = deq.insert(cdeq.begin() + before, val);
474 auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : bitdeq.insert(cbitdeq.begin() + before, val);
476 assert(it == deq.begin() + before);
477 assert(bitit == bitdeq.begin() + before);
482 if (cdeq.size() < limitlen) {
484 auto rand_begin = RANDDATA.begin() + ctx.
randbits(RANDDATA_BITS);
485 auto rand_end = rand_begin +
count;
486 auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 assert(it == cdeq.begin());
489 assert(bitit == cbitdeq.begin());
494 if (cdeq.size() < limitlen) {
496 auto rand_begin = RANDDATA.begin() + ctx.
randbits(RANDDATA_BITS);
497 auto rand_end = rand_begin +
count;
498 auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
506 if (cdeq.size() < limitlen) {
510 auto it = deq.insert(cdeq.begin() + before,
count, val);
511 auto bitit = bitdeq.insert(cbitdeq.begin() + before,
count, val);
512 assert(it == deq.begin() + before);
513 assert(bitit == bitdeq.begin() + before);
518 if (cdeq.size() < limitlen) {
521 auto rand_begin = RANDDATA.begin() + ctx.
randbits(RANDDATA_BITS);
522 auto rand_end = rand_begin +
count;
523 auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 assert(it == deq.begin() + before);
526 assert(bitit == bitdeq.begin() + before);
531 assert(deq.size() == bitdeq.size());
532 auto it = deq.begin();
533 auto bitit = bitdeq.begin();
534 auto itend = deq.end();
535 while (it != itend) {
FUZZ_TARGET(bitdeque,.init=InitRandData)
T ConsumeIntegralInRange(T min, T max)
bool randbool() noexcept
Generate a random boolean.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Class that mimics std::deque<bool>, but with std::vector<bool>'s bit packing.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)