Branch data Line data Source code
1 : : // Copyright (c) 2022-present 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 [ + - ]: 1622 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 1172 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 1172 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 1172 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 1172 : std::deque<bool> deq;
43 [ + - ]: 1172 : bitdeque_type bitdeq;
44 : :
45 : 1172 : const auto& cdeq = deq;
46 : 1172 : const auto& cbitdeq = bitdeq;
47 : :
48 : 1172 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 9266042 : while (initlen) {
50 : 9263698 : bool val = ctx.randbool();
51 [ + - ]: 9263698 : deq.push_back(val);
52 [ + - ]: 9263698 : bitdeq.push_back(val);
53 : 9263698 : --initlen;
54 : : }
55 : :
56 [ + + ]: 1172 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 398261 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 397089 : CallOneOf(
60 : : provider,
61 : 28568 : [&] {
62 : : // constructor()
63 : 57136 : deq = std::deque<bool>{};
64 : 28568 : bitdeq = bitdeque_type{};
65 : 28568 : },
66 : 6862 : [&] {
67 : : // clear()
68 : 6862 : deq.clear();
69 : 6862 : bitdeq.clear();
70 : 6862 : },
71 : 10934 : [&] {
72 : : // resize()
73 : 10934 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 10934 : deq.resize(count);
75 : 10934 : bitdeq.resize(count);
76 : 10934 : },
77 : 12488 : [&] {
78 : : // assign(count, val)
79 : 12488 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 12488 : bool val = ctx.randbool();
81 : 12488 : deq.assign(count, val);
82 : 12488 : bitdeq.assign(count, val);
83 : 12488 : },
84 : 5554 : [&] {
85 : : // constructor(count, val)
86 : 5554 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 5554 : bool val = ctx.randbool();
88 : 11108 : deq = std::deque<bool>(count, val);
89 : 5554 : bitdeq = bitdeque_type(count, val);
90 : 5554 : },
91 : 4156 : [&] {
92 : : // constructor(count)
93 : 4156 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 8312 : deq = std::deque<bool>(count);
95 : 4156 : bitdeq = bitdeque_type(count);
96 : 4156 : },
97 : 7087 : [&] {
98 : : // construct(begin, end)
99 : 7087 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 7087 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 7087 : auto rand_end = rand_begin + count;
102 : 14174 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 7087 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 7087 : },
105 : 11910 : [&] {
106 : : // assign(begin, end)
107 : 11910 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 11910 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 11910 : auto rand_end = rand_begin + count;
110 : 11910 : deq.assign(rand_begin, rand_end);
111 : 11910 : bitdeq.assign(rand_begin, rand_end);
112 : 11910 : },
113 : 11618 : [&] {
114 : : // construct(initializer_list)
115 : 11618 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 23236 : deq = std::deque<bool>(ilist);
117 : 11618 : bitdeq = bitdeque_type(ilist);
118 : 11618 : },
119 : 16910 : [&] {
120 : : // assign(initializer_list)
121 : 16910 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 16910 : deq.assign(ilist);
123 : 16910 : bitdeq.assign(ilist);
124 : 16910 : },
125 : 16934 : [&] {
126 : : // operator=(const&)
127 : 16934 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 16934 : bool val = ctx.randbool();
129 : 16934 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 16934 : deq = deq2;
131 [ + - ]: 16934 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 16934 : bitdeq = bitdeq2;
133 : 16934 : },
134 : 5006 : [&] {
135 : : // operator=(&&)
136 : 5006 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 5006 : bool val = ctx.randbool();
138 : 5006 : std::deque<bool> deq2(count, val);
139 : 5006 : deq = std::move(deq2);
140 [ + - ]: 5006 : bitdeque_type bitdeq2(count, val);
141 : 5006 : bitdeq = std::move(bitdeq2);
142 : 5006 : },
143 : 4977 : [&] {
144 : : // deque swap
145 : 4977 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 4977 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 4977 : auto rand_end = rand_begin + count;
148 : 4977 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 4977 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 4977 : using std::swap;
151 [ - + - + ]: 4977 : assert(deq.size() == bitdeq.size());
152 [ - + - + ]: 4977 : assert(deq2.size() == bitdeq2.size());
153 : 4977 : swap(deq, deq2);
154 : 4977 : swap(bitdeq, bitdeq2);
155 [ - + - + ]: 4977 : assert(deq.size() == bitdeq.size());
156 [ - + - + ]: 4977 : assert(deq2.size() == bitdeq2.size());
157 : 4977 : },
158 : 9124 : [&] {
159 : : // deque.swap
160 : 9124 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 9124 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 9124 : auto rand_end = rand_begin + count;
163 : 9124 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 9124 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + - + ]: 9124 : assert(deq.size() == bitdeq.size());
166 [ - + - + ]: 9124 : assert(deq2.size() == bitdeq2.size());
167 : 9124 : deq.swap(deq2);
168 : 9124 : bitdeq.swap(bitdeq2);
169 [ - + - + ]: 9124 : assert(deq.size() == bitdeq.size());
170 [ - + - + ]: 9124 : assert(deq2.size() == bitdeq2.size());
171 : 9124 : },
172 : 9809 : [&] {
173 : : // operator=(initializer_list)
174 : 9809 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 9809 : deq = ilist;
176 : 9809 : bitdeq = ilist;
177 : 9809 : },
178 : 10869 : [&] {
179 : : // iterator arithmetic
180 [ - + ]: 10869 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 [ - + ]: 10869 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 10869 : auto it = deq.begin() + pos1;
183 : 10869 : auto bitit = bitdeq.begin() + pos1;
184 [ - + + + : 10869 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
- + ]
185 [ - + ]: 10869 : assert(it - deq.begin() == pos1);
186 [ - + ]: 10869 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 10869 : if (provider.ConsumeBool()) {
188 : 6697 : it += pos2 - pos1;
189 : 6697 : bitit += pos2 - pos1;
190 : : } else {
191 : 4172 : it -= pos1 - pos2;
192 : 4172 : bitit -= pos1 - pos2;
193 : : }
194 [ - + + + : 10869 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
- + ]
195 [ - + ]: 10869 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 10869 : if (provider.ConsumeBool()) {
197 [ - + + + ]: 6425 : if ((size_t)pos2 != cdeq.size()) {
198 : 4415 : ++it;
199 : 4415 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 4444 : if (pos2 != 0) {
203 : 3471 : --it;
204 : 3471 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 10869 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 10869 : },
209 : 3520 : [&] {
210 : : // begin() and end()
211 [ - + ]: 3520 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 3520 : },
213 : 3767 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 3767 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 3767 : },
217 : 2791 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 2791 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 2791 : },
221 : 3663 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 3663 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 3663 : },
225 : 2205 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 2205 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 2205 : },
229 : 2352 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 2352 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 2352 : },
233 : 3314 : [&] {
234 : : // size() and maxsize()
235 [ - + - + ]: 3314 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 3314 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 3314 : },
238 : 3220 : [&] {
239 : : // empty
240 [ - + ]: 3220 : assert(cdeq.empty() == cbitdeq.empty());
241 : 3220 : },
242 : 5577 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 5577 : if (!cdeq.empty()) {
245 [ - + ]: 4710 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 4710 : auto& ref = deq.at(pos);
247 : 4710 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 4710 : assert(ref == bitref);
249 [ + + ]: 4710 : if (ctx.randbool()) {
250 : 2324 : ref = !ref;
251 : 2324 : bitref.flip();
252 : : }
253 : 4710 : }
254 : 5577 : },
255 : 11025 : [&] {
256 : : // at (maybe out of range) and bit assign
257 [ - + ]: 11025 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 11025 : bool newval = ctx.randbool();
259 : 11025 : bool throw_deq{false}, throw_bitdeq{false};
260 : 11025 : bool val_deq{false}, val_bitdeq{false};
261 : 11025 : try {
262 [ + + ]: 11025 : auto& ref = deq.at(pos);
263 : 3870 : val_deq = ref;
264 : 3870 : ref = newval;
265 [ - + ]: 7155 : } catch (const std::out_of_range&) {
266 : 7155 : throw_deq = true;
267 : 7155 : }
268 : 11025 : try {
269 [ + + ]: 11025 : auto ref = bitdeq.at(pos);
270 : 3870 : val_bitdeq = ref;
271 : 3870 : ref = newval;
272 [ - + ]: 11025 : } catch (const std::out_of_range&) {
273 : 7155 : throw_bitdeq = true;
274 : 7155 : }
275 [ - + ]: 11025 : assert(throw_deq == throw_bitdeq);
276 [ - + - + ]: 11025 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 11025 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 11025 : },
279 : 2881 : [&] {
280 : : // at (maybe out of range) (const)
281 [ - + ]: 2881 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 2881 : bool throw_deq{false}, throw_bitdeq{false};
283 : 2881 : bool val_deq{false}, val_bitdeq{false};
284 : 2881 : try {
285 [ + + ]: 2881 : auto& ref = cdeq.at(pos);
286 : 1576 : val_deq = ref;
287 [ - + ]: 1305 : } catch (const std::out_of_range&) {
288 : 1305 : throw_deq = true;
289 : 1305 : }
290 : 2881 : try {
291 [ + + ]: 2881 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 1305 : } catch (const std::out_of_range&) {
294 : 1305 : throw_bitdeq = true;
295 : 1305 : }
296 [ - + ]: 2881 : assert(throw_deq == throw_bitdeq);
297 [ - + - + ]: 2881 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 2881 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 2881 : },
300 : 5797 : [&] {
301 : : // operator[]
302 [ + + ]: 5797 : if (!cdeq.empty()) {
303 [ - + ]: 5056 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 5056 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 5056 : if (ctx.randbool()) {
306 : 2524 : deq[pos] = !deq[pos];
307 : 2524 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 5797 : },
311 : 2961 : [&] {
312 : : // operator[] const
313 [ + + ]: 2961 : if (!cdeq.empty()) {
314 [ - + ]: 2280 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 2280 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 2961 : },
318 : 5595 : [&] {
319 : : // front()
320 [ + + ]: 5595 : if (!cdeq.empty()) {
321 [ - + ]: 4400 : auto& ref = deq.front();
322 : 4400 : auto bitref = bitdeq.front();
323 [ - + ]: 4400 : assert(ref == bitref);
324 [ + + ]: 4400 : if (ctx.randbool()) {
325 : 2096 : ref = !ref;
326 : 2096 : bitref = !bitref;
327 : : }
328 : 4400 : }
329 : 5595 : },
330 : 2370 : [&] {
331 : : // front() const
332 [ + + ]: 2370 : if (!cdeq.empty()) {
333 [ - + ]: 1678 : auto& ref = cdeq.front();
334 : 1678 : auto bitref = cbitdeq.front();
335 [ - + ]: 1678 : assert(ref == bitref);
336 : : }
337 : 2370 : },
338 : 6244 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 6244 : if (!cdeq.empty()) {
341 : 5166 : auto& ref = deq.back();
342 : 5166 : auto bitref = bitdeq.back();
343 [ - + ]: 5166 : assert(ref == bitref);
344 [ + + ]: 5166 : if (ctx.randbool()) {
345 : 2571 : ref = !ref;
346 : 2571 : bitref.flip();
347 : : }
348 : 5166 : }
349 : 6244 : },
350 : 5122 : [&] {
351 : : // back() const
352 [ + + ]: 5122 : if (!cdeq.empty()) {
353 : 3583 : const auto& cdeq = deq;
354 : 3583 : const auto& cbitdeq = bitdeq;
355 : 3583 : auto& ref = cdeq.back();
356 : 3583 : auto bitref = cbitdeq.back();
357 [ - + ]: 3583 : assert(ref == bitref);
358 : : }
359 : 5122 : },
360 : 8988 : [&] {
361 : : // push_back()
362 [ - + + + ]: 8988 : if (cdeq.size() < limitlen) {
363 : 7643 : bool val = ctx.randbool();
364 [ + + ]: 7643 : if (cdeq.empty()) {
365 : 3120 : deq.push_back(val);
366 : 3120 : bitdeq.push_back(val);
367 : : } else {
368 [ - + ]: 4523 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 4523 : auto& ref = deq[pos];
370 : 4523 : auto bitref = bitdeq[pos];
371 [ - + ]: 4523 : assert(ref == bitref);
372 : 4523 : deq.push_back(val);
373 : 4523 : bitdeq.push_back(val);
374 [ - + ]: 4523 : assert(ref == bitref); // references are not invalidated
375 : 4523 : }
376 : : }
377 : 8988 : },
378 : 11858 : [&] {
379 : : // push_front()
380 [ - + + + ]: 11858 : if (cdeq.size() < limitlen) {
381 : 11085 : bool val = ctx.randbool();
382 [ + + ]: 11085 : if (cdeq.empty()) {
383 : 4447 : deq.push_front(val);
384 : 4447 : bitdeq.push_front(val);
385 : : } else {
386 [ - + ]: 6638 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 6638 : auto& ref = deq[pos];
388 : 6638 : auto bitref = bitdeq[pos];
389 [ - + ]: 6638 : assert(ref == bitref);
390 : 6638 : deq.push_front(val);
391 : 6638 : bitdeq.push_front(val);
392 [ - + ]: 6638 : assert(ref == bitref); // references are not invalidated
393 : 6638 : }
394 : : }
395 : 11858 : },
396 : 6137 : [&] {
397 : : // pop_back()
398 [ + + ]: 6137 : if (!cdeq.empty()) {
399 [ - + + + ]: 4811 : if (cdeq.size() == 1) {
400 : 1473 : deq.pop_back();
401 : 1473 : bitdeq.pop_back();
402 : : } else {
403 : 3338 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 3338 : auto& ref = deq[pos];
405 : 3338 : auto bitref = bitdeq[pos];
406 [ - + ]: 3338 : assert(ref == bitref);
407 : 3338 : deq.pop_back();
408 : 3338 : bitdeq.pop_back();
409 [ - + ]: 3338 : assert(ref == bitref); // references to other elements are not invalidated
410 : 3338 : }
411 : : }
412 : 6137 : },
413 : 8200 : [&] {
414 : : // pop_front()
415 [ + + ]: 8200 : if (!cdeq.empty()) {
416 [ - + + + ]: 6437 : if (cdeq.size() == 1) {
417 : 2745 : deq.pop_front();
418 : 2745 : bitdeq.pop_front();
419 : : } else {
420 : 3692 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 3692 : auto& ref = deq[pos];
422 : 3692 : auto bitref = bitdeq[pos];
423 [ - + ]: 3692 : assert(ref == bitref);
424 : 3692 : deq.pop_front();
425 : 3692 : bitdeq.pop_front();
426 [ - + ]: 3692 : assert(ref == bitref); // references to other elements are not invalidated
427 : 3692 : }
428 : : }
429 : 8200 : },
430 : 9162 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 9162 : if (!cdeq.empty()) {
433 [ - + ]: 7735 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 [ - + ]: 7735 : size_t after = cdeq.size() - 1 - before;
435 : 7735 : auto it = deq.erase(cdeq.begin() + before);
436 : 7735 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 7735 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 15470 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 9162 : },
441 : 9330 : [&] {
442 : : // erase (at front, range)
443 [ - + ]: 9330 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 9330 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 9330 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 9330 : assert(it == deq.begin());
447 [ + - ]: 9330 : assert(bitit == bitdeq.begin());
448 : 9330 : },
449 : 3090 : [&] {
450 : : // erase (at back, range)
451 [ - + ]: 3090 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 3090 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 3090 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 3090 : assert(it == deq.end());
455 [ + - ]: 3090 : assert(bitit == bitdeq.end());
456 : 3090 : },
457 : 5674 : [&] {
458 : : // erase (in middle, range)
459 [ - + ]: 5674 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 [ - + ]: 5674 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 [ - + ]: 5674 : size_t after = cdeq.size() - count - before;
462 : 5674 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 5674 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 5674 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 11348 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 5674 : },
467 : 15657 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ - + + + ]: 15657 : if (cdeq.size() < limitlen) {
470 : 14956 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 14956 : bool val = ctx.randbool();
472 : 14956 : bool do_emplace = provider.ConsumeBool();
473 : 14956 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 14956 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 14956 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 14956 : assert(it == deq.begin() + before);
477 [ + - ]: 14956 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 15657 : },
480 : 10755 : [&] {
481 : : // insert (at front, begin/end)
482 [ - + + + ]: 10755 : if (cdeq.size() < limitlen) {
483 : 10157 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 10157 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 10157 : auto rand_end = rand_begin + count;
486 : 10157 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 10157 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 10157 : assert(it == cdeq.begin());
489 [ + - ]: 10157 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 10755 : },
492 : 7905 : [&] {
493 : : // insert (at back, begin/end)
494 [ - + + + ]: 7905 : if (cdeq.size() < limitlen) {
495 : 6539 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 6539 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 6539 : auto rand_end = rand_begin + count;
498 : 6539 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 6539 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 6539 : assert(it == cdeq.end() - count);
501 [ + - ]: 6539 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 7905 : },
504 : 33560 : [&] {
505 : : // insert (in middle, range)
506 [ - + + + ]: 33560 : if (cdeq.size() < limitlen) {
507 : 27821 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 [ - + ]: 27821 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 27821 : bool val = ctx.randbool();
510 : 27821 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 27821 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 27821 : assert(it == deq.begin() + before);
513 [ + - ]: 27821 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 33560 : },
516 : 21563 : [&] {
517 : : // insert (in middle, begin/end)
518 [ - + + + ]: 21563 : if (cdeq.size() < limitlen) {
519 : 18909 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 [ - + ]: 18909 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 18909 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 18909 : auto rand_end = rand_begin + count;
523 : 18909 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 18909 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 18909 : assert(it == deq.begin() + before);
526 [ + - ]: 18909 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 21563 : });
529 : : }
530 : 1172 : {
531 [ - + - + ]: 1172 : assert(deq.size() == bitdeq.size());
532 : 1172 : auto it = deq.begin();
533 : 1172 : auto bitit = bitdeq.begin();
534 : 1172 : auto itend = deq.end();
535 [ + + ]: 13667248 : while (it != itend) {
536 [ - + ]: 13666076 : assert(*it == *bitit);
537 : 13666076 : ++it;
538 : 13666076 : ++bitit;
539 : : }
540 : : }
541 : 1172 : }
|