Branch data Line data Source code
1 : : // Copyright (c) 2022 The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <random.h>
6 : : #include <test/fuzz/FuzzedDataProvider.h>
7 : : #include <test/fuzz/util.h>
8 : : #include <util/bitdeque.h>
9 : :
10 : : #include <deque>
11 : : #include <vector>
12 : :
13 : : namespace {
14 : :
15 : : constexpr int LEN_BITS = 16;
16 : : constexpr int RANDDATA_BITS = 20;
17 : :
18 : : using bitdeque_type = bitdeque<128>;
19 : :
20 : : //! Deterministic random vector of bools, for begin/end insertions to draw from.
21 : : std::vector<bool> RANDDATA;
22 : :
23 : 1 : void InitRandData()
24 : : {
25 : 1 : FastRandomContext ctx(true);
26 : 1 : RANDDATA.clear();
27 [ + + ]: 1114113 : for (size_t i = 0; i < (1U << RANDDATA_BITS) + (1U << LEN_BITS); ++i) {
28 [ + - ]: 1114112 : RANDDATA.push_back(ctx.randbool());
29 : : }
30 : 1 : }
31 : :
32 : : } // namespace
33 : :
34 [ + - ]: 1057 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 601 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 601 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 601 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 601 : std::deque<bool> deq;
43 [ + - ]: 601 : bitdeque_type bitdeq;
44 : :
45 : 601 : const auto& cdeq = deq;
46 : 601 : const auto& cbitdeq = bitdeq;
47 : :
48 : 601 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 5170748 : while (initlen) {
50 : 5169546 : bool val = ctx.randbool();
51 [ + - ]: 5169546 : deq.push_back(val);
52 [ + - ]: 5169546 : bitdeq.push_back(val);
53 : 5169546 : --initlen;
54 : : }
55 : :
56 [ + + ]: 601 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 165374 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 164773 : CallOneOf(
60 : : provider,
61 : 11575 : [&] {
62 : : // constructor()
63 : 23150 : deq = std::deque<bool>{};
64 : 11575 : bitdeq = bitdeque_type{};
65 : 11575 : },
66 : 2492 : [&] {
67 : : // clear()
68 : 2492 : deq.clear();
69 : 2492 : bitdeq.clear();
70 : 2492 : },
71 : 4053 : [&] {
72 : : // resize()
73 : 4053 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 4053 : deq.resize(count);
75 : 4053 : bitdeq.resize(count);
76 : 4053 : },
77 : 5892 : [&] {
78 : : // assign(count, val)
79 : 5892 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 5892 : bool val = ctx.randbool();
81 : 5892 : deq.assign(count, val);
82 : 5892 : bitdeq.assign(count, val);
83 : 5892 : },
84 : 2199 : [&] {
85 : : // constructor(count, val)
86 : 2199 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 2199 : bool val = ctx.randbool();
88 : 4398 : deq = std::deque<bool>(count, val);
89 : 2199 : bitdeq = bitdeque_type(count, val);
90 : 2199 : },
91 : 1403 : [&] {
92 : : // constructor(count)
93 : 1403 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 2806 : deq = std::deque<bool>(count);
95 : 1403 : bitdeq = bitdeque_type(count);
96 : 1403 : },
97 : 3030 : [&] {
98 : : // construct(begin, end)
99 : 3030 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 3030 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 3030 : auto rand_end = rand_begin + count;
102 : 6060 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 3030 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 3030 : },
105 : 5253 : [&] {
106 : : // assign(begin, end)
107 : 5253 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 5253 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 5253 : auto rand_end = rand_begin + count;
110 : 5253 : deq.assign(rand_begin, rand_end);
111 : 5253 : bitdeq.assign(rand_begin, rand_end);
112 : 5253 : },
113 : 5728 : [&] {
114 : : // construct(initializer_list)
115 : 5728 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 11456 : deq = std::deque<bool>(ilist);
117 : 5728 : bitdeq = bitdeque_type(ilist);
118 : 5728 : },
119 : 7871 : [&] {
120 : : // assign(initializer_list)
121 : 7871 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 7871 : deq.assign(ilist);
123 : 7871 : bitdeq.assign(ilist);
124 : 7871 : },
125 : 7270 : [&] {
126 : : // operator=(const&)
127 : 7270 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 7270 : bool val = ctx.randbool();
129 : 7270 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 7270 : deq = deq2;
131 [ + - ]: 7270 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 7270 : bitdeq = bitdeq2;
133 : 7270 : },
134 : 2275 : [&] {
135 : : // operator=(&&)
136 : 2275 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 2275 : bool val = ctx.randbool();
138 : 2275 : std::deque<bool> deq2(count, val);
139 : 2275 : deq = std::move(deq2);
140 [ + - ]: 2275 : bitdeque_type bitdeq2(count, val);
141 : 2275 : bitdeq = std::move(bitdeq2);
142 : 2275 : },
143 : 2447 : [&] {
144 : : // deque swap
145 : 2447 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 2447 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 2447 : auto rand_end = rand_begin + count;
148 : 2447 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 2447 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 2447 : using std::swap;
151 [ - + - + ]: 2447 : assert(deq.size() == bitdeq.size());
152 [ - + - + ]: 2447 : assert(deq2.size() == bitdeq2.size());
153 : 2447 : swap(deq, deq2);
154 : 2447 : swap(bitdeq, bitdeq2);
155 [ - + - + ]: 2447 : assert(deq.size() == bitdeq.size());
156 [ - + - + ]: 2447 : assert(deq2.size() == bitdeq2.size());
157 : 2447 : },
158 : 4456 : [&] {
159 : : // deque.swap
160 : 4456 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 4456 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 4456 : auto rand_end = rand_begin + count;
163 : 4456 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 4456 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + - + ]: 4456 : assert(deq.size() == bitdeq.size());
166 [ - + - + ]: 4456 : assert(deq2.size() == bitdeq2.size());
167 : 4456 : deq.swap(deq2);
168 : 4456 : bitdeq.swap(bitdeq2);
169 [ - + - + ]: 4456 : assert(deq.size() == bitdeq.size());
170 [ - + - + ]: 4456 : assert(deq2.size() == bitdeq2.size());
171 : 4456 : },
172 : 3929 : [&] {
173 : : // operator=(initializer_list)
174 : 3929 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 3929 : deq = ilist;
176 : 3929 : bitdeq = ilist;
177 : 3929 : },
178 : 3420 : [&] {
179 : : // iterator arithmetic
180 [ - + ]: 3420 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 [ - + ]: 3420 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 3420 : auto it = deq.begin() + pos1;
183 : 3420 : auto bitit = bitdeq.begin() + pos1;
184 [ - + + + : 3420 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
- + ]
185 [ - + ]: 3420 : assert(it - deq.begin() == pos1);
186 [ - + ]: 3420 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 3420 : if (provider.ConsumeBool()) {
188 : 1913 : it += pos2 - pos1;
189 : 1913 : bitit += pos2 - pos1;
190 : : } else {
191 : 1507 : it -= pos1 - pos2;
192 : 1507 : bitit -= pos1 - pos2;
193 : : }
194 [ - + + + : 3420 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
- + ]
195 [ - + ]: 3420 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 3420 : if (provider.ConsumeBool()) {
197 [ - + + + ]: 1752 : if ((size_t)pos2 != cdeq.size()) {
198 : 1291 : ++it;
199 : 1291 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 1668 : if (pos2 != 0) {
203 : 1233 : --it;
204 : 1233 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 3420 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 3420 : },
209 : 1367 : [&] {
210 : : // begin() and end()
211 [ - + ]: 1367 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 1367 : },
213 : 1517 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 1517 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 1517 : },
217 : 1214 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 1214 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 1214 : },
221 : 1413 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 1413 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 1413 : },
225 : 760 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 760 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 760 : },
229 : 870 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 870 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 870 : },
233 : 1478 : [&] {
234 : : // size() and maxsize()
235 [ - + - + ]: 1478 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 1478 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 1478 : },
238 : 1499 : [&] {
239 : : // empty
240 [ - + ]: 1499 : assert(cdeq.empty() == cbitdeq.empty());
241 : 1499 : },
242 : 2190 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 2190 : if (!cdeq.empty()) {
245 [ - + ]: 1853 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 1853 : auto& ref = deq.at(pos);
247 : 1853 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 1853 : assert(ref == bitref);
249 [ + + ]: 1853 : if (ctx.randbool()) {
250 : 904 : ref = !ref;
251 : 904 : bitref.flip();
252 : : }
253 : 1853 : }
254 : 2190 : },
255 : 3867 : [&] {
256 : : // at (maybe out of range) and bit assign
257 [ - + ]: 3867 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 3867 : bool newval = ctx.randbool();
259 : 3867 : bool throw_deq{false}, throw_bitdeq{false};
260 : 3867 : bool val_deq{false}, val_bitdeq{false};
261 : 3867 : try {
262 [ + + ]: 3867 : auto& ref = deq.at(pos);
263 : 1374 : val_deq = ref;
264 : 1374 : ref = newval;
265 [ - + ]: 2493 : } catch (const std::out_of_range&) {
266 : 2493 : throw_deq = true;
267 : 2493 : }
268 : 3867 : try {
269 [ + + ]: 3867 : auto ref = bitdeq.at(pos);
270 : 1374 : val_bitdeq = ref;
271 : 1374 : ref = newval;
272 [ - + ]: 3867 : } catch (const std::out_of_range&) {
273 : 2493 : throw_bitdeq = true;
274 : 2493 : }
275 [ - + ]: 3867 : assert(throw_deq == throw_bitdeq);
276 [ - + - + ]: 3867 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 3867 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 3867 : },
279 : 1310 : [&] {
280 : : // at (maybe out of range) (const)
281 [ - + ]: 1310 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 1310 : bool throw_deq{false}, throw_bitdeq{false};
283 : 1310 : bool val_deq{false}, val_bitdeq{false};
284 : 1310 : try {
285 [ + + ]: 1310 : auto& ref = cdeq.at(pos);
286 : 822 : val_deq = ref;
287 [ - + ]: 488 : } catch (const std::out_of_range&) {
288 : 488 : throw_deq = true;
289 : 488 : }
290 : 1310 : try {
291 [ + + ]: 1310 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 488 : } catch (const std::out_of_range&) {
294 : 488 : throw_bitdeq = true;
295 : 488 : }
296 [ - + ]: 1310 : assert(throw_deq == throw_bitdeq);
297 [ - + - + ]: 1310 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 1310 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 1310 : },
300 : 2613 : [&] {
301 : : // operator[]
302 [ + + ]: 2613 : if (!cdeq.empty()) {
303 [ - + ]: 2222 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 2222 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 2222 : if (ctx.randbool()) {
306 : 1116 : deq[pos] = !deq[pos];
307 : 1116 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 2613 : },
311 : 1404 : [&] {
312 : : // operator[] const
313 [ + + ]: 1404 : if (!cdeq.empty()) {
314 [ - + ]: 1127 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 1127 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 1404 : },
318 : 2731 : [&] {
319 : : // front()
320 [ + + ]: 2731 : if (!cdeq.empty()) {
321 [ - + ]: 2348 : auto& ref = deq.front();
322 : 2348 : auto bitref = bitdeq.front();
323 [ - + ]: 2348 : assert(ref == bitref);
324 [ + + ]: 2348 : if (ctx.randbool()) {
325 : 1119 : ref = !ref;
326 : 1119 : bitref = !bitref;
327 : : }
328 : 2348 : }
329 : 2731 : },
330 : 846 : [&] {
331 : : // front() const
332 [ + + ]: 846 : if (!cdeq.empty()) {
333 [ - + ]: 549 : auto& ref = cdeq.front();
334 : 549 : auto bitref = cbitdeq.front();
335 [ - + ]: 549 : assert(ref == bitref);
336 : : }
337 : 846 : },
338 : 2537 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 2537 : if (!cdeq.empty()) {
341 : 2108 : auto& ref = deq.back();
342 : 2108 : auto bitref = bitdeq.back();
343 [ - + ]: 2108 : assert(ref == bitref);
344 [ + + ]: 2108 : if (ctx.randbool()) {
345 : 1062 : ref = !ref;
346 : 1062 : bitref.flip();
347 : : }
348 : 2108 : }
349 : 2537 : },
350 : 2244 : [&] {
351 : : // back() const
352 [ + + ]: 2244 : if (!cdeq.empty()) {
353 : 1537 : const auto& cdeq = deq;
354 : 1537 : const auto& cbitdeq = bitdeq;
355 : 1537 : auto& ref = cdeq.back();
356 : 1537 : auto bitref = cbitdeq.back();
357 [ - + ]: 1537 : assert(ref == bitref);
358 : : }
359 : 2244 : },
360 : 3580 : [&] {
361 : : // push_back()
362 [ - + + + ]: 3580 : if (cdeq.size() < limitlen) {
363 : 3114 : bool val = ctx.randbool();
364 [ + + ]: 3114 : if (cdeq.empty()) {
365 : 1527 : deq.push_back(val);
366 : 1527 : bitdeq.push_back(val);
367 : : } else {
368 [ - + ]: 1587 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 1587 : auto& ref = deq[pos];
370 : 1587 : auto bitref = bitdeq[pos];
371 [ - + ]: 1587 : assert(ref == bitref);
372 : 1587 : deq.push_back(val);
373 : 1587 : bitdeq.push_back(val);
374 [ - + ]: 1587 : assert(ref == bitref); // references are not invalidated
375 : 1587 : }
376 : : }
377 : 3580 : },
378 : 4934 : [&] {
379 : : // push_front()
380 [ - + + + ]: 4934 : if (cdeq.size() < limitlen) {
381 : 4583 : bool val = ctx.randbool();
382 [ + + ]: 4583 : if (cdeq.empty()) {
383 : 1836 : deq.push_front(val);
384 : 1836 : bitdeq.push_front(val);
385 : : } else {
386 [ - + ]: 2747 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 2747 : auto& ref = deq[pos];
388 : 2747 : auto bitref = bitdeq[pos];
389 [ - + ]: 2747 : assert(ref == bitref);
390 : 2747 : deq.push_front(val);
391 : 2747 : bitdeq.push_front(val);
392 [ - + ]: 2747 : assert(ref == bitref); // references are not invalidated
393 : 2747 : }
394 : : }
395 : 4934 : },
396 : 2472 : [&] {
397 : : // pop_back()
398 [ + + ]: 2472 : if (!cdeq.empty()) {
399 [ - + + + ]: 1878 : if (cdeq.size() == 1) {
400 : 675 : deq.pop_back();
401 : 675 : bitdeq.pop_back();
402 : : } else {
403 : 1203 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 1203 : auto& ref = deq[pos];
405 : 1203 : auto bitref = bitdeq[pos];
406 [ - + ]: 1203 : assert(ref == bitref);
407 : 1203 : deq.pop_back();
408 : 1203 : bitdeq.pop_back();
409 [ - + ]: 1203 : assert(ref == bitref); // references to other elements are not invalidated
410 : 1203 : }
411 : : }
412 : 2472 : },
413 : 3099 : [&] {
414 : : // pop_front()
415 [ + + ]: 3099 : if (!cdeq.empty()) {
416 [ - + + + ]: 2419 : if (cdeq.size() == 1) {
417 : 1180 : deq.pop_front();
418 : 1180 : bitdeq.pop_front();
419 : : } else {
420 : 1239 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 1239 : auto& ref = deq[pos];
422 : 1239 : auto bitref = bitdeq[pos];
423 [ - + ]: 1239 : assert(ref == bitref);
424 : 1239 : deq.pop_front();
425 : 1239 : bitdeq.pop_front();
426 [ - + ]: 1239 : assert(ref == bitref); // references to other elements are not invalidated
427 : 1239 : }
428 : : }
429 : 3099 : },
430 : 3611 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 3611 : if (!cdeq.empty()) {
433 [ - + ]: 3062 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 [ - + ]: 3062 : size_t after = cdeq.size() - 1 - before;
435 : 3062 : auto it = deq.erase(cdeq.begin() + before);
436 : 3062 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 3062 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 6124 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 3611 : },
441 : 3107 : [&] {
442 : : // erase (at front, range)
443 [ - + ]: 3107 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 3107 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 3107 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 3107 : assert(it == deq.begin());
447 [ + - ]: 3107 : assert(bitit == bitdeq.begin());
448 : 3107 : },
449 : 1555 : [&] {
450 : : // erase (at back, range)
451 [ - + ]: 1555 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 1555 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 1555 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 1555 : assert(it == deq.end());
455 [ + - ]: 1555 : assert(bitit == bitdeq.end());
456 : 1555 : },
457 : 2545 : [&] {
458 : : // erase (in middle, range)
459 [ - + ]: 2545 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 [ - + ]: 2545 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 [ - + ]: 2545 : size_t after = cdeq.size() - count - before;
462 : 2545 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 2545 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 2545 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 5090 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 2545 : },
467 : 5600 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ - + + + ]: 5600 : if (cdeq.size() < limitlen) {
470 : 5273 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 5273 : bool val = ctx.randbool();
472 : 5273 : bool do_emplace = provider.ConsumeBool();
473 : 5273 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 5273 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 5273 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 5273 : assert(it == deq.begin() + before);
477 [ + - ]: 5273 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 5600 : },
480 : 4944 : [&] {
481 : : // insert (at front, begin/end)
482 [ - + + + ]: 4944 : if (cdeq.size() < limitlen) {
483 : 4619 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 4619 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 4619 : auto rand_end = rand_begin + count;
486 : 4619 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 4619 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 4619 : assert(it == cdeq.begin());
489 [ + - ]: 4619 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 4944 : },
492 : 3744 : [&] {
493 : : // insert (at back, begin/end)
494 [ - + + + ]: 3744 : if (cdeq.size() < limitlen) {
495 : 2965 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 2965 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 2965 : auto rand_end = rand_begin + count;
498 : 2965 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 2965 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 2965 : assert(it == cdeq.end() - count);
501 [ + - ]: 2965 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 3744 : },
504 : 11786 : [&] {
505 : : // insert (in middle, range)
506 [ - + + + ]: 11786 : if (cdeq.size() < limitlen) {
507 : 9336 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 [ - + ]: 9336 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 9336 : bool val = ctx.randbool();
510 : 9336 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 9336 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 9336 : assert(it == deq.begin() + before);
513 [ + - ]: 9336 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 11786 : },
516 : 10643 : [&] {
517 : : // insert (in middle, begin/end)
518 [ - + + + ]: 10643 : if (cdeq.size() < limitlen) {
519 : 9223 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 [ - + ]: 9223 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 9223 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 9223 : auto rand_end = rand_begin + count;
523 : 9223 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 9223 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 9223 : assert(it == deq.begin() + before);
526 [ + - ]: 9223 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 10643 : });
529 : : }
530 : 601 : {
531 [ - + - + ]: 601 : assert(deq.size() == bitdeq.size());
532 : 601 : auto it = deq.begin();
533 : 601 : auto bitit = bitdeq.begin();
534 : 601 : auto itend = deq.end();
535 [ + + ]: 7247510 : while (it != itend) {
536 [ - + ]: 7246909 : assert(*it == *bitit);
537 : 7246909 : ++it;
538 : 7246909 : ++bitit;
539 : : }
540 : : }
541 : 601 : }
|