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 [ + - ]: 1560 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 1106 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 1106 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 1106 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 1106 : std::deque<bool> deq;
43 [ + - ]: 1106 : bitdeque_type bitdeq;
44 : :
45 : 1106 : const auto& cdeq = deq;
46 : 1106 : const auto& cbitdeq = bitdeq;
47 : :
48 : 1106 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 8991965 : while (initlen) {
50 : 8989753 : bool val = ctx.randbool();
51 [ + - ]: 8989753 : deq.push_back(val);
52 [ + - ]: 8989753 : bitdeq.push_back(val);
53 : 8989753 : --initlen;
54 : : }
55 : :
56 [ + + ]: 1106 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 370166 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 369060 : CallOneOf(
60 : : provider,
61 : 26468 : [&] {
62 : : // constructor()
63 : 52936 : deq = std::deque<bool>{};
64 : 26468 : bitdeq = bitdeque_type{};
65 : 26468 : },
66 : 5902 : [&] {
67 : : // clear()
68 : 5902 : deq.clear();
69 : 5902 : bitdeq.clear();
70 : 5902 : },
71 : 8678 : [&] {
72 : : // resize()
73 : 8678 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 8678 : deq.resize(count);
75 : 8678 : bitdeq.resize(count);
76 : 8678 : },
77 : 12176 : [&] {
78 : : // assign(count, val)
79 : 12176 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 12176 : bool val = ctx.randbool();
81 : 12176 : deq.assign(count, val);
82 : 12176 : bitdeq.assign(count, val);
83 : 12176 : },
84 : 4319 : [&] {
85 : : // constructor(count, val)
86 : 4319 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 4319 : bool val = ctx.randbool();
88 : 8638 : deq = std::deque<bool>(count, val);
89 : 4319 : bitdeq = bitdeque_type(count, val);
90 : 4319 : },
91 : 3246 : [&] {
92 : : // constructor(count)
93 : 3246 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 6492 : deq = std::deque<bool>(count);
95 : 3246 : bitdeq = bitdeque_type(count);
96 : 3246 : },
97 : 6607 : [&] {
98 : : // construct(begin, end)
99 : 6607 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 6607 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 6607 : auto rand_end = rand_begin + count;
102 : 13214 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 6607 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 6607 : },
105 : 12230 : [&] {
106 : : // assign(begin, end)
107 : 12230 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 12230 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 12230 : auto rand_end = rand_begin + count;
110 : 12230 : deq.assign(rand_begin, rand_end);
111 : 12230 : bitdeq.assign(rand_begin, rand_end);
112 : 12230 : },
113 : 11509 : [&] {
114 : : // construct(initializer_list)
115 : 11509 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 23018 : deq = std::deque<bool>(ilist);
117 : 11509 : bitdeq = bitdeque_type(ilist);
118 : 11509 : },
119 : 16960 : [&] {
120 : : // assign(initializer_list)
121 : 16960 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 16960 : deq.assign(ilist);
123 : 16960 : bitdeq.assign(ilist);
124 : 16960 : },
125 : 17063 : [&] {
126 : : // operator=(const&)
127 : 17063 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 17063 : bool val = ctx.randbool();
129 : 17063 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 17063 : deq = deq2;
131 [ + - ]: 17063 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 17063 : bitdeq = bitdeq2;
133 : 17063 : },
134 : 4923 : [&] {
135 : : // operator=(&&)
136 : 4923 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 4923 : bool val = ctx.randbool();
138 : 4923 : std::deque<bool> deq2(count, val);
139 : 4923 : deq = std::move(deq2);
140 [ + - ]: 4923 : bitdeque_type bitdeq2(count, val);
141 : 4923 : bitdeq = std::move(bitdeq2);
142 : 4923 : },
143 : 4784 : [&] {
144 : : // deque swap
145 : 4784 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 4784 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 4784 : auto rand_end = rand_begin + count;
148 : 4784 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 4784 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 4784 : using std::swap;
151 [ - + ]: 4784 : assert(deq.size() == bitdeq.size());
152 [ - + ]: 4784 : assert(deq2.size() == bitdeq2.size());
153 : 4784 : swap(deq, deq2);
154 : 4784 : swap(bitdeq, bitdeq2);
155 [ - + ]: 4784 : assert(deq.size() == bitdeq.size());
156 [ - + ]: 4784 : assert(deq2.size() == bitdeq2.size());
157 : 4784 : },
158 : 6985 : [&] {
159 : : // deque.swap
160 : 6985 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 6985 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 6985 : auto rand_end = rand_begin + count;
163 : 6985 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 6985 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + ]: 6985 : assert(deq.size() == bitdeq.size());
166 [ - + ]: 6985 : assert(deq2.size() == bitdeq2.size());
167 : 6985 : deq.swap(deq2);
168 : 6985 : bitdeq.swap(bitdeq2);
169 [ - + ]: 6985 : assert(deq.size() == bitdeq.size());
170 [ - + ]: 6985 : assert(deq2.size() == bitdeq2.size());
171 : 6985 : },
172 : 9263 : [&] {
173 : : // operator=(initializer_list)
174 : 9263 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 9263 : deq = ilist;
176 : 9263 : bitdeq = ilist;
177 : 9263 : },
178 : 7303 : [&] {
179 : : // iterator arithmetic
180 : 7303 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 : 7303 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 7303 : auto it = deq.begin() + pos1;
183 : 7303 : auto bitit = bitdeq.begin() + pos1;
184 [ + + - + ]: 7303 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
185 [ - + ]: 7303 : assert(it - deq.begin() == pos1);
186 [ - + ]: 7303 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 7303 : if (provider.ConsumeBool()) {
188 : 4127 : it += pos2 - pos1;
189 : 4127 : bitit += pos2 - pos1;
190 : : } else {
191 : 3176 : it -= pos1 - pos2;
192 : 3176 : bitit -= pos1 - pos2;
193 : : }
194 [ + + - + ]: 7303 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
195 [ - + ]: 7303 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 7303 : if (provider.ConsumeBool()) {
197 [ + + ]: 3941 : if ((size_t)pos2 != cdeq.size()) {
198 : 2811 : ++it;
199 : 2811 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 3362 : if (pos2 != 0) {
203 : 2325 : --it;
204 : 2325 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 7303 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 7303 : },
209 : 3042 : [&] {
210 : : // begin() and end()
211 [ - + ]: 3042 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 3042 : },
213 : 3842 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 3842 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 3842 : },
217 : 3231 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 3231 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 3231 : },
221 : 2983 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 2983 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 2983 : },
225 : 2164 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 2164 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 2164 : },
229 : 2511 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 2511 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 2511 : },
233 : 3256 : [&] {
234 : : // size() and maxsize()
235 [ - + ]: 3256 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 3256 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 3256 : },
238 : 2938 : [&] {
239 : : // empty
240 [ - + ]: 2938 : assert(cdeq.empty() == cbitdeq.empty());
241 : 2938 : },
242 : 5022 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 5022 : if (!cdeq.empty()) {
245 : 4242 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 4242 : auto& ref = deq.at(pos);
247 : 4242 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 4242 : assert(ref == bitref);
249 [ + + ]: 4242 : if (ctx.randbool()) {
250 : 2122 : ref = !ref;
251 : 2122 : bitref.flip();
252 : : }
253 : 4242 : }
254 : 5022 : },
255 : 11005 : [&] {
256 : : // at (maybe out of range) and bit assign
257 : 11005 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 11005 : bool newval = ctx.randbool();
259 : 11005 : bool throw_deq{false}, throw_bitdeq{false};
260 : 11005 : bool val_deq{false}, val_bitdeq{false};
261 : 11005 : try {
262 [ + + ]: 11005 : auto& ref = deq.at(pos);
263 : 3309 : val_deq = ref;
264 : 3309 : ref = newval;
265 [ - + ]: 7696 : } catch (const std::out_of_range&) {
266 : 7696 : throw_deq = true;
267 : 7696 : }
268 : 11005 : try {
269 [ + + ]: 11005 : auto ref = bitdeq.at(pos);
270 : 3309 : val_bitdeq = ref;
271 : 3309 : ref = newval;
272 [ - + ]: 11005 : } catch (const std::out_of_range&) {
273 : 7696 : throw_bitdeq = true;
274 : 7696 : }
275 [ - + ]: 11005 : assert(throw_deq == throw_bitdeq);
276 [ - + ]: 11005 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 11005 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 11005 : },
279 : 2456 : [&] {
280 : : // at (maybe out of range) (const)
281 : 2456 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 2456 : bool throw_deq{false}, throw_bitdeq{false};
283 : 2456 : bool val_deq{false}, val_bitdeq{false};
284 : 2456 : try {
285 [ + + ]: 2456 : auto& ref = cdeq.at(pos);
286 : 1342 : val_deq = ref;
287 [ - + ]: 1114 : } catch (const std::out_of_range&) {
288 : 1114 : throw_deq = true;
289 : 1114 : }
290 : 2456 : try {
291 [ + + ]: 2456 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 1114 : } catch (const std::out_of_range&) {
294 : 1114 : throw_bitdeq = true;
295 : 1114 : }
296 [ - + ]: 2456 : assert(throw_deq == throw_bitdeq);
297 [ - + ]: 2456 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 2456 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 2456 : },
300 : 6578 : [&] {
301 : : // operator[]
302 [ + + ]: 6578 : if (!cdeq.empty()) {
303 : 5845 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 5845 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 5845 : if (ctx.randbool()) {
306 : 2904 : deq[pos] = !deq[pos];
307 : 2904 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 6578 : },
311 : 2490 : [&] {
312 : : // operator[] const
313 [ + + ]: 2490 : if (!cdeq.empty()) {
314 : 1756 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 1756 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 2490 : },
318 : 5537 : [&] {
319 : : // front()
320 [ + + ]: 5537 : if (!cdeq.empty()) {
321 [ - + ]: 4425 : auto& ref = deq.front();
322 : 4425 : auto bitref = bitdeq.front();
323 [ - + ]: 4425 : assert(ref == bitref);
324 [ + + ]: 4425 : if (ctx.randbool()) {
325 : 2168 : ref = !ref;
326 : 2168 : bitref = !bitref;
327 : : }
328 : 4425 : }
329 : 5537 : },
330 : 2426 : [&] {
331 : : // front() const
332 [ + + ]: 2426 : if (!cdeq.empty()) {
333 [ - + ]: 1509 : auto& ref = cdeq.front();
334 : 1509 : auto bitref = cbitdeq.front();
335 [ - + ]: 1509 : assert(ref == bitref);
336 : : }
337 : 2426 : },
338 : 7258 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 7258 : if (!cdeq.empty()) {
341 : 6489 : auto& ref = deq.back();
342 : 6489 : auto bitref = bitdeq.back();
343 [ - + ]: 6489 : assert(ref == bitref);
344 [ + + ]: 6489 : if (ctx.randbool()) {
345 : 3266 : ref = !ref;
346 : 3266 : bitref.flip();
347 : : }
348 : 6489 : }
349 : 7258 : },
350 : 4970 : [&] {
351 : : // back() const
352 [ + + ]: 4970 : if (!cdeq.empty()) {
353 : 3592 : const auto& cdeq = deq;
354 : 3592 : const auto& cbitdeq = bitdeq;
355 : 3592 : auto& ref = cdeq.back();
356 : 3592 : auto bitref = cbitdeq.back();
357 [ - + ]: 3592 : assert(ref == bitref);
358 : : }
359 : 4970 : },
360 : 7874 : [&] {
361 : : // push_back()
362 [ + + ]: 7874 : if (cdeq.size() < limitlen) {
363 : 6952 : bool val = ctx.randbool();
364 [ + + ]: 6952 : if (cdeq.empty()) {
365 : 2561 : deq.push_back(val);
366 : 2561 : bitdeq.push_back(val);
367 : : } else {
368 : 4391 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 4391 : auto& ref = deq[pos];
370 : 4391 : auto bitref = bitdeq[pos];
371 [ - + ]: 4391 : assert(ref == bitref);
372 : 4391 : deq.push_back(val);
373 : 4391 : bitdeq.push_back(val);
374 [ - + ]: 4391 : assert(ref == bitref); // references are not invalidated
375 : 4391 : }
376 : : }
377 : 7874 : },
378 : 10804 : [&] {
379 : : // push_front()
380 [ + + ]: 10804 : if (cdeq.size() < limitlen) {
381 : 9785 : bool val = ctx.randbool();
382 [ + + ]: 9785 : if (cdeq.empty()) {
383 : 3199 : deq.push_front(val);
384 : 3199 : bitdeq.push_front(val);
385 : : } else {
386 : 6586 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 6586 : auto& ref = deq[pos];
388 : 6586 : auto bitref = bitdeq[pos];
389 [ - + ]: 6586 : assert(ref == bitref);
390 : 6586 : deq.push_front(val);
391 : 6586 : bitdeq.push_front(val);
392 [ - + ]: 6586 : assert(ref == bitref); // references are not invalidated
393 : 6586 : }
394 : : }
395 : 10804 : },
396 : 5249 : [&] {
397 : : // pop_back()
398 [ + + ]: 5249 : if (!cdeq.empty()) {
399 [ + + ]: 4169 : if (cdeq.size() == 1) {
400 : 1324 : deq.pop_back();
401 : 1324 : bitdeq.pop_back();
402 : : } else {
403 : 2845 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 2845 : auto& ref = deq[pos];
405 : 2845 : auto bitref = bitdeq[pos];
406 [ - + ]: 2845 : assert(ref == bitref);
407 : 2845 : deq.pop_back();
408 : 2845 : bitdeq.pop_back();
409 [ - + ]: 2845 : assert(ref == bitref); // references to other elements are not invalidated
410 : 2845 : }
411 : : }
412 : 5249 : },
413 : 5853 : [&] {
414 : : // pop_front()
415 [ + + ]: 5853 : if (!cdeq.empty()) {
416 [ + + ]: 4302 : if (cdeq.size() == 1) {
417 : 1377 : deq.pop_front();
418 : 1377 : bitdeq.pop_front();
419 : : } else {
420 : 2925 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 2925 : auto& ref = deq[pos];
422 : 2925 : auto bitref = bitdeq[pos];
423 [ - + ]: 2925 : assert(ref == bitref);
424 : 2925 : deq.pop_front();
425 : 2925 : bitdeq.pop_front();
426 [ - + ]: 2925 : assert(ref == bitref); // references to other elements are not invalidated
427 : 2925 : }
428 : : }
429 : 5853 : },
430 : 9851 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 9851 : if (!cdeq.empty()) {
433 : 8058 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 : 8058 : size_t after = cdeq.size() - 1 - before;
435 : 8058 : auto it = deq.erase(cdeq.begin() + before);
436 : 8058 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 8058 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 16116 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 9851 : },
441 : 8227 : [&] {
442 : : // erase (at front, range)
443 : 8227 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 8227 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 8227 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 8227 : assert(it == deq.begin());
447 [ + - ]: 8227 : assert(bitit == bitdeq.begin());
448 : 8227 : },
449 : 3213 : [&] {
450 : : // erase (at back, range)
451 : 3213 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 3213 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 3213 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 3213 : assert(it == deq.end());
455 [ + - ]: 3213 : assert(bitit == bitdeq.end());
456 : 3213 : },
457 : 4876 : [&] {
458 : : // erase (in middle, range)
459 : 4876 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 : 4876 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 : 4876 : size_t after = cdeq.size() - count - before;
462 : 4876 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 4876 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 4876 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 9752 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 4876 : },
467 : 12389 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ + + ]: 12389 : if (cdeq.size() < limitlen) {
470 : 11630 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 11630 : bool val = ctx.randbool();
472 : 11630 : bool do_emplace = provider.ConsumeBool();
473 : 11630 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 11630 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 11630 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 11630 : assert(it == deq.begin() + before);
477 [ + - ]: 11630 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 12389 : },
480 : 10495 : [&] {
481 : : // insert (at front, begin/end)
482 [ + + ]: 10495 : if (cdeq.size() < limitlen) {
483 : 9797 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 9797 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 9797 : auto rand_end = rand_begin + count;
486 : 9797 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 9797 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 9797 : assert(it == cdeq.begin());
489 [ + - ]: 9797 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 10495 : },
492 : 8803 : [&] {
493 : : // insert (at back, begin/end)
494 [ + + ]: 8803 : if (cdeq.size() < limitlen) {
495 : 7043 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 7043 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 7043 : auto rand_end = rand_begin + count;
498 : 7043 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 7043 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 7043 : assert(it == cdeq.end() - count);
501 [ + - ]: 7043 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 8803 : },
504 : 27109 : [&] {
505 : : // insert (in middle, range)
506 [ + + ]: 27109 : if (cdeq.size() < limitlen) {
507 : 22355 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 : 22355 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 22355 : bool val = ctx.randbool();
510 : 22355 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 22355 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 22355 : assert(it == deq.begin() + before);
513 [ + - ]: 22355 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 27109 : },
516 : 24192 : [&] {
517 : : // insert (in middle, begin/end)
518 [ + + ]: 24192 : if (cdeq.size() < limitlen) {
519 : 20979 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 : 20979 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 20979 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 20979 : auto rand_end = rand_begin + count;
523 : 20979 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 20979 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 20979 : assert(it == deq.begin() + before);
526 [ + - ]: 20979 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 24192 : });
529 : : }
530 : 1106 : {
531 [ - + ]: 1106 : assert(deq.size() == bitdeq.size());
532 : 1106 : auto it = deq.begin();
533 : 1106 : auto bitit = bitdeq.begin();
534 : 1106 : auto itend = deq.end();
535 [ + + ]: 12967919 : while (it != itend) {
536 [ - + ]: 12966813 : assert(*it == *bitit);
537 : 12966813 : ++it;
538 : 12966813 : ++bitit;
539 : : }
540 : : }
541 : 1106 : }
|