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 [ + - ]: 1389 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 931 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 931 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 931 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 931 : std::deque<bool> deq;
43 [ + - ]: 931 : bitdeque_type bitdeq;
44 : :
45 : 931 : const auto& cdeq = deq;
46 : 931 : const auto& cbitdeq = bitdeq;
47 : :
48 : 931 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 6557163 : while (initlen) {
50 : 6555301 : bool val = ctx.randbool();
51 [ + - ]: 6555301 : deq.push_back(val);
52 [ + - ]: 6555301 : bitdeq.push_back(val);
53 : 6555301 : --initlen;
54 : : }
55 : :
56 [ + + ]: 931 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 295076 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 294145 : CallOneOf(
60 : : provider,
61 : 19463 : [&] {
62 : : // constructor()
63 : 38926 : deq = std::deque<bool>{};
64 : 19463 : bitdeq = bitdeque_type{};
65 : 19463 : },
66 : 5802 : [&] {
67 : : // clear()
68 : 5802 : deq.clear();
69 : 5802 : bitdeq.clear();
70 : 5802 : },
71 : 7553 : [&] {
72 : : // resize()
73 : 7553 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 7553 : deq.resize(count);
75 : 7553 : bitdeq.resize(count);
76 : 7553 : },
77 : 10073 : [&] {
78 : : // assign(count, val)
79 : 10073 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 10073 : bool val = ctx.randbool();
81 : 10073 : deq.assign(count, val);
82 : 10073 : bitdeq.assign(count, val);
83 : 10073 : },
84 : 4071 : [&] {
85 : : // constructor(count, val)
86 : 4071 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 4071 : bool val = ctx.randbool();
88 : 8142 : deq = std::deque<bool>(count, val);
89 : 4071 : bitdeq = bitdeque_type(count, val);
90 : 4071 : },
91 : 3036 : [&] {
92 : : // constructor(count)
93 : 3036 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 6072 : deq = std::deque<bool>(count);
95 : 3036 : bitdeq = bitdeque_type(count);
96 : 3036 : },
97 : 5616 : [&] {
98 : : // construct(begin, end)
99 : 5616 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 5616 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 5616 : auto rand_end = rand_begin + count;
102 : 11232 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 5616 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 5616 : },
105 : 9971 : [&] {
106 : : // assign(begin, end)
107 : 9971 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 9971 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 9971 : auto rand_end = rand_begin + count;
110 : 9971 : deq.assign(rand_begin, rand_end);
111 : 9971 : bitdeq.assign(rand_begin, rand_end);
112 : 9971 : },
113 : 9363 : [&] {
114 : : // construct(initializer_list)
115 : 9363 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 18726 : deq = std::deque<bool>(ilist);
117 : 9363 : bitdeq = bitdeque_type(ilist);
118 : 9363 : },
119 : 11703 : [&] {
120 : : // assign(initializer_list)
121 : 11703 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 11703 : deq.assign(ilist);
123 : 11703 : bitdeq.assign(ilist);
124 : 11703 : },
125 : 13342 : [&] {
126 : : // operator=(const&)
127 : 13342 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 13342 : bool val = ctx.randbool();
129 : 13342 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 13342 : deq = deq2;
131 [ + - ]: 13342 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 13342 : bitdeq = bitdeq2;
133 : 13342 : },
134 : 3547 : [&] {
135 : : // operator=(&&)
136 : 3547 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 3547 : bool val = ctx.randbool();
138 : 3547 : std::deque<bool> deq2(count, val);
139 : 3547 : deq = std::move(deq2);
140 [ + - ]: 3547 : bitdeque_type bitdeq2(count, val);
141 : 3547 : bitdeq = std::move(bitdeq2);
142 : 3547 : },
143 : 4118 : [&] {
144 : : // deque swap
145 : 4118 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 4118 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 4118 : auto rand_end = rand_begin + count;
148 : 4118 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 4118 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 4118 : using std::swap;
151 [ - + - + ]: 4118 : assert(deq.size() == bitdeq.size());
152 [ - + - + ]: 4118 : assert(deq2.size() == bitdeq2.size());
153 : 4118 : swap(deq, deq2);
154 : 4118 : swap(bitdeq, bitdeq2);
155 [ - + - + ]: 4118 : assert(deq.size() == bitdeq.size());
156 [ - + - + ]: 4118 : assert(deq2.size() == bitdeq2.size());
157 : 4118 : },
158 : 6961 : [&] {
159 : : // deque.swap
160 : 6961 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 6961 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 6961 : auto rand_end = rand_begin + count;
163 : 6961 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 6961 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + - + ]: 6961 : assert(deq.size() == bitdeq.size());
166 [ - + - + ]: 6961 : assert(deq2.size() == bitdeq2.size());
167 : 6961 : deq.swap(deq2);
168 : 6961 : bitdeq.swap(bitdeq2);
169 [ - + - + ]: 6961 : assert(deq.size() == bitdeq.size());
170 [ - + - + ]: 6961 : assert(deq2.size() == bitdeq2.size());
171 : 6961 : },
172 : 7310 : [&] {
173 : : // operator=(initializer_list)
174 : 7310 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 7310 : deq = ilist;
176 : 7310 : bitdeq = ilist;
177 : 7310 : },
178 : 7888 : [&] {
179 : : // iterator arithmetic
180 [ - + ]: 7888 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 [ - + ]: 7888 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 7888 : auto it = deq.begin() + pos1;
183 : 7888 : auto bitit = bitdeq.begin() + pos1;
184 [ - + + + : 7888 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
- + ]
185 [ - + ]: 7888 : assert(it - deq.begin() == pos1);
186 [ - + ]: 7888 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 7888 : if (provider.ConsumeBool()) {
188 : 4470 : it += pos2 - pos1;
189 : 4470 : bitit += pos2 - pos1;
190 : : } else {
191 : 3418 : it -= pos1 - pos2;
192 : 3418 : bitit -= pos1 - pos2;
193 : : }
194 [ - + + + : 7888 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
- + ]
195 [ - + ]: 7888 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 7888 : if (provider.ConsumeBool()) {
197 [ - + + + ]: 4067 : if ((size_t)pos2 != cdeq.size()) {
198 : 2888 : ++it;
199 : 2888 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 3821 : if (pos2 != 0) {
203 : 3015 : --it;
204 : 3015 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 7888 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 7888 : },
209 : 2743 : [&] {
210 : : // begin() and end()
211 [ - + ]: 2743 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 2743 : },
213 : 2792 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 2792 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 2792 : },
217 : 2322 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 2322 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 2322 : },
221 : 2535 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 2535 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 2535 : },
225 : 1329 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 1329 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 1329 : },
229 : 1688 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 1688 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 1688 : },
233 : 2489 : [&] {
234 : : // size() and maxsize()
235 [ - + - + ]: 2489 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 2489 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 2489 : },
238 : 2239 : [&] {
239 : : // empty
240 [ - + ]: 2239 : assert(cdeq.empty() == cbitdeq.empty());
241 : 2239 : },
242 : 4160 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 4160 : if (!cdeq.empty()) {
245 [ - + ]: 3514 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 3514 : auto& ref = deq.at(pos);
247 : 3514 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 3514 : assert(ref == bitref);
249 [ + + ]: 3514 : if (ctx.randbool()) {
250 : 1734 : ref = !ref;
251 : 1734 : bitref.flip();
252 : : }
253 : 3514 : }
254 : 4160 : },
255 : 7737 : [&] {
256 : : // at (maybe out of range) and bit assign
257 [ - + ]: 7737 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 7737 : bool newval = ctx.randbool();
259 : 7737 : bool throw_deq{false}, throw_bitdeq{false};
260 : 7737 : bool val_deq{false}, val_bitdeq{false};
261 : 7737 : try {
262 [ + + ]: 7737 : auto& ref = deq.at(pos);
263 : 2639 : val_deq = ref;
264 : 2639 : ref = newval;
265 [ - + ]: 5098 : } catch (const std::out_of_range&) {
266 : 5098 : throw_deq = true;
267 : 5098 : }
268 : 7737 : try {
269 [ + + ]: 7737 : auto ref = bitdeq.at(pos);
270 : 2639 : val_bitdeq = ref;
271 : 2639 : ref = newval;
272 [ - + ]: 7737 : } catch (const std::out_of_range&) {
273 : 5098 : throw_bitdeq = true;
274 : 5098 : }
275 [ - + ]: 7737 : assert(throw_deq == throw_bitdeq);
276 [ - + - + ]: 7737 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 7737 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 7737 : },
279 : 2557 : [&] {
280 : : // at (maybe out of range) (const)
281 [ - + ]: 2557 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 2557 : bool throw_deq{false}, throw_bitdeq{false};
283 : 2557 : bool val_deq{false}, val_bitdeq{false};
284 : 2557 : try {
285 [ + + ]: 2557 : auto& ref = cdeq.at(pos);
286 : 1417 : val_deq = ref;
287 [ - + ]: 1140 : } catch (const std::out_of_range&) {
288 : 1140 : throw_deq = true;
289 : 1140 : }
290 : 2557 : try {
291 [ + + ]: 2557 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 1140 : } catch (const std::out_of_range&) {
294 : 1140 : throw_bitdeq = true;
295 : 1140 : }
296 [ - + ]: 2557 : assert(throw_deq == throw_bitdeq);
297 [ - + - + ]: 2557 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 2557 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 2557 : },
300 : 4287 : [&] {
301 : : // operator[]
302 [ + + ]: 4287 : if (!cdeq.empty()) {
303 [ - + ]: 3608 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 3608 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 3608 : if (ctx.randbool()) {
306 : 1795 : deq[pos] = !deq[pos];
307 : 1795 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 4287 : },
311 : 2645 : [&] {
312 : : // operator[] const
313 [ + + ]: 2645 : if (!cdeq.empty()) {
314 [ - + ]: 1674 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 1674 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 2645 : },
318 : 4554 : [&] {
319 : : // front()
320 [ + + ]: 4554 : if (!cdeq.empty()) {
321 [ - + ]: 3844 : auto& ref = deq.front();
322 : 3844 : auto bitref = bitdeq.front();
323 [ - + ]: 3844 : assert(ref == bitref);
324 [ + + ]: 3844 : if (ctx.randbool()) {
325 : 1834 : ref = !ref;
326 : 1834 : bitref = !bitref;
327 : : }
328 : 3844 : }
329 : 4554 : },
330 : 1722 : [&] {
331 : : // front() const
332 [ + + ]: 1722 : if (!cdeq.empty()) {
333 [ - + ]: 1114 : auto& ref = cdeq.front();
334 : 1114 : auto bitref = cbitdeq.front();
335 [ - + ]: 1114 : assert(ref == bitref);
336 : : }
337 : 1722 : },
338 : 4178 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 4178 : if (!cdeq.empty()) {
341 : 3439 : auto& ref = deq.back();
342 : 3439 : auto bitref = bitdeq.back();
343 [ - + ]: 3439 : assert(ref == bitref);
344 [ + + ]: 3439 : if (ctx.randbool()) {
345 : 1698 : ref = !ref;
346 : 1698 : bitref.flip();
347 : : }
348 : 3439 : }
349 : 4178 : },
350 : 3405 : [&] {
351 : : // back() const
352 [ + + ]: 3405 : if (!cdeq.empty()) {
353 : 2481 : const auto& cdeq = deq;
354 : 2481 : const auto& cbitdeq = bitdeq;
355 : 2481 : auto& ref = cdeq.back();
356 : 2481 : auto bitref = cbitdeq.back();
357 [ - + ]: 2481 : assert(ref == bitref);
358 : : }
359 : 3405 : },
360 : 6695 : [&] {
361 : : // push_back()
362 [ - + + + ]: 6695 : if (cdeq.size() < limitlen) {
363 : 5931 : bool val = ctx.randbool();
364 [ + + ]: 5931 : if (cdeq.empty()) {
365 : 2519 : deq.push_back(val);
366 : 2519 : bitdeq.push_back(val);
367 : : } else {
368 [ - + ]: 3412 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 3412 : auto& ref = deq[pos];
370 : 3412 : auto bitref = bitdeq[pos];
371 [ - + ]: 3412 : assert(ref == bitref);
372 : 3412 : deq.push_back(val);
373 : 3412 : bitdeq.push_back(val);
374 [ - + ]: 3412 : assert(ref == bitref); // references are not invalidated
375 : 3412 : }
376 : : }
377 : 6695 : },
378 : 8876 : [&] {
379 : : // push_front()
380 [ - + + + ]: 8876 : if (cdeq.size() < limitlen) {
381 : 8400 : bool val = ctx.randbool();
382 [ + + ]: 8400 : if (cdeq.empty()) {
383 : 3401 : deq.push_front(val);
384 : 3401 : bitdeq.push_front(val);
385 : : } else {
386 [ - + ]: 4999 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 4999 : auto& ref = deq[pos];
388 : 4999 : auto bitref = bitdeq[pos];
389 [ - + ]: 4999 : assert(ref == bitref);
390 : 4999 : deq.push_front(val);
391 : 4999 : bitdeq.push_front(val);
392 [ - + ]: 4999 : assert(ref == bitref); // references are not invalidated
393 : 4999 : }
394 : : }
395 : 8876 : },
396 : 4555 : [&] {
397 : : // pop_back()
398 [ + + ]: 4555 : if (!cdeq.empty()) {
399 [ - + + + ]: 3687 : if (cdeq.size() == 1) {
400 : 1193 : deq.pop_back();
401 : 1193 : bitdeq.pop_back();
402 : : } else {
403 : 2494 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 2494 : auto& ref = deq[pos];
405 : 2494 : auto bitref = bitdeq[pos];
406 [ - + ]: 2494 : assert(ref == bitref);
407 : 2494 : deq.pop_back();
408 : 2494 : bitdeq.pop_back();
409 [ - + ]: 2494 : assert(ref == bitref); // references to other elements are not invalidated
410 : 2494 : }
411 : : }
412 : 4555 : },
413 : 5427 : [&] {
414 : : // pop_front()
415 [ + + ]: 5427 : if (!cdeq.empty()) {
416 [ - + + + ]: 4154 : if (cdeq.size() == 1) {
417 : 1957 : deq.pop_front();
418 : 1957 : bitdeq.pop_front();
419 : : } else {
420 : 2197 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 2197 : auto& ref = deq[pos];
422 : 2197 : auto bitref = bitdeq[pos];
423 [ - + ]: 2197 : assert(ref == bitref);
424 : 2197 : deq.pop_front();
425 : 2197 : bitdeq.pop_front();
426 [ - + ]: 2197 : assert(ref == bitref); // references to other elements are not invalidated
427 : 2197 : }
428 : : }
429 : 5427 : },
430 : 6879 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 6879 : if (!cdeq.empty()) {
433 [ - + ]: 5718 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 [ - + ]: 5718 : size_t after = cdeq.size() - 1 - before;
435 : 5718 : auto it = deq.erase(cdeq.begin() + before);
436 : 5718 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 5718 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 11436 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 6879 : },
441 : 6207 : [&] {
442 : : // erase (at front, range)
443 [ - + ]: 6207 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 6207 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 6207 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 6207 : assert(it == deq.begin());
447 [ + - ]: 6207 : assert(bitit == bitdeq.begin());
448 : 6207 : },
449 : 1908 : [&] {
450 : : // erase (at back, range)
451 [ - + ]: 1908 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 1908 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 1908 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 1908 : assert(it == deq.end());
455 [ + - ]: 1908 : assert(bitit == bitdeq.end());
456 : 1908 : },
457 : 4690 : [&] {
458 : : // erase (in middle, range)
459 [ - + ]: 4690 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 [ - + ]: 4690 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 [ - + ]: 4690 : size_t after = cdeq.size() - count - before;
462 : 4690 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 4690 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 4690 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 9380 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 4690 : },
467 : 11727 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ - + + + ]: 11727 : if (cdeq.size() < limitlen) {
470 : 11238 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 11238 : bool val = ctx.randbool();
472 : 11238 : bool do_emplace = provider.ConsumeBool();
473 : 11238 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 11238 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 11238 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 11238 : assert(it == deq.begin() + before);
477 [ + - ]: 11238 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 11727 : },
480 : 8178 : [&] {
481 : : // insert (at front, begin/end)
482 [ - + + + ]: 8178 : if (cdeq.size() < limitlen) {
483 : 7550 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 7550 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 7550 : auto rand_end = rand_begin + count;
486 : 7550 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 7550 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 7550 : assert(it == cdeq.begin());
489 [ + - ]: 7550 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 8178 : },
492 : 6324 : [&] {
493 : : // insert (at back, begin/end)
494 [ - + + + ]: 6324 : if (cdeq.size() < limitlen) {
495 : 5087 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 5087 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 5087 : auto rand_end = rand_begin + count;
498 : 5087 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 5087 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 5087 : assert(it == cdeq.end() - count);
501 [ + - ]: 5087 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 6324 : },
504 : 24496 : [&] {
505 : : // insert (in middle, range)
506 [ - + + + ]: 24496 : if (cdeq.size() < limitlen) {
507 : 19965 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 [ - + ]: 19965 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 19965 : bool val = ctx.randbool();
510 : 19965 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 19965 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 19965 : assert(it == deq.begin() + before);
513 [ + - ]: 19965 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 24496 : },
516 : 14984 : [&] {
517 : : // insert (in middle, begin/end)
518 [ - + + + ]: 14984 : if (cdeq.size() < limitlen) {
519 : 13490 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 [ - + ]: 13490 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 13490 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 13490 : auto rand_end = rand_begin + count;
523 : 13490 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 13490 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 13490 : assert(it == deq.begin() + before);
526 [ + - ]: 13490 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 14984 : });
529 : : }
530 : 931 : {
531 [ - + - + ]: 931 : assert(deq.size() == bitdeq.size());
532 : 931 : auto it = deq.begin();
533 : 931 : auto bitit = bitdeq.begin();
534 : 931 : auto itend = deq.end();
535 [ + + ]: 10358096 : while (it != itend) {
536 [ - + ]: 10357165 : assert(*it == *bitit);
537 : 10357165 : ++it;
538 : 10357165 : ++bitit;
539 : : }
540 : : }
541 : 931 : }
|