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 [ + - ]: 1188 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 746 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 746 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 746 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 746 : std::deque<bool> deq;
43 [ + - ]: 746 : bitdeque_type bitdeq;
44 : :
45 : 746 : const auto& cdeq = deq;
46 : 746 : const auto& cbitdeq = bitdeq;
47 : :
48 : 746 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 5661133 : while (initlen) {
50 : 5659641 : bool val = ctx.randbool();
51 [ + - ]: 5659641 : deq.push_back(val);
52 [ + - ]: 5659641 : bitdeq.push_back(val);
53 : 5659641 : --initlen;
54 : : }
55 : :
56 [ + + ]: 746 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 255946 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 255200 : CallOneOf(
60 : : provider,
61 : 18159 : [&] {
62 : : // constructor()
63 : 36318 : deq = std::deque<bool>{};
64 : 18159 : bitdeq = bitdeque_type{};
65 : 18159 : },
66 : 4063 : [&] {
67 : : // clear()
68 : 4063 : deq.clear();
69 : 4063 : bitdeq.clear();
70 : 4063 : },
71 : 6264 : [&] {
72 : : // resize()
73 : 6264 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 6264 : deq.resize(count);
75 : 6264 : bitdeq.resize(count);
76 : 6264 : },
77 : 9032 : [&] {
78 : : // assign(count, val)
79 : 9032 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 9032 : bool val = ctx.randbool();
81 : 9032 : deq.assign(count, val);
82 : 9032 : bitdeq.assign(count, val);
83 : 9032 : },
84 : 2605 : [&] {
85 : : // constructor(count, val)
86 : 2605 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 2605 : bool val = ctx.randbool();
88 : 5210 : deq = std::deque<bool>(count, val);
89 : 2605 : bitdeq = bitdeque_type(count, val);
90 : 2605 : },
91 : 2005 : [&] {
92 : : // constructor(count)
93 : 2005 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 4010 : deq = std::deque<bool>(count);
95 : 2005 : bitdeq = bitdeque_type(count);
96 : 2005 : },
97 : 4361 : [&] {
98 : : // construct(begin, end)
99 : 4361 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 4361 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 4361 : auto rand_end = rand_begin + count;
102 : 8722 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 4361 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 4361 : },
105 : 9282 : [&] {
106 : : // assign(begin, end)
107 : 9282 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 9282 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 9282 : auto rand_end = rand_begin + count;
110 : 9282 : deq.assign(rand_begin, rand_end);
111 : 9282 : bitdeq.assign(rand_begin, rand_end);
112 : 9282 : },
113 : 7277 : [&] {
114 : : // construct(initializer_list)
115 : 7277 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 14554 : deq = std::deque<bool>(ilist);
117 : 7277 : bitdeq = bitdeque_type(ilist);
118 : 7277 : },
119 : 11122 : [&] {
120 : : // assign(initializer_list)
121 : 11122 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 11122 : deq.assign(ilist);
123 : 11122 : bitdeq.assign(ilist);
124 : 11122 : },
125 : 11565 : [&] {
126 : : // operator=(const&)
127 : 11565 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 11565 : bool val = ctx.randbool();
129 : 11565 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 11565 : deq = deq2;
131 [ + - ]: 11565 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 11565 : bitdeq = bitdeq2;
133 : 11565 : },
134 : 2984 : [&] {
135 : : // operator=(&&)
136 : 2984 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 2984 : bool val = ctx.randbool();
138 : 2984 : std::deque<bool> deq2(count, val);
139 : 2984 : deq = std::move(deq2);
140 [ + - ]: 2984 : bitdeque_type bitdeq2(count, val);
141 : 2984 : bitdeq = std::move(bitdeq2);
142 : 2984 : },
143 : 3360 : [&] {
144 : : // deque swap
145 : 3360 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 3360 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 3360 : auto rand_end = rand_begin + count;
148 : 3360 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 3360 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 3360 : using std::swap;
151 [ - + ]: 3360 : assert(deq.size() == bitdeq.size());
152 [ - + ]: 3360 : assert(deq2.size() == bitdeq2.size());
153 : 3360 : swap(deq, deq2);
154 : 3360 : swap(bitdeq, bitdeq2);
155 [ - + ]: 3360 : assert(deq.size() == bitdeq.size());
156 [ - + ]: 3360 : assert(deq2.size() == bitdeq2.size());
157 : 3360 : },
158 : 5954 : [&] {
159 : : // deque.swap
160 : 5954 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 5954 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 5954 : auto rand_end = rand_begin + count;
163 : 5954 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 5954 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + ]: 5954 : assert(deq.size() == bitdeq.size());
166 [ - + ]: 5954 : assert(deq2.size() == bitdeq2.size());
167 : 5954 : deq.swap(deq2);
168 : 5954 : bitdeq.swap(bitdeq2);
169 [ - + ]: 5954 : assert(deq.size() == bitdeq.size());
170 [ - + ]: 5954 : assert(deq2.size() == bitdeq2.size());
171 : 5954 : },
172 : 7003 : [&] {
173 : : // operator=(initializer_list)
174 : 7003 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 7003 : deq = ilist;
176 : 7003 : bitdeq = ilist;
177 : 7003 : },
178 : 4609 : [&] {
179 : : // iterator arithmetic
180 : 4609 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 : 4609 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 4609 : auto it = deq.begin() + pos1;
183 : 4609 : auto bitit = bitdeq.begin() + pos1;
184 [ + + - + ]: 4609 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
185 [ - + ]: 4609 : assert(it - deq.begin() == pos1);
186 [ - + ]: 4609 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 4609 : if (provider.ConsumeBool()) {
188 : 2732 : it += pos2 - pos1;
189 : 2732 : bitit += pos2 - pos1;
190 : : } else {
191 : 1877 : it -= pos1 - pos2;
192 : 1877 : bitit -= pos1 - pos2;
193 : : }
194 [ + + - + ]: 4609 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
195 [ - + ]: 4609 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 4609 : if (provider.ConsumeBool()) {
197 [ + + ]: 2580 : if ((size_t)pos2 != cdeq.size()) {
198 : 1938 : ++it;
199 : 1938 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 2029 : if (pos2 != 0) {
203 : 1502 : --it;
204 : 1502 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 4609 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 4609 : },
209 : 1887 : [&] {
210 : : // begin() and end()
211 [ - + ]: 1887 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 1887 : },
213 : 2434 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 2434 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 2434 : },
217 : 2023 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 2023 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 2023 : },
221 : 1432 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 1432 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 1432 : },
225 : 1416 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 1416 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 1416 : },
229 : 1684 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 1684 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 1684 : },
233 : 2450 : [&] {
234 : : // size() and maxsize()
235 [ - + ]: 2450 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 2450 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 2450 : },
238 : 1881 : [&] {
239 : : // empty
240 [ - + ]: 1881 : assert(cdeq.empty() == cbitdeq.empty());
241 : 1881 : },
242 : 3367 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 3367 : if (!cdeq.empty()) {
245 : 2892 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 2892 : auto& ref = deq.at(pos);
247 : 2892 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 2892 : assert(ref == bitref);
249 [ + + ]: 2892 : if (ctx.randbool()) {
250 : 1433 : ref = !ref;
251 : 1433 : bitref.flip();
252 : : }
253 : 2892 : }
254 : 3367 : },
255 : 7747 : [&] {
256 : : // at (maybe out of range) and bit assign
257 : 7747 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 7747 : bool newval = ctx.randbool();
259 : 7747 : bool throw_deq{false}, throw_bitdeq{false};
260 : 7747 : bool val_deq{false}, val_bitdeq{false};
261 : 7747 : try {
262 [ + + ]: 7747 : auto& ref = deq.at(pos);
263 : 2378 : val_deq = ref;
264 : 2378 : ref = newval;
265 [ - + ]: 5369 : } catch (const std::out_of_range&) {
266 : 5369 : throw_deq = true;
267 : 5369 : }
268 : 7747 : try {
269 [ + + ]: 7747 : auto ref = bitdeq.at(pos);
270 : 2378 : val_bitdeq = ref;
271 : 2378 : ref = newval;
272 [ - + ]: 7747 : } catch (const std::out_of_range&) {
273 : 5369 : throw_bitdeq = true;
274 : 5369 : }
275 [ - + ]: 7747 : assert(throw_deq == throw_bitdeq);
276 [ - + ]: 7747 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 7747 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 7747 : },
279 : 1750 : [&] {
280 : : // at (maybe out of range) (const)
281 : 1750 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 1750 : bool throw_deq{false}, throw_bitdeq{false};
283 : 1750 : bool val_deq{false}, val_bitdeq{false};
284 : 1750 : try {
285 [ + + ]: 1750 : auto& ref = cdeq.at(pos);
286 : 1050 : val_deq = ref;
287 [ - + ]: 700 : } catch (const std::out_of_range&) {
288 : 700 : throw_deq = true;
289 : 700 : }
290 : 1750 : try {
291 [ + + ]: 1750 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 700 : } catch (const std::out_of_range&) {
294 : 700 : throw_bitdeq = true;
295 : 700 : }
296 [ - + ]: 1750 : assert(throw_deq == throw_bitdeq);
297 [ - + ]: 1750 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 1750 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 1750 : },
300 : 4331 : [&] {
301 : : // operator[]
302 [ + + ]: 4331 : if (!cdeq.empty()) {
303 : 3775 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 3775 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 3775 : if (ctx.randbool()) {
306 : 1908 : deq[pos] = !deq[pos];
307 : 1908 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 4331 : },
311 : 1662 : [&] {
312 : : // operator[] const
313 [ + + ]: 1662 : if (!cdeq.empty()) {
314 : 1249 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 1249 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 1662 : },
318 : 3647 : [&] {
319 : : // front()
320 [ + + ]: 3647 : if (!cdeq.empty()) {
321 [ - + ]: 2992 : auto& ref = deq.front();
322 : 2992 : auto bitref = bitdeq.front();
323 [ - + ]: 2992 : assert(ref == bitref);
324 [ + + ]: 2992 : if (ctx.randbool()) {
325 : 1428 : ref = !ref;
326 : 1428 : bitref = !bitref;
327 : : }
328 : 2992 : }
329 : 3647 : },
330 : 1318 : [&] {
331 : : // front() const
332 [ + + ]: 1318 : if (!cdeq.empty()) {
333 [ - + ]: 965 : auto& ref = cdeq.front();
334 : 965 : auto bitref = cbitdeq.front();
335 [ - + ]: 965 : assert(ref == bitref);
336 : : }
337 : 1318 : },
338 : 4652 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 4652 : if (!cdeq.empty()) {
341 : 4010 : auto& ref = deq.back();
342 : 4010 : auto bitref = bitdeq.back();
343 [ - + ]: 4010 : assert(ref == bitref);
344 [ + + ]: 4010 : if (ctx.randbool()) {
345 : 2052 : ref = !ref;
346 : 2052 : bitref.flip();
347 : : }
348 : 4010 : }
349 : 4652 : },
350 : 3524 : [&] {
351 : : // back() const
352 [ + + ]: 3524 : if (!cdeq.empty()) {
353 : 2560 : const auto& cdeq = deq;
354 : 2560 : const auto& cbitdeq = bitdeq;
355 : 2560 : auto& ref = cdeq.back();
356 : 2560 : auto bitref = cbitdeq.back();
357 [ - + ]: 2560 : assert(ref == bitref);
358 : : }
359 : 3524 : },
360 : 5719 : [&] {
361 : : // push_back()
362 [ + + ]: 5719 : if (cdeq.size() < limitlen) {
363 : 4904 : bool val = ctx.randbool();
364 [ + + ]: 4904 : if (cdeq.empty()) {
365 : 1850 : deq.push_back(val);
366 : 1850 : bitdeq.push_back(val);
367 : : } else {
368 : 3054 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 3054 : auto& ref = deq[pos];
370 : 3054 : auto bitref = bitdeq[pos];
371 [ - + ]: 3054 : assert(ref == bitref);
372 : 3054 : deq.push_back(val);
373 : 3054 : bitdeq.push_back(val);
374 [ - + ]: 3054 : assert(ref == bitref); // references are not invalidated
375 : 3054 : }
376 : : }
377 : 5719 : },
378 : 7115 : [&] {
379 : : // push_front()
380 [ + + ]: 7115 : if (cdeq.size() < limitlen) {
381 : 6451 : bool val = ctx.randbool();
382 [ + + ]: 6451 : if (cdeq.empty()) {
383 : 2325 : deq.push_front(val);
384 : 2325 : bitdeq.push_front(val);
385 : : } else {
386 : 4126 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 4126 : auto& ref = deq[pos];
388 : 4126 : auto bitref = bitdeq[pos];
389 [ - + ]: 4126 : assert(ref == bitref);
390 : 4126 : deq.push_front(val);
391 : 4126 : bitdeq.push_front(val);
392 [ - + ]: 4126 : assert(ref == bitref); // references are not invalidated
393 : 4126 : }
394 : : }
395 : 7115 : },
396 : 4044 : [&] {
397 : : // pop_back()
398 [ + + ]: 4044 : if (!cdeq.empty()) {
399 [ + + ]: 3236 : if (cdeq.size() == 1) {
400 : 1172 : deq.pop_back();
401 : 1172 : bitdeq.pop_back();
402 : : } else {
403 : 2064 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 2064 : auto& ref = deq[pos];
405 : 2064 : auto bitref = bitdeq[pos];
406 [ - + ]: 2064 : assert(ref == bitref);
407 : 2064 : deq.pop_back();
408 : 2064 : bitdeq.pop_back();
409 [ - + ]: 2064 : assert(ref == bitref); // references to other elements are not invalidated
410 : 2064 : }
411 : : }
412 : 4044 : },
413 : 4391 : [&] {
414 : : // pop_front()
415 [ + + ]: 4391 : if (!cdeq.empty()) {
416 [ + + ]: 3109 : if (cdeq.size() == 1) {
417 : 1041 : deq.pop_front();
418 : 1041 : bitdeq.pop_front();
419 : : } else {
420 : 2068 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 2068 : auto& ref = deq[pos];
422 : 2068 : auto bitref = bitdeq[pos];
423 [ - + ]: 2068 : assert(ref == bitref);
424 : 2068 : deq.pop_front();
425 : 2068 : bitdeq.pop_front();
426 [ - + ]: 2068 : assert(ref == bitref); // references to other elements are not invalidated
427 : 2068 : }
428 : : }
429 : 4391 : },
430 : 5839 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 5839 : if (!cdeq.empty()) {
433 : 4892 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 : 4892 : size_t after = cdeq.size() - 1 - before;
435 : 4892 : auto it = deq.erase(cdeq.begin() + before);
436 : 4892 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 4892 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 9784 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 5839 : },
441 : 6424 : [&] {
442 : : // erase (at front, range)
443 : 6424 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 6424 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 6424 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 6424 : assert(it == deq.begin());
447 [ + - ]: 6424 : assert(bitit == bitdeq.begin());
448 : 6424 : },
449 : 2139 : [&] {
450 : : // erase (at back, range)
451 : 2139 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 2139 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 2139 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 2139 : assert(it == deq.end());
455 [ + - ]: 2139 : assert(bitit == bitdeq.end());
456 : 2139 : },
457 : 3936 : [&] {
458 : : // erase (in middle, range)
459 : 3936 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 : 3936 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 : 3936 : size_t after = cdeq.size() - count - before;
462 : 3936 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 3936 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 3936 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 7872 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 3936 : },
467 : 9237 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ + + ]: 9237 : if (cdeq.size() < limitlen) {
470 : 8779 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 8779 : bool val = ctx.randbool();
472 : 8779 : bool do_emplace = provider.ConsumeBool();
473 : 8779 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 8779 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 8779 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 8779 : assert(it == deq.begin() + before);
477 [ + - ]: 8779 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 9237 : },
480 : 7182 : [&] {
481 : : // insert (at front, begin/end)
482 [ + + ]: 7182 : if (cdeq.size() < limitlen) {
483 : 6798 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 6798 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 6798 : auto rand_end = rand_begin + count;
486 : 6798 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 6798 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 6798 : assert(it == cdeq.begin());
489 [ + - ]: 6798 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 7182 : },
492 : 6313 : [&] {
493 : : // insert (at back, begin/end)
494 [ + + ]: 6313 : if (cdeq.size() < limitlen) {
495 : 5231 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 5231 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 5231 : auto rand_end = rand_begin + count;
498 : 5231 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 5231 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 5231 : assert(it == cdeq.end() - count);
501 [ + - ]: 5231 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 6313 : },
504 : 18492 : [&] {
505 : : // insert (in middle, range)
506 [ + + ]: 18492 : if (cdeq.size() < limitlen) {
507 : 15381 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 : 15381 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 15381 : bool val = ctx.randbool();
510 : 15381 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 15381 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 15381 : assert(it == deq.begin() + before);
513 [ + - ]: 15381 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 18492 : },
516 : 17519 : [&] {
517 : : // insert (in middle, begin/end)
518 [ + + ]: 17519 : if (cdeq.size() < limitlen) {
519 : 14911 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 : 14911 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 14911 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 14911 : auto rand_end = rand_begin + count;
523 : 14911 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 14911 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 14911 : assert(it == deq.begin() + before);
526 [ + - ]: 14911 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 17519 : });
529 : : }
530 : 746 : {
531 [ - + ]: 746 : assert(deq.size() == bitdeq.size());
532 : 746 : auto it = deq.begin();
533 : 746 : auto bitit = bitdeq.begin();
534 : 746 : auto itend = deq.end();
535 [ + + ]: 8942709 : while (it != itend) {
536 [ - + ]: 8941963 : assert(*it == *bitit);
537 : 8941963 : ++it;
538 : 8941963 : ++bitit;
539 : : }
540 : : }
541 : 746 : }
|