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 [ + - ]: 1085 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 627 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 627 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 627 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 627 : std::deque<bool> deq;
43 [ + - ]: 627 : bitdeque_type bitdeq;
44 : :
45 : 627 : const auto& cdeq = deq;
46 : 627 : const auto& cbitdeq = bitdeq;
47 : :
48 : 627 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 4831359 : while (initlen) {
50 : 4830105 : bool val = ctx.randbool();
51 [ + - ]: 4830105 : deq.push_back(val);
52 [ + - ]: 4830105 : bitdeq.push_back(val);
53 : 4830105 : --initlen;
54 : : }
55 : :
56 [ + + ]: 627 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 170050 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 169423 : CallOneOf(
60 : : provider,
61 : 12145 : [&] {
62 : : // constructor()
63 : 24290 : deq = std::deque<bool>{};
64 : 12145 : bitdeq = bitdeque_type{};
65 : 12145 : },
66 : 2731 : [&] {
67 : : // clear()
68 : 2731 : deq.clear();
69 : 2731 : bitdeq.clear();
70 : 2731 : },
71 : 4235 : [&] {
72 : : // resize()
73 : 4235 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 4235 : deq.resize(count);
75 : 4235 : bitdeq.resize(count);
76 : 4235 : },
77 : 6290 : [&] {
78 : : // assign(count, val)
79 : 6290 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 6290 : bool val = ctx.randbool();
81 : 6290 : deq.assign(count, val);
82 : 6290 : bitdeq.assign(count, val);
83 : 6290 : },
84 : 2319 : [&] {
85 : : // constructor(count, val)
86 : 2319 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 2319 : bool val = ctx.randbool();
88 : 4638 : deq = std::deque<bool>(count, val);
89 : 2319 : bitdeq = bitdeque_type(count, val);
90 : 2319 : },
91 : 1727 : [&] {
92 : : // constructor(count)
93 : 1727 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 3454 : deq = std::deque<bool>(count);
95 : 1727 : bitdeq = bitdeque_type(count);
96 : 1727 : },
97 : 3360 : [&] {
98 : : // construct(begin, end)
99 : 3360 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 3360 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 3360 : auto rand_end = rand_begin + count;
102 : 6720 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 3360 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 3360 : },
105 : 5843 : [&] {
106 : : // assign(begin, end)
107 : 5843 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 5843 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 5843 : auto rand_end = rand_begin + count;
110 : 5843 : deq.assign(rand_begin, rand_end);
111 : 5843 : bitdeq.assign(rand_begin, rand_end);
112 : 5843 : },
113 : 5767 : [&] {
114 : : // construct(initializer_list)
115 : 5767 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 11534 : deq = std::deque<bool>(ilist);
117 : 5767 : bitdeq = bitdeque_type(ilist);
118 : 5767 : },
119 : 7857 : [&] {
120 : : // assign(initializer_list)
121 : 7857 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 7857 : deq.assign(ilist);
123 : 7857 : bitdeq.assign(ilist);
124 : 7857 : },
125 : 6869 : [&] {
126 : : // operator=(const&)
127 : 6869 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 6869 : bool val = ctx.randbool();
129 : 6869 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 6869 : deq = deq2;
131 [ + - ]: 6869 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 6869 : bitdeq = bitdeq2;
133 : 6869 : },
134 : 2138 : [&] {
135 : : // operator=(&&)
136 : 2138 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 2138 : bool val = ctx.randbool();
138 : 2138 : std::deque<bool> deq2(count, val);
139 : 2138 : deq = std::move(deq2);
140 [ + - ]: 2138 : bitdeque_type bitdeq2(count, val);
141 : 2138 : bitdeq = std::move(bitdeq2);
142 : 2138 : },
143 : 2765 : [&] {
144 : : // deque swap
145 : 2765 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 2765 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 2765 : auto rand_end = rand_begin + count;
148 : 2765 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 2765 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 2765 : using std::swap;
151 [ - + - + ]: 2765 : assert(deq.size() == bitdeq.size());
152 [ - + - + ]: 2765 : assert(deq2.size() == bitdeq2.size());
153 : 2765 : swap(deq, deq2);
154 : 2765 : swap(bitdeq, bitdeq2);
155 [ - + - + ]: 2765 : assert(deq.size() == bitdeq.size());
156 [ - + - + ]: 2765 : assert(deq2.size() == bitdeq2.size());
157 : 2765 : },
158 : 4638 : [&] {
159 : : // deque.swap
160 : 4638 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 4638 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 4638 : auto rand_end = rand_begin + count;
163 : 4638 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 4638 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + - + ]: 4638 : assert(deq.size() == bitdeq.size());
166 [ - + - + ]: 4638 : assert(deq2.size() == bitdeq2.size());
167 : 4638 : deq.swap(deq2);
168 : 4638 : bitdeq.swap(bitdeq2);
169 [ - + - + ]: 4638 : assert(deq.size() == bitdeq.size());
170 [ - + - + ]: 4638 : assert(deq2.size() == bitdeq2.size());
171 : 4638 : },
172 : 4929 : [&] {
173 : : // operator=(initializer_list)
174 : 4929 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 4929 : deq = ilist;
176 : 4929 : bitdeq = ilist;
177 : 4929 : },
178 : 3347 : [&] {
179 : : // iterator arithmetic
180 [ - + ]: 3347 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 [ - + ]: 3347 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 3347 : auto it = deq.begin() + pos1;
183 : 3347 : auto bitit = bitdeq.begin() + pos1;
184 [ - + + + : 3347 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
- + ]
185 [ - + ]: 3347 : assert(it - deq.begin() == pos1);
186 [ - + ]: 3347 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 3347 : if (provider.ConsumeBool()) {
188 : 1754 : it += pos2 - pos1;
189 : 1754 : bitit += pos2 - pos1;
190 : : } else {
191 : 1593 : it -= pos1 - pos2;
192 : 1593 : bitit -= pos1 - pos2;
193 : : }
194 [ - + + + : 3347 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
- + ]
195 [ - + ]: 3347 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 3347 : if (provider.ConsumeBool()) {
197 [ - + + + ]: 1507 : if ((size_t)pos2 != cdeq.size()) {
198 : 1180 : ++it;
199 : 1180 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 1840 : if (pos2 != 0) {
203 : 1444 : --it;
204 : 1444 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 3347 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 3347 : },
209 : 1482 : [&] {
210 : : // begin() and end()
211 [ - + ]: 1482 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 1482 : },
213 : 1669 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 1669 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 1669 : },
217 : 1382 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 1382 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 1382 : },
221 : 1191 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 1191 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 1191 : },
225 : 627 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 627 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 627 : },
229 : 845 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 845 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 845 : },
233 : 1396 : [&] {
234 : : // size() and maxsize()
235 [ - + - + ]: 1396 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 1396 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 1396 : },
238 : 1270 : [&] {
239 : : // empty
240 [ - + ]: 1270 : assert(cdeq.empty() == cbitdeq.empty());
241 : 1270 : },
242 : 2330 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 2330 : if (!cdeq.empty()) {
245 [ - + ]: 1971 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 1971 : auto& ref = deq.at(pos);
247 : 1971 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 1971 : assert(ref == bitref);
249 [ + + ]: 1971 : if (ctx.randbool()) {
250 : 982 : ref = !ref;
251 : 982 : bitref.flip();
252 : : }
253 : 1971 : }
254 : 2330 : },
255 : 4035 : [&] {
256 : : // at (maybe out of range) and bit assign
257 [ - + ]: 4035 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 4035 : bool newval = ctx.randbool();
259 : 4035 : bool throw_deq{false}, throw_bitdeq{false};
260 : 4035 : bool val_deq{false}, val_bitdeq{false};
261 : 4035 : try {
262 [ + + ]: 4035 : auto& ref = deq.at(pos);
263 : 1371 : val_deq = ref;
264 : 1371 : ref = newval;
265 [ - + ]: 2664 : } catch (const std::out_of_range&) {
266 : 2664 : throw_deq = true;
267 : 2664 : }
268 : 4035 : try {
269 [ + + ]: 4035 : auto ref = bitdeq.at(pos);
270 : 1371 : val_bitdeq = ref;
271 : 1371 : ref = newval;
272 [ - + ]: 4035 : } catch (const std::out_of_range&) {
273 : 2664 : throw_bitdeq = true;
274 : 2664 : }
275 [ - + ]: 4035 : assert(throw_deq == throw_bitdeq);
276 [ - + - + ]: 4035 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 4035 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 4035 : },
279 : 1494 : [&] {
280 : : // at (maybe out of range) (const)
281 [ - + ]: 1494 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 1494 : bool throw_deq{false}, throw_bitdeq{false};
283 : 1494 : bool val_deq{false}, val_bitdeq{false};
284 : 1494 : try {
285 [ + + ]: 1494 : auto& ref = cdeq.at(pos);
286 : 953 : val_deq = ref;
287 [ - + ]: 541 : } catch (const std::out_of_range&) {
288 : 541 : throw_deq = true;
289 : 541 : }
290 : 1494 : try {
291 [ + + ]: 1494 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 541 : } catch (const std::out_of_range&) {
294 : 541 : throw_bitdeq = true;
295 : 541 : }
296 [ - + ]: 1494 : assert(throw_deq == throw_bitdeq);
297 [ - + - + ]: 1494 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 1494 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 1494 : },
300 : 2510 : [&] {
301 : : // operator[]
302 [ + + ]: 2510 : if (!cdeq.empty()) {
303 [ - + ]: 2163 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 2163 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 2163 : if (ctx.randbool()) {
306 : 1077 : deq[pos] = !deq[pos];
307 : 1077 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 2510 : },
311 : 1329 : [&] {
312 : : // operator[] const
313 [ + + ]: 1329 : if (!cdeq.empty()) {
314 [ - + ]: 856 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 856 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 1329 : },
318 : 2719 : [&] {
319 : : // front()
320 [ + + ]: 2719 : if (!cdeq.empty()) {
321 [ - + ]: 2340 : auto& ref = deq.front();
322 : 2340 : auto bitref = bitdeq.front();
323 [ - + ]: 2340 : assert(ref == bitref);
324 [ + + ]: 2340 : if (ctx.randbool()) {
325 : 1113 : ref = !ref;
326 : 1113 : bitref = !bitref;
327 : : }
328 : 2340 : }
329 : 2719 : },
330 : 966 : [&] {
331 : : // front() const
332 [ + + ]: 966 : if (!cdeq.empty()) {
333 [ - + ]: 631 : auto& ref = cdeq.front();
334 : 631 : auto bitref = cbitdeq.front();
335 [ - + ]: 631 : assert(ref == bitref);
336 : : }
337 : 966 : },
338 : 2505 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 2505 : if (!cdeq.empty()) {
341 : 2136 : auto& ref = deq.back();
342 : 2136 : auto bitref = bitdeq.back();
343 [ - + ]: 2136 : assert(ref == bitref);
344 [ + + ]: 2136 : if (ctx.randbool()) {
345 : 1072 : ref = !ref;
346 : 1072 : bitref.flip();
347 : : }
348 : 2136 : }
349 : 2505 : },
350 : 1930 : [&] {
351 : : // back() const
352 [ + + ]: 1930 : if (!cdeq.empty()) {
353 : 1435 : const auto& cdeq = deq;
354 : 1435 : const auto& cbitdeq = bitdeq;
355 : 1435 : auto& ref = cdeq.back();
356 : 1435 : auto bitref = cbitdeq.back();
357 [ - + ]: 1435 : assert(ref == bitref);
358 : : }
359 : 1930 : },
360 : 3988 : [&] {
361 : : // push_back()
362 [ - + + + ]: 3988 : if (cdeq.size() < limitlen) {
363 : 3419 : bool val = ctx.randbool();
364 [ + + ]: 3419 : if (cdeq.empty()) {
365 : 1534 : deq.push_back(val);
366 : 1534 : bitdeq.push_back(val);
367 : : } else {
368 [ - + ]: 1885 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 1885 : auto& ref = deq[pos];
370 : 1885 : auto bitref = bitdeq[pos];
371 [ - + ]: 1885 : assert(ref == bitref);
372 : 1885 : deq.push_back(val);
373 : 1885 : bitdeq.push_back(val);
374 [ - + ]: 1885 : assert(ref == bitref); // references are not invalidated
375 : 1885 : }
376 : : }
377 : 3988 : },
378 : 4988 : [&] {
379 : : // push_front()
380 [ - + + + ]: 4988 : if (cdeq.size() < limitlen) {
381 : 4646 : bool val = ctx.randbool();
382 [ + + ]: 4646 : if (cdeq.empty()) {
383 : 1840 : deq.push_front(val);
384 : 1840 : bitdeq.push_front(val);
385 : : } else {
386 [ - + ]: 2806 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 2806 : auto& ref = deq[pos];
388 : 2806 : auto bitref = bitdeq[pos];
389 [ - + ]: 2806 : assert(ref == bitref);
390 : 2806 : deq.push_front(val);
391 : 2806 : bitdeq.push_front(val);
392 [ - + ]: 2806 : assert(ref == bitref); // references are not invalidated
393 : 2806 : }
394 : : }
395 : 4988 : },
396 : 2449 : [&] {
397 : : // pop_back()
398 [ + + ]: 2449 : if (!cdeq.empty()) {
399 [ - + + + ]: 1890 : if (cdeq.size() == 1) {
400 : 620 : deq.pop_back();
401 : 620 : bitdeq.pop_back();
402 : : } else {
403 : 1270 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 1270 : auto& ref = deq[pos];
405 : 1270 : auto bitref = bitdeq[pos];
406 [ - + ]: 1270 : assert(ref == bitref);
407 : 1270 : deq.pop_back();
408 : 1270 : bitdeq.pop_back();
409 [ - + ]: 1270 : assert(ref == bitref); // references to other elements are not invalidated
410 : 1270 : }
411 : : }
412 : 2449 : },
413 : 3114 : [&] {
414 : : // pop_front()
415 [ + + ]: 3114 : if (!cdeq.empty()) {
416 [ - + + + ]: 2311 : if (cdeq.size() == 1) {
417 : 1139 : deq.pop_front();
418 : 1139 : bitdeq.pop_front();
419 : : } else {
420 : 1172 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 1172 : auto& ref = deq[pos];
422 : 1172 : auto bitref = bitdeq[pos];
423 [ - + ]: 1172 : assert(ref == bitref);
424 : 1172 : deq.pop_front();
425 : 1172 : bitdeq.pop_front();
426 [ - + ]: 1172 : assert(ref == bitref); // references to other elements are not invalidated
427 : 1172 : }
428 : : }
429 : 3114 : },
430 : 3482 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 3482 : if (!cdeq.empty()) {
433 [ - + ]: 2843 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 [ - + ]: 2843 : size_t after = cdeq.size() - 1 - before;
435 : 2843 : auto it = deq.erase(cdeq.begin() + before);
436 : 2843 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 2843 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 5686 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 3482 : },
441 : 3244 : [&] {
442 : : // erase (at front, range)
443 [ - + ]: 3244 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 3244 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 3244 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 3244 : assert(it == deq.begin());
447 [ + - ]: 3244 : assert(bitit == bitdeq.begin());
448 : 3244 : },
449 : 1133 : [&] {
450 : : // erase (at back, range)
451 [ - + ]: 1133 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 1133 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 1133 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 1133 : assert(it == deq.end());
455 [ + - ]: 1133 : assert(bitit == bitdeq.end());
456 : 1133 : },
457 : 2594 : [&] {
458 : : // erase (in middle, range)
459 [ - + ]: 2594 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 [ - + ]: 2594 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 [ - + ]: 2594 : size_t after = cdeq.size() - count - before;
462 : 2594 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 2594 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 2594 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 5188 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 2594 : },
467 : 5901 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ - + + + ]: 5901 : if (cdeq.size() < limitlen) {
470 : 5523 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 5523 : bool val = ctx.randbool();
472 : 5523 : bool do_emplace = provider.ConsumeBool();
473 : 5523 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 5523 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 5523 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 5523 : assert(it == deq.begin() + before);
477 [ + - ]: 5523 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 5901 : },
480 : 5464 : [&] {
481 : : // insert (at front, begin/end)
482 [ - + + + ]: 5464 : if (cdeq.size() < limitlen) {
483 : 5073 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 5073 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 5073 : auto rand_end = rand_begin + count;
486 : 5073 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 5073 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 5073 : assert(it == cdeq.begin());
489 [ + - ]: 5073 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 5464 : },
492 : 3961 : [&] {
493 : : // insert (at back, begin/end)
494 [ - + + + ]: 3961 : if (cdeq.size() < limitlen) {
495 : 3064 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 3064 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 3064 : auto rand_end = rand_begin + count;
498 : 3064 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 3064 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 3064 : assert(it == cdeq.end() - count);
501 [ + - ]: 3064 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 3961 : },
504 : 12411 : [&] {
505 : : // insert (in middle, range)
506 [ - + + + ]: 12411 : if (cdeq.size() < limitlen) {
507 : 9946 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 [ - + ]: 9946 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 9946 : bool val = ctx.randbool();
510 : 9946 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 9946 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 9946 : assert(it == deq.begin() + before);
513 [ + - ]: 9946 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 12411 : },
516 : 10054 : [&] {
517 : : // insert (in middle, begin/end)
518 [ - + + + ]: 10054 : if (cdeq.size() < limitlen) {
519 : 9073 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 [ - + ]: 9073 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 9073 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 9073 : auto rand_end = rand_begin + count;
523 : 9073 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 9073 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 9073 : assert(it == deq.begin() + before);
526 [ + - ]: 9073 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 10054 : });
529 : : }
530 : 627 : {
531 [ - + - + ]: 627 : assert(deq.size() == bitdeq.size());
532 : 627 : auto it = deq.begin();
533 : 627 : auto bitit = bitdeq.begin();
534 : 627 : auto itend = deq.end();
535 [ + + ]: 7609753 : while (it != itend) {
536 [ - + ]: 7609126 : assert(*it == *bitit);
537 : 7609126 : ++it;
538 : 7609126 : ++bitit;
539 : : }
540 : : }
541 : 627 : }
|