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 [ + - ]: 1341 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 909 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 909 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 909 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 909 : std::deque<bool> deq;
43 [ + - ]: 909 : bitdeque_type bitdeq;
44 : :
45 : 909 : const auto& cdeq = deq;
46 : 909 : const auto& cbitdeq = bitdeq;
47 : :
48 : 909 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 6834839 : while (initlen) {
50 : 6833021 : bool val = ctx.randbool();
51 [ + - ]: 6833021 : deq.push_back(val);
52 [ + - ]: 6833021 : bitdeq.push_back(val);
53 : 6833021 : --initlen;
54 : : }
55 : :
56 [ + + ]: 909 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 332627 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 331718 : CallOneOf(
60 : : provider,
61 : 25860 : [&] {
62 : : // constructor()
63 : 51720 : deq = std::deque<bool>{};
64 : 25860 : bitdeq = bitdeque_type{};
65 : 25860 : },
66 : 6021 : [&] {
67 : : // clear()
68 : 6021 : deq.clear();
69 : 6021 : bitdeq.clear();
70 : 6021 : },
71 : 7967 : [&] {
72 : : // resize()
73 : 7967 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 7967 : deq.resize(count);
75 : 7967 : bitdeq.resize(count);
76 : 7967 : },
77 : 10354 : [&] {
78 : : // assign(count, val)
79 : 10354 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 10354 : bool val = ctx.randbool();
81 : 10354 : deq.assign(count, val);
82 : 10354 : bitdeq.assign(count, val);
83 : 10354 : },
84 : 3917 : [&] {
85 : : // constructor(count, val)
86 : 3917 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 3917 : bool val = ctx.randbool();
88 : 7834 : deq = std::deque<bool>(count, val);
89 : 3917 : bitdeq = bitdeque_type(count, val);
90 : 3917 : },
91 : 3003 : [&] {
92 : : // constructor(count)
93 : 3003 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 6006 : deq = std::deque<bool>(count);
95 : 3003 : bitdeq = bitdeque_type(count);
96 : 3003 : },
97 : 5703 : [&] {
98 : : // construct(begin, end)
99 : 5703 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 5703 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 5703 : auto rand_end = rand_begin + count;
102 : 11406 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 5703 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 5703 : },
105 : 9868 : [&] {
106 : : // assign(begin, end)
107 : 9868 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 9868 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 9868 : auto rand_end = rand_begin + count;
110 : 9868 : deq.assign(rand_begin, rand_end);
111 : 9868 : bitdeq.assign(rand_begin, rand_end);
112 : 9868 : },
113 : 8533 : [&] {
114 : : // construct(initializer_list)
115 : 8533 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 17066 : deq = std::deque<bool>(ilist);
117 : 8533 : bitdeq = bitdeque_type(ilist);
118 : 8533 : },
119 : 13860 : [&] {
120 : : // assign(initializer_list)
121 : 13860 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 13860 : deq.assign(ilist);
123 : 13860 : bitdeq.assign(ilist);
124 : 13860 : },
125 : 14676 : [&] {
126 : : // operator=(const&)
127 : 14676 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 14676 : bool val = ctx.randbool();
129 : 14676 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 14676 : deq = deq2;
131 [ + - ]: 14676 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 14676 : bitdeq = bitdeq2;
133 : 14676 : },
134 : 3788 : [&] {
135 : : // operator=(&&)
136 : 3788 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 3788 : bool val = ctx.randbool();
138 : 3788 : std::deque<bool> deq2(count, val);
139 : 3788 : deq = std::move(deq2);
140 [ + - ]: 3788 : bitdeque_type bitdeq2(count, val);
141 : 3788 : bitdeq = std::move(bitdeq2);
142 : 3788 : },
143 : 3952 : [&] {
144 : : // deque swap
145 : 3952 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 3952 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 3952 : auto rand_end = rand_begin + count;
148 : 3952 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 3952 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 3952 : using std::swap;
151 [ - + ]: 3952 : assert(deq.size() == bitdeq.size());
152 [ - + ]: 3952 : assert(deq2.size() == bitdeq2.size());
153 : 3952 : swap(deq, deq2);
154 : 3952 : swap(bitdeq, bitdeq2);
155 [ - + ]: 3952 : assert(deq.size() == bitdeq.size());
156 [ - + ]: 3952 : assert(deq2.size() == bitdeq2.size());
157 : 3952 : },
158 : 6440 : [&] {
159 : : // deque.swap
160 : 6440 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 6440 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 6440 : auto rand_end = rand_begin + count;
163 : 6440 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 6440 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + ]: 6440 : assert(deq.size() == bitdeq.size());
166 [ - + ]: 6440 : assert(deq2.size() == bitdeq2.size());
167 : 6440 : deq.swap(deq2);
168 : 6440 : bitdeq.swap(bitdeq2);
169 [ - + ]: 6440 : assert(deq.size() == bitdeq.size());
170 [ - + ]: 6440 : assert(deq2.size() == bitdeq2.size());
171 : 6440 : },
172 : 8151 : [&] {
173 : : // operator=(initializer_list)
174 : 8151 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 8151 : deq = ilist;
176 : 8151 : bitdeq = ilist;
177 : 8151 : },
178 : 6769 : [&] {
179 : : // iterator arithmetic
180 : 6769 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 : 6769 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 6769 : auto it = deq.begin() + pos1;
183 : 6769 : auto bitit = bitdeq.begin() + pos1;
184 [ + + - + ]: 6769 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
185 [ - + ]: 6769 : assert(it - deq.begin() == pos1);
186 [ - + ]: 6769 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 6769 : if (provider.ConsumeBool()) {
188 : 4072 : it += pos2 - pos1;
189 : 4072 : bitit += pos2 - pos1;
190 : : } else {
191 : 2697 : it -= pos1 - pos2;
192 : 2697 : bitit -= pos1 - pos2;
193 : : }
194 [ + + - + ]: 6769 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
195 [ - + ]: 6769 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 6769 : if (provider.ConsumeBool()) {
197 [ + + ]: 3830 : if ((size_t)pos2 != cdeq.size()) {
198 : 2743 : ++it;
199 : 2743 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 2939 : if (pos2 != 0) {
203 : 2028 : --it;
204 : 2028 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 6769 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 6769 : },
209 : 2493 : [&] {
210 : : // begin() and end()
211 [ - + ]: 2493 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 2493 : },
213 : 3450 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 3450 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 3450 : },
217 : 2938 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 2938 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 2938 : },
221 : 3002 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 3002 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 3002 : },
225 : 2041 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 2041 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 2041 : },
229 : 2282 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 2282 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 2282 : },
233 : 3386 : [&] {
234 : : // size() and maxsize()
235 [ - + ]: 3386 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 3386 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 3386 : },
238 : 2817 : [&] {
239 : : // empty
240 [ - + ]: 2817 : assert(cdeq.empty() == cbitdeq.empty());
241 : 2817 : },
242 : 5335 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 5335 : if (!cdeq.empty()) {
245 : 4440 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 4440 : auto& ref = deq.at(pos);
247 : 4440 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 4440 : assert(ref == bitref);
249 [ + + ]: 4440 : if (ctx.randbool()) {
250 : 2146 : ref = !ref;
251 : 2146 : bitref.flip();
252 : : }
253 : 4440 : }
254 : 5335 : },
255 : 11690 : [&] {
256 : : // at (maybe out of range) and bit assign
257 : 11690 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 11690 : bool newval = ctx.randbool();
259 : 11690 : bool throw_deq{false}, throw_bitdeq{false};
260 : 11690 : bool val_deq{false}, val_bitdeq{false};
261 : 11690 : try {
262 [ + + ]: 11690 : auto& ref = deq.at(pos);
263 : 4078 : val_deq = ref;
264 : 4078 : ref = newval;
265 [ - + ]: 7612 : } catch (const std::out_of_range&) {
266 : 7612 : throw_deq = true;
267 : 7612 : }
268 : 11690 : try {
269 [ + + ]: 11690 : auto ref = bitdeq.at(pos);
270 : 4078 : val_bitdeq = ref;
271 : 4078 : ref = newval;
272 [ - + ]: 11690 : } catch (const std::out_of_range&) {
273 : 7612 : throw_bitdeq = true;
274 : 7612 : }
275 [ - + ]: 11690 : assert(throw_deq == throw_bitdeq);
276 [ - + ]: 11690 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 11690 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 11690 : },
279 : 2111 : [&] {
280 : : // at (maybe out of range) (const)
281 : 2111 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 2111 : bool throw_deq{false}, throw_bitdeq{false};
283 : 2111 : bool val_deq{false}, val_bitdeq{false};
284 : 2111 : try {
285 [ + + ]: 2111 : auto& ref = cdeq.at(pos);
286 : 1095 : val_deq = ref;
287 [ - + ]: 1016 : } catch (const std::out_of_range&) {
288 : 1016 : throw_deq = true;
289 : 1016 : }
290 : 2111 : try {
291 [ + + ]: 2111 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 1016 : } catch (const std::out_of_range&) {
294 : 1016 : throw_bitdeq = true;
295 : 1016 : }
296 [ - + ]: 2111 : assert(throw_deq == throw_bitdeq);
297 [ - + ]: 2111 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 2111 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 2111 : },
300 : 5344 : [&] {
301 : : // operator[]
302 [ + + ]: 5344 : if (!cdeq.empty()) {
303 : 4710 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 4710 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 4710 : if (ctx.randbool()) {
306 : 2362 : deq[pos] = !deq[pos];
307 : 2362 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 5344 : },
311 : 2439 : [&] {
312 : : // operator[] const
313 [ + + ]: 2439 : if (!cdeq.empty()) {
314 : 1565 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 1565 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 2439 : },
318 : 4713 : [&] {
319 : : // front()
320 [ + + ]: 4713 : if (!cdeq.empty()) {
321 [ - + ]: 3952 : auto& ref = deq.front();
322 : 3952 : auto bitref = bitdeq.front();
323 [ - + ]: 3952 : assert(ref == bitref);
324 [ + + ]: 3952 : if (ctx.randbool()) {
325 : 1951 : ref = !ref;
326 : 1951 : bitref = !bitref;
327 : : }
328 : 3952 : }
329 : 4713 : },
330 : 2438 : [&] {
331 : : // front() const
332 [ + + ]: 2438 : if (!cdeq.empty()) {
333 [ - + ]: 1615 : auto& ref = cdeq.front();
334 : 1615 : auto bitref = cbitdeq.front();
335 [ - + ]: 1615 : assert(ref == bitref);
336 : : }
337 : 2438 : },
338 : 4774 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 4774 : if (!cdeq.empty()) {
341 : 3904 : auto& ref = deq.back();
342 : 3904 : auto bitref = bitdeq.back();
343 [ - + ]: 3904 : assert(ref == bitref);
344 [ + + ]: 3904 : if (ctx.randbool()) {
345 : 1976 : ref = !ref;
346 : 1976 : bitref.flip();
347 : : }
348 : 3904 : }
349 : 4774 : },
350 : 4291 : [&] {
351 : : // back() const
352 [ + + ]: 4291 : if (!cdeq.empty()) {
353 : 3207 : const auto& cdeq = deq;
354 : 3207 : const auto& cbitdeq = bitdeq;
355 : 3207 : auto& ref = cdeq.back();
356 : 3207 : auto bitref = cbitdeq.back();
357 [ - + ]: 3207 : assert(ref == bitref);
358 : : }
359 : 4291 : },
360 : 7402 : [&] {
361 : : // push_back()
362 [ + + ]: 7402 : if (cdeq.size() < limitlen) {
363 : 6466 : bool val = ctx.randbool();
364 [ + + ]: 6466 : if (cdeq.empty()) {
365 : 2331 : deq.push_back(val);
366 : 2331 : bitdeq.push_back(val);
367 : : } else {
368 : 4135 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 4135 : auto& ref = deq[pos];
370 : 4135 : auto bitref = bitdeq[pos];
371 [ - + ]: 4135 : assert(ref == bitref);
372 : 4135 : deq.push_back(val);
373 : 4135 : bitdeq.push_back(val);
374 [ - + ]: 4135 : assert(ref == bitref); // references are not invalidated
375 : 4135 : }
376 : : }
377 : 7402 : },
378 : 11393 : [&] {
379 : : // push_front()
380 [ + + ]: 11393 : if (cdeq.size() < limitlen) {
381 : 10434 : bool val = ctx.randbool();
382 [ + + ]: 10434 : if (cdeq.empty()) {
383 : 3663 : deq.push_front(val);
384 : 3663 : bitdeq.push_front(val);
385 : : } else {
386 : 6771 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 6771 : auto& ref = deq[pos];
388 : 6771 : auto bitref = bitdeq[pos];
389 [ - + ]: 6771 : assert(ref == bitref);
390 : 6771 : deq.push_front(val);
391 : 6771 : bitdeq.push_front(val);
392 [ - + ]: 6771 : assert(ref == bitref); // references are not invalidated
393 : 6771 : }
394 : : }
395 : 11393 : },
396 : 6239 : [&] {
397 : : // pop_back()
398 [ + + ]: 6239 : if (!cdeq.empty()) {
399 [ + + ]: 5188 : if (cdeq.size() == 1) {
400 : 1446 : deq.pop_back();
401 : 1446 : bitdeq.pop_back();
402 : : } else {
403 : 3742 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 3742 : auto& ref = deq[pos];
405 : 3742 : auto bitref = bitdeq[pos];
406 [ - + ]: 3742 : assert(ref == bitref);
407 : 3742 : deq.pop_back();
408 : 3742 : bitdeq.pop_back();
409 [ - + ]: 3742 : assert(ref == bitref); // references to other elements are not invalidated
410 : 3742 : }
411 : : }
412 : 6239 : },
413 : 7051 : [&] {
414 : : // pop_front()
415 [ + + ]: 7051 : if (!cdeq.empty()) {
416 [ + + ]: 5320 : if (cdeq.size() == 1) {
417 : 2269 : deq.pop_front();
418 : 2269 : bitdeq.pop_front();
419 : : } else {
420 : 3051 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 3051 : auto& ref = deq[pos];
422 : 3051 : auto bitref = bitdeq[pos];
423 [ - + ]: 3051 : assert(ref == bitref);
424 : 3051 : deq.pop_front();
425 : 3051 : bitdeq.pop_front();
426 [ - + ]: 3051 : assert(ref == bitref); // references to other elements are not invalidated
427 : 3051 : }
428 : : }
429 : 7051 : },
430 : 7760 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 7760 : if (!cdeq.empty()) {
433 : 6421 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 : 6421 : size_t after = cdeq.size() - 1 - before;
435 : 6421 : auto it = deq.erase(cdeq.begin() + before);
436 : 6421 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 6421 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 12842 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 7760 : },
441 : 8071 : [&] {
442 : : // erase (at front, range)
443 : 8071 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 8071 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 8071 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 8071 : assert(it == deq.begin());
447 [ + - ]: 8071 : assert(bitit == bitdeq.begin());
448 : 8071 : },
449 : 3434 : [&] {
450 : : // erase (at back, range)
451 : 3434 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 3434 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 3434 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 3434 : assert(it == deq.end());
455 [ + - ]: 3434 : assert(bitit == bitdeq.end());
456 : 3434 : },
457 : 5706 : [&] {
458 : : // erase (in middle, range)
459 : 5706 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 : 5706 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 : 5706 : size_t after = cdeq.size() - count - before;
462 : 5706 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 5706 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 5706 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 11412 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 5706 : },
467 : 12155 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ + + ]: 12155 : if (cdeq.size() < limitlen) {
470 : 11530 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 11530 : bool val = ctx.randbool();
472 : 11530 : bool do_emplace = provider.ConsumeBool();
473 : 11530 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 11530 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 11530 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 11530 : assert(it == deq.begin() + before);
477 [ + - ]: 11530 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 12155 : },
480 : 8291 : [&] {
481 : : // insert (at front, begin/end)
482 [ + + ]: 8291 : if (cdeq.size() < limitlen) {
483 : 7672 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 7672 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 7672 : auto rand_end = rand_begin + count;
486 : 7672 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 7672 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 7672 : assert(it == cdeq.begin());
489 [ + - ]: 7672 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 8291 : },
492 : 8487 : [&] {
493 : : // insert (at back, begin/end)
494 [ + + ]: 8487 : if (cdeq.size() < limitlen) {
495 : 7255 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 7255 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 7255 : auto rand_end = rand_begin + count;
498 : 7255 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 7255 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 7255 : assert(it == cdeq.end() - count);
501 [ + - ]: 7255 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 8487 : },
504 : 23189 : [&] {
505 : : // insert (in middle, range)
506 [ + + ]: 23189 : if (cdeq.size() < limitlen) {
507 : 19276 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 : 19276 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 19276 : bool val = ctx.randbool();
510 : 19276 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 19276 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 19276 : assert(it == deq.begin() + before);
513 [ + - ]: 19276 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 23189 : },
516 : 18134 : [&] {
517 : : // insert (in middle, begin/end)
518 [ + + ]: 18134 : if (cdeq.size() < limitlen) {
519 : 15761 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 : 15761 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 15761 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 15761 : auto rand_end = rand_begin + count;
523 : 15761 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 15761 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 15761 : assert(it == deq.begin() + before);
526 [ + - ]: 15761 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 18134 : });
529 : : }
530 : 909 : {
531 [ - + ]: 909 : assert(deq.size() == bitdeq.size());
532 : 909 : auto it = deq.begin();
533 : 909 : auto bitit = bitdeq.begin();
534 : 909 : auto itend = deq.end();
535 [ + + ]: 9551444 : while (it != itend) {
536 [ - + ]: 9550535 : assert(*it == *bitit);
537 : 9550535 : ++it;
538 : 9550535 : ++bitit;
539 : : }
540 : : }
541 : 909 : }
|