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 [ + - ]: 1496 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 1040 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 1040 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 1040 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 1040 : std::deque<bool> deq;
43 [ + - ]: 1040 : bitdeque_type bitdeq;
44 : :
45 : 1040 : const auto& cdeq = deq;
46 : 1040 : const auto& cbitdeq = bitdeq;
47 : :
48 : 1040 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 8250682 : while (initlen) {
50 : 8248602 : bool val = ctx.randbool();
51 [ + - ]: 8248602 : deq.push_back(val);
52 [ + - ]: 8248602 : bitdeq.push_back(val);
53 : 8248602 : --initlen;
54 : : }
55 : :
56 [ + + ]: 1040 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 350041 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 349001 : CallOneOf(
60 : : provider,
61 : 24847 : [&] {
62 : : // constructor()
63 : 49694 : deq = std::deque<bool>{};
64 : 24847 : bitdeq = bitdeque_type{};
65 : 24847 : },
66 : 5998 : [&] {
67 : : // clear()
68 : 5998 : deq.clear();
69 : 5998 : bitdeq.clear();
70 : 5998 : },
71 : 9927 : [&] {
72 : : // resize()
73 : 9927 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 9927 : deq.resize(count);
75 : 9927 : bitdeq.resize(count);
76 : 9927 : },
77 : 11446 : [&] {
78 : : // assign(count, val)
79 : 11446 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 11446 : bool val = ctx.randbool();
81 : 11446 : deq.assign(count, val);
82 : 11446 : bitdeq.assign(count, val);
83 : 11446 : },
84 : 4661 : [&] {
85 : : // constructor(count, val)
86 : 4661 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 4661 : bool val = ctx.randbool();
88 : 9322 : deq = std::deque<bool>(count, val);
89 : 4661 : bitdeq = bitdeque_type(count, val);
90 : 4661 : },
91 : 3277 : [&] {
92 : : // constructor(count)
93 : 3277 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 6554 : deq = std::deque<bool>(count);
95 : 3277 : bitdeq = bitdeque_type(count);
96 : 3277 : },
97 : 5726 : [&] {
98 : : // construct(begin, end)
99 : 5726 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 5726 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 5726 : auto rand_end = rand_begin + count;
102 : 11452 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 5726 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 5726 : },
105 : 10145 : [&] {
106 : : // assign(begin, end)
107 : 10145 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 10145 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 10145 : auto rand_end = rand_begin + count;
110 : 10145 : deq.assign(rand_begin, rand_end);
111 : 10145 : bitdeq.assign(rand_begin, rand_end);
112 : 10145 : },
113 : 10260 : [&] {
114 : : // construct(initializer_list)
115 : 10260 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 20520 : deq = std::deque<bool>(ilist);
117 : 10260 : bitdeq = bitdeque_type(ilist);
118 : 10260 : },
119 : 15350 : [&] {
120 : : // assign(initializer_list)
121 : 15350 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 15350 : deq.assign(ilist);
123 : 15350 : bitdeq.assign(ilist);
124 : 15350 : },
125 : 15303 : [&] {
126 : : // operator=(const&)
127 : 15303 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 15303 : bool val = ctx.randbool();
129 : 15303 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 15303 : deq = deq2;
131 [ + - ]: 15303 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 15303 : bitdeq = bitdeq2;
133 : 15303 : },
134 : 4364 : [&] {
135 : : // operator=(&&)
136 : 4364 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 4364 : bool val = ctx.randbool();
138 : 4364 : std::deque<bool> deq2(count, val);
139 : 4364 : deq = std::move(deq2);
140 [ + - ]: 4364 : bitdeque_type bitdeq2(count, val);
141 : 4364 : bitdeq = std::move(bitdeq2);
142 : 4364 : },
143 : 4474 : [&] {
144 : : // deque swap
145 : 4474 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 4474 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 4474 : auto rand_end = rand_begin + count;
148 : 4474 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 4474 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 4474 : using std::swap;
151 [ - + - + ]: 4474 : assert(deq.size() == bitdeq.size());
152 [ - + - + ]: 4474 : assert(deq2.size() == bitdeq2.size());
153 : 4474 : swap(deq, deq2);
154 : 4474 : swap(bitdeq, bitdeq2);
155 [ - + - + ]: 4474 : assert(deq.size() == bitdeq.size());
156 [ - + - + ]: 4474 : assert(deq2.size() == bitdeq2.size());
157 : 4474 : },
158 : 7653 : [&] {
159 : : // deque.swap
160 : 7653 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 7653 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 7653 : auto rand_end = rand_begin + count;
163 : 7653 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 7653 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + - + ]: 7653 : assert(deq.size() == bitdeq.size());
166 [ - + - + ]: 7653 : assert(deq2.size() == bitdeq2.size());
167 : 7653 : deq.swap(deq2);
168 : 7653 : bitdeq.swap(bitdeq2);
169 [ - + - + ]: 7653 : assert(deq.size() == bitdeq.size());
170 [ - + - + ]: 7653 : assert(deq2.size() == bitdeq2.size());
171 : 7653 : },
172 : 8574 : [&] {
173 : : // operator=(initializer_list)
174 : 8574 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 8574 : deq = ilist;
176 : 8574 : bitdeq = ilist;
177 : 8574 : },
178 : 8992 : [&] {
179 : : // iterator arithmetic
180 [ - + ]: 8992 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 [ - + ]: 8992 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 8992 : auto it = deq.begin() + pos1;
183 : 8992 : auto bitit = bitdeq.begin() + pos1;
184 [ - + + + : 8992 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
- + ]
185 [ - + ]: 8992 : assert(it - deq.begin() == pos1);
186 [ - + ]: 8992 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 8992 : if (provider.ConsumeBool()) {
188 : 5391 : it += pos2 - pos1;
189 : 5391 : bitit += pos2 - pos1;
190 : : } else {
191 : 3601 : it -= pos1 - pos2;
192 : 3601 : bitit -= pos1 - pos2;
193 : : }
194 [ - + + + : 8992 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
- + ]
195 [ - + ]: 8992 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 8992 : if (provider.ConsumeBool()) {
197 [ - + + + ]: 5117 : if ((size_t)pos2 != cdeq.size()) {
198 : 3451 : ++it;
199 : 3451 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 3875 : if (pos2 != 0) {
203 : 3005 : --it;
204 : 3005 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 8992 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 8992 : },
209 : 2901 : [&] {
210 : : // begin() and end()
211 [ - + ]: 2901 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 2901 : },
213 : 3368 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 3368 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 3368 : },
217 : 2442 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 2442 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 2442 : },
221 : 3353 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 3353 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 3353 : },
225 : 1822 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 1822 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 1822 : },
229 : 1787 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 1787 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 1787 : },
233 : 2981 : [&] {
234 : : // size() and maxsize()
235 [ - + - + ]: 2981 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 2981 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 2981 : },
238 : 2805 : [&] {
239 : : // empty
240 [ - + ]: 2805 : assert(cdeq.empty() == cbitdeq.empty());
241 : 2805 : },
242 : 5027 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 5027 : if (!cdeq.empty()) {
245 [ - + ]: 4261 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 4261 : auto& ref = deq.at(pos);
247 : 4261 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 4261 : assert(ref == bitref);
249 [ + + ]: 4261 : if (ctx.randbool()) {
250 : 2098 : ref = !ref;
251 : 2098 : bitref.flip();
252 : : }
253 : 4261 : }
254 : 5027 : },
255 : 9536 : [&] {
256 : : // at (maybe out of range) and bit assign
257 [ - + ]: 9536 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 9536 : bool newval = ctx.randbool();
259 : 9536 : bool throw_deq{false}, throw_bitdeq{false};
260 : 9536 : bool val_deq{false}, val_bitdeq{false};
261 : 9536 : try {
262 [ + + ]: 9536 : auto& ref = deq.at(pos);
263 : 3458 : val_deq = ref;
264 : 3458 : ref = newval;
265 [ - + ]: 6078 : } catch (const std::out_of_range&) {
266 : 6078 : throw_deq = true;
267 : 6078 : }
268 : 9536 : try {
269 [ + + ]: 9536 : auto ref = bitdeq.at(pos);
270 : 3458 : val_bitdeq = ref;
271 : 3458 : ref = newval;
272 [ - + ]: 9536 : } catch (const std::out_of_range&) {
273 : 6078 : throw_bitdeq = true;
274 : 6078 : }
275 [ - + ]: 9536 : assert(throw_deq == throw_bitdeq);
276 [ - + - + ]: 9536 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 9536 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 9536 : },
279 : 2623 : [&] {
280 : : // at (maybe out of range) (const)
281 [ - + ]: 2623 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 2623 : bool throw_deq{false}, throw_bitdeq{false};
283 : 2623 : bool val_deq{false}, val_bitdeq{false};
284 : 2623 : try {
285 [ + + ]: 2623 : auto& ref = cdeq.at(pos);
286 : 1459 : val_deq = ref;
287 [ - + ]: 1164 : } catch (const std::out_of_range&) {
288 : 1164 : throw_deq = true;
289 : 1164 : }
290 : 2623 : try {
291 [ + + ]: 2623 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 1164 : } catch (const std::out_of_range&) {
294 : 1164 : throw_bitdeq = true;
295 : 1164 : }
296 [ - + ]: 2623 : assert(throw_deq == throw_bitdeq);
297 [ - + - + ]: 2623 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 2623 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 2623 : },
300 : 5514 : [&] {
301 : : // operator[]
302 [ + + ]: 5514 : if (!cdeq.empty()) {
303 [ - + ]: 4804 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 4804 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 4804 : if (ctx.randbool()) {
306 : 2396 : deq[pos] = !deq[pos];
307 : 2396 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 5514 : },
311 : 2569 : [&] {
312 : : // operator[] const
313 [ + + ]: 2569 : if (!cdeq.empty()) {
314 [ - + ]: 2006 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 2006 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 2569 : },
318 : 4909 : [&] {
319 : : // front()
320 [ + + ]: 4909 : if (!cdeq.empty()) {
321 [ - + ]: 3936 : auto& ref = deq.front();
322 : 3936 : auto bitref = bitdeq.front();
323 [ - + ]: 3936 : assert(ref == bitref);
324 [ + + ]: 3936 : if (ctx.randbool()) {
325 : 1873 : ref = !ref;
326 : 1873 : bitref = !bitref;
327 : : }
328 : 3936 : }
329 : 4909 : },
330 : 2141 : [&] {
331 : : // front() const
332 [ + + ]: 2141 : if (!cdeq.empty()) {
333 [ - + ]: 1525 : auto& ref = cdeq.front();
334 : 1525 : auto bitref = cbitdeq.front();
335 [ - + ]: 1525 : assert(ref == bitref);
336 : : }
337 : 2141 : },
338 : 5139 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 5139 : if (!cdeq.empty()) {
341 : 4274 : auto& ref = deq.back();
342 : 4274 : auto bitref = bitdeq.back();
343 [ - + ]: 4274 : assert(ref == bitref);
344 [ + + ]: 4274 : if (ctx.randbool()) {
345 : 2128 : ref = !ref;
346 : 2128 : bitref.flip();
347 : : }
348 : 4274 : }
349 : 5139 : },
350 : 4625 : [&] {
351 : : // back() const
352 [ + + ]: 4625 : if (!cdeq.empty()) {
353 : 3200 : const auto& cdeq = deq;
354 : 3200 : const auto& cbitdeq = bitdeq;
355 : 3200 : auto& ref = cdeq.back();
356 : 3200 : auto bitref = cbitdeq.back();
357 [ - + ]: 3200 : assert(ref == bitref);
358 : : }
359 : 4625 : },
360 : 7785 : [&] {
361 : : // push_back()
362 [ - + + + ]: 7785 : if (cdeq.size() < limitlen) {
363 : 6633 : bool val = ctx.randbool();
364 [ + + ]: 6633 : if (cdeq.empty()) {
365 : 2867 : deq.push_back(val);
366 : 2867 : bitdeq.push_back(val);
367 : : } else {
368 [ - + ]: 3766 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 3766 : auto& ref = deq[pos];
370 : 3766 : auto bitref = bitdeq[pos];
371 [ - + ]: 3766 : assert(ref == bitref);
372 : 3766 : deq.push_back(val);
373 : 3766 : bitdeq.push_back(val);
374 [ - + ]: 3766 : assert(ref == bitref); // references are not invalidated
375 : 3766 : }
376 : : }
377 : 7785 : },
378 : 10791 : [&] {
379 : : // push_front()
380 [ - + + + ]: 10791 : if (cdeq.size() < limitlen) {
381 : 10054 : bool val = ctx.randbool();
382 [ + + ]: 10054 : if (cdeq.empty()) {
383 : 4077 : deq.push_front(val);
384 : 4077 : bitdeq.push_front(val);
385 : : } else {
386 [ - + ]: 5977 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 5977 : auto& ref = deq[pos];
388 : 5977 : auto bitref = bitdeq[pos];
389 [ - + ]: 5977 : assert(ref == bitref);
390 : 5977 : deq.push_front(val);
391 : 5977 : bitdeq.push_front(val);
392 [ - + ]: 5977 : assert(ref == bitref); // references are not invalidated
393 : 5977 : }
394 : : }
395 : 10791 : },
396 : 5621 : [&] {
397 : : // pop_back()
398 [ + + ]: 5621 : if (!cdeq.empty()) {
399 [ - + + + ]: 4366 : if (cdeq.size() == 1) {
400 : 1301 : deq.pop_back();
401 : 1301 : bitdeq.pop_back();
402 : : } else {
403 : 3065 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 3065 : auto& ref = deq[pos];
405 : 3065 : auto bitref = bitdeq[pos];
406 [ - + ]: 3065 : assert(ref == bitref);
407 : 3065 : deq.pop_back();
408 : 3065 : bitdeq.pop_back();
409 [ - + ]: 3065 : assert(ref == bitref); // references to other elements are not invalidated
410 : 3065 : }
411 : : }
412 : 5621 : },
413 : 7207 : [&] {
414 : : // pop_front()
415 [ + + ]: 7207 : if (!cdeq.empty()) {
416 [ - + + + ]: 5715 : if (cdeq.size() == 1) {
417 : 2487 : deq.pop_front();
418 : 2487 : bitdeq.pop_front();
419 : : } else {
420 : 3228 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 3228 : auto& ref = deq[pos];
422 : 3228 : auto bitref = bitdeq[pos];
423 [ - + ]: 3228 : assert(ref == bitref);
424 : 3228 : deq.pop_front();
425 : 3228 : bitdeq.pop_front();
426 [ - + ]: 3228 : assert(ref == bitref); // references to other elements are not invalidated
427 : 3228 : }
428 : : }
429 : 7207 : },
430 : 8099 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 8099 : if (!cdeq.empty()) {
433 [ - + ]: 6837 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 [ - + ]: 6837 : size_t after = cdeq.size() - 1 - before;
435 : 6837 : auto it = deq.erase(cdeq.begin() + before);
436 : 6837 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 6837 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 13674 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 8099 : },
441 : 8172 : [&] {
442 : : // erase (at front, range)
443 [ - + ]: 8172 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 8172 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 8172 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 8172 : assert(it == deq.begin());
447 [ + - ]: 8172 : assert(bitit == bitdeq.begin());
448 : 8172 : },
449 : 2791 : [&] {
450 : : // erase (at back, range)
451 [ - + ]: 2791 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 2791 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 2791 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 2791 : assert(it == deq.end());
455 [ + - ]: 2791 : assert(bitit == bitdeq.end());
456 : 2791 : },
457 : 5144 : [&] {
458 : : // erase (in middle, range)
459 [ - + ]: 5144 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 [ - + ]: 5144 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 [ - + ]: 5144 : size_t after = cdeq.size() - count - before;
462 : 5144 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 5144 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 5144 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 10288 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 5144 : },
467 : 13189 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ - + + + ]: 13189 : if (cdeq.size() < limitlen) {
470 : 12508 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 12508 : bool val = ctx.randbool();
472 : 12508 : bool do_emplace = provider.ConsumeBool();
473 : 12508 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 12508 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 12508 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 12508 : assert(it == deq.begin() + before);
477 [ + - ]: 12508 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 13189 : },
480 : 9813 : [&] {
481 : : // insert (at front, begin/end)
482 [ - + + + ]: 9813 : if (cdeq.size() < limitlen) {
483 : 9251 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 9251 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 9251 : auto rand_end = rand_begin + count;
486 : 9251 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 9251 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 9251 : assert(it == cdeq.begin());
489 [ + - ]: 9251 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 9813 : },
492 : 7422 : [&] {
493 : : // insert (at back, begin/end)
494 [ - + + + ]: 7422 : if (cdeq.size() < limitlen) {
495 : 6144 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 6144 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 6144 : auto rand_end = rand_begin + count;
498 : 6144 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 6144 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 6144 : assert(it == cdeq.end() - count);
501 [ + - ]: 6144 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 7422 : },
504 : 29073 : [&] {
505 : : // insert (in middle, range)
506 [ - + + + ]: 29073 : if (cdeq.size() < limitlen) {
507 : 23778 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 [ - + ]: 23778 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 23778 : bool val = ctx.randbool();
510 : 23778 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 23778 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 23778 : assert(it == deq.begin() + before);
513 [ + - ]: 23778 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 29073 : },
516 : 19355 : [&] {
517 : : // insert (in middle, begin/end)
518 [ - + + + ]: 19355 : if (cdeq.size() < limitlen) {
519 : 16925 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 [ - + ]: 16925 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 16925 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 16925 : auto rand_end = rand_begin + count;
523 : 16925 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 16925 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 16925 : assert(it == deq.begin() + before);
526 [ + - ]: 16925 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 19355 : });
529 : : }
530 : 1040 : {
531 [ - + - + ]: 1040 : assert(deq.size() == bitdeq.size());
532 : 1040 : auto it = deq.begin();
533 : 1040 : auto bitit = bitdeq.begin();
534 : 1040 : auto itend = deq.end();
535 [ + + ]: 12524706 : while (it != itend) {
536 [ - + ]: 12523666 : assert(*it == *bitit);
537 : 12523666 : ++it;
538 : 12523666 : ++bitit;
539 : : }
540 : : }
541 : 1040 : }
|