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 [ + - ]: 1666 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 1210 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 1210 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 1210 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 1210 : std::deque<bool> deq;
43 [ + - ]: 1210 : bitdeque_type bitdeq;
44 : :
45 : 1210 : const auto& cdeq = deq;
46 : 1210 : const auto& cbitdeq = bitdeq;
47 : :
48 : 1210 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 10304963 : while (initlen) {
50 : 10302543 : bool val = ctx.randbool();
51 [ + - ]: 10302543 : deq.push_back(val);
52 [ + - ]: 10302543 : bitdeq.push_back(val);
53 : 10302543 : --initlen;
54 : : }
55 : :
56 [ + + ]: 1210 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 392589 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 391379 : CallOneOf(
60 : : provider,
61 : 27558 : [&] {
62 : : // constructor()
63 : 55116 : deq = std::deque<bool>{};
64 : 27558 : bitdeq = bitdeque_type{};
65 : 27558 : },
66 : 6147 : [&] {
67 : : // clear()
68 : 6147 : deq.clear();
69 : 6147 : bitdeq.clear();
70 : 6147 : },
71 : 9097 : [&] {
72 : : // resize()
73 : 9097 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 9097 : deq.resize(count);
75 : 9097 : bitdeq.resize(count);
76 : 9097 : },
77 : 12663 : [&] {
78 : : // assign(count, val)
79 : 12663 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 12663 : bool val = ctx.randbool();
81 : 12663 : deq.assign(count, val);
82 : 12663 : bitdeq.assign(count, val);
83 : 12663 : },
84 : 4745 : [&] {
85 : : // constructor(count, val)
86 : 4745 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 4745 : bool val = ctx.randbool();
88 : 9490 : deq = std::deque<bool>(count, val);
89 : 4745 : bitdeq = bitdeque_type(count, val);
90 : 4745 : },
91 : 3623 : [&] {
92 : : // constructor(count)
93 : 3623 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 7246 : deq = std::deque<bool>(count);
95 : 3623 : bitdeq = bitdeque_type(count);
96 : 3623 : },
97 : 7161 : [&] {
98 : : // construct(begin, end)
99 : 7161 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 7161 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 7161 : auto rand_end = rand_begin + count;
102 : 14322 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 7161 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 7161 : },
105 : 12962 : [&] {
106 : : // assign(begin, end)
107 : 12962 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 12962 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 12962 : auto rand_end = rand_begin + count;
110 : 12962 : deq.assign(rand_begin, rand_end);
111 : 12962 : bitdeq.assign(rand_begin, rand_end);
112 : 12962 : },
113 : 12237 : [&] {
114 : : // construct(initializer_list)
115 : 12237 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 24474 : deq = std::deque<bool>(ilist);
117 : 12237 : bitdeq = bitdeque_type(ilist);
118 : 12237 : },
119 : 18022 : [&] {
120 : : // assign(initializer_list)
121 : 18022 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 18022 : deq.assign(ilist);
123 : 18022 : bitdeq.assign(ilist);
124 : 18022 : },
125 : 18174 : [&] {
126 : : // operator=(const&)
127 : 18174 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 18174 : bool val = ctx.randbool();
129 : 18174 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 18174 : deq = deq2;
131 [ + - ]: 18174 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 18174 : bitdeq = bitdeq2;
133 : 18174 : },
134 : 5247 : [&] {
135 : : // operator=(&&)
136 : 5247 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 5247 : bool val = ctx.randbool();
138 : 5247 : std::deque<bool> deq2(count, val);
139 : 5247 : deq = std::move(deq2);
140 [ + - ]: 5247 : bitdeque_type bitdeq2(count, val);
141 : 5247 : bitdeq = std::move(bitdeq2);
142 : 5247 : },
143 : 5050 : [&] {
144 : : // deque swap
145 : 5050 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 5050 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 5050 : auto rand_end = rand_begin + count;
148 : 5050 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 5050 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 5050 : using std::swap;
151 [ - + - + ]: 5050 : assert(deq.size() == bitdeq.size());
152 [ - + - + ]: 5050 : assert(deq2.size() == bitdeq2.size());
153 : 5050 : swap(deq, deq2);
154 : 5050 : swap(bitdeq, bitdeq2);
155 [ - + - + ]: 5050 : assert(deq.size() == bitdeq.size());
156 [ - + - + ]: 5050 : assert(deq2.size() == bitdeq2.size());
157 : 5050 : },
158 : 7296 : [&] {
159 : : // deque.swap
160 : 7296 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 7296 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 7296 : auto rand_end = rand_begin + count;
163 : 7296 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 7296 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + - + ]: 7296 : assert(deq.size() == bitdeq.size());
166 [ - + - + ]: 7296 : assert(deq2.size() == bitdeq2.size());
167 : 7296 : deq.swap(deq2);
168 : 7296 : bitdeq.swap(bitdeq2);
169 [ - + - + ]: 7296 : assert(deq.size() == bitdeq.size());
170 [ - + - + ]: 7296 : assert(deq2.size() == bitdeq2.size());
171 : 7296 : },
172 : 9747 : [&] {
173 : : // operator=(initializer_list)
174 : 9747 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 9747 : deq = ilist;
176 : 9747 : bitdeq = ilist;
177 : 9747 : },
178 : 7808 : [&] {
179 : : // iterator arithmetic
180 [ - + ]: 7808 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 [ - + ]: 7808 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 7808 : auto it = deq.begin() + pos1;
183 : 7808 : auto bitit = bitdeq.begin() + pos1;
184 [ - + + + : 7808 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
- + ]
185 [ - + ]: 7808 : assert(it - deq.begin() == pos1);
186 [ - + ]: 7808 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 7808 : if (provider.ConsumeBool()) {
188 : 4336 : it += pos2 - pos1;
189 : 4336 : bitit += pos2 - pos1;
190 : : } else {
191 : 3472 : it -= pos1 - pos2;
192 : 3472 : bitit -= pos1 - pos2;
193 : : }
194 [ - + + + : 7808 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
- + ]
195 [ - + ]: 7808 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 7808 : if (provider.ConsumeBool()) {
197 [ - + + + ]: 4145 : if ((size_t)pos2 != cdeq.size()) {
198 : 2926 : ++it;
199 : 2926 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 3663 : if (pos2 != 0) {
203 : 2581 : --it;
204 : 2581 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 7808 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 7808 : },
209 : 3203 : [&] {
210 : : // begin() and end()
211 [ - + ]: 3203 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 3203 : },
213 : 4205 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 4205 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 4205 : },
217 : 3545 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 3545 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 3545 : },
221 : 3120 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 3120 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 3120 : },
225 : 2491 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 2491 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 2491 : },
229 : 2653 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 2653 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 2653 : },
233 : 3439 : [&] {
234 : : // size() and maxsize()
235 [ - + - + ]: 3439 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 3439 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 3439 : },
238 : 3113 : [&] {
239 : : // empty
240 [ - + ]: 3113 : assert(cdeq.empty() == cbitdeq.empty());
241 : 3113 : },
242 : 5391 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 5391 : if (!cdeq.empty()) {
245 [ - + ]: 4583 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 4583 : auto& ref = deq.at(pos);
247 : 4583 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 4583 : assert(ref == bitref);
249 [ + + ]: 4583 : if (ctx.randbool()) {
250 : 2298 : ref = !ref;
251 : 2298 : bitref.flip();
252 : : }
253 : 4583 : }
254 : 5391 : },
255 : 11913 : [&] {
256 : : // at (maybe out of range) and bit assign
257 [ - + ]: 11913 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 11913 : bool newval = ctx.randbool();
259 : 11913 : bool throw_deq{false}, throw_bitdeq{false};
260 : 11913 : bool val_deq{false}, val_bitdeq{false};
261 : 11913 : try {
262 [ + + ]: 11913 : auto& ref = deq.at(pos);
263 : 3423 : val_deq = ref;
264 : 3423 : ref = newval;
265 [ - + ]: 8490 : } catch (const std::out_of_range&) {
266 : 8490 : throw_deq = true;
267 : 8490 : }
268 : 11913 : try {
269 [ + + ]: 11913 : auto ref = bitdeq.at(pos);
270 : 3423 : val_bitdeq = ref;
271 : 3423 : ref = newval;
272 [ - + ]: 11913 : } catch (const std::out_of_range&) {
273 : 8490 : throw_bitdeq = true;
274 : 8490 : }
275 [ - + ]: 11913 : assert(throw_deq == throw_bitdeq);
276 [ - + - + ]: 11913 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 11913 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 11913 : },
279 : 2593 : [&] {
280 : : // at (maybe out of range) (const)
281 [ - + ]: 2593 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 2593 : bool throw_deq{false}, throw_bitdeq{false};
283 : 2593 : bool val_deq{false}, val_bitdeq{false};
284 : 2593 : try {
285 [ + + ]: 2593 : auto& ref = cdeq.at(pos);
286 : 1401 : val_deq = ref;
287 [ - + ]: 1192 : } catch (const std::out_of_range&) {
288 : 1192 : throw_deq = true;
289 : 1192 : }
290 : 2593 : try {
291 [ + + ]: 2593 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 1192 : } catch (const std::out_of_range&) {
294 : 1192 : throw_bitdeq = true;
295 : 1192 : }
296 [ - + ]: 2593 : assert(throw_deq == throw_bitdeq);
297 [ - + - + ]: 2593 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 2593 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 2593 : },
300 : 7025 : [&] {
301 : : // operator[]
302 [ + + ]: 7025 : if (!cdeq.empty()) {
303 [ - + ]: 6253 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 6253 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 6253 : if (ctx.randbool()) {
306 : 3104 : deq[pos] = !deq[pos];
307 : 3104 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 7025 : },
311 : 2722 : [&] {
312 : : // operator[] const
313 [ + + ]: 2722 : if (!cdeq.empty()) {
314 [ - + ]: 1972 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 1972 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 2722 : },
318 : 5857 : [&] {
319 : : // front()
320 [ + + ]: 5857 : if (!cdeq.empty()) {
321 [ - + ]: 4599 : auto& ref = deq.front();
322 : 4599 : auto bitref = bitdeq.front();
323 [ - + ]: 4599 : assert(ref == bitref);
324 [ + + ]: 4599 : if (ctx.randbool()) {
325 : 2263 : ref = !ref;
326 : 2263 : bitref = !bitref;
327 : : }
328 : 4599 : }
329 : 5857 : },
330 : 2669 : [&] {
331 : : // front() const
332 [ + + ]: 2669 : if (!cdeq.empty()) {
333 [ - + ]: 1731 : auto& ref = cdeq.front();
334 : 1731 : auto bitref = cbitdeq.front();
335 [ - + ]: 1731 : assert(ref == bitref);
336 : : }
337 : 2669 : },
338 : 7491 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 7491 : if (!cdeq.empty()) {
341 : 6697 : auto& ref = deq.back();
342 : 6697 : auto bitref = bitdeq.back();
343 [ - + ]: 6697 : assert(ref == bitref);
344 [ + + ]: 6697 : if (ctx.randbool()) {
345 : 3370 : ref = !ref;
346 : 3370 : bitref.flip();
347 : : }
348 : 6697 : }
349 : 7491 : },
350 : 5328 : [&] {
351 : : // back() const
352 [ + + ]: 5328 : if (!cdeq.empty()) {
353 : 3901 : const auto& cdeq = deq;
354 : 3901 : const auto& cbitdeq = bitdeq;
355 : 3901 : auto& ref = cdeq.back();
356 : 3901 : auto bitref = cbitdeq.back();
357 [ - + ]: 3901 : assert(ref == bitref);
358 : : }
359 : 5328 : },
360 : 8292 : [&] {
361 : : // push_back()
362 [ - + + + ]: 8292 : if (cdeq.size() < limitlen) {
363 : 7225 : bool val = ctx.randbool();
364 [ + + ]: 7225 : if (cdeq.empty()) {
365 : 2719 : deq.push_back(val);
366 : 2719 : bitdeq.push_back(val);
367 : : } else {
368 [ - + ]: 4506 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 4506 : auto& ref = deq[pos];
370 : 4506 : auto bitref = bitdeq[pos];
371 [ - + ]: 4506 : assert(ref == bitref);
372 : 4506 : deq.push_back(val);
373 : 4506 : bitdeq.push_back(val);
374 [ - + ]: 4506 : assert(ref == bitref); // references are not invalidated
375 : 4506 : }
376 : : }
377 : 8292 : },
378 : 11920 : [&] {
379 : : // push_front()
380 [ - + + + ]: 11920 : if (cdeq.size() < limitlen) {
381 : 10753 : bool val = ctx.randbool();
382 [ + + ]: 10753 : if (cdeq.empty()) {
383 : 3823 : deq.push_front(val);
384 : 3823 : bitdeq.push_front(val);
385 : : } else {
386 [ - + ]: 6930 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 6930 : auto& ref = deq[pos];
388 : 6930 : auto bitref = bitdeq[pos];
389 [ - + ]: 6930 : assert(ref == bitref);
390 : 6930 : deq.push_front(val);
391 : 6930 : bitdeq.push_front(val);
392 [ - + ]: 6930 : assert(ref == bitref); // references are not invalidated
393 : 6930 : }
394 : : }
395 : 11920 : },
396 : 5647 : [&] {
397 : : // pop_back()
398 [ + + ]: 5647 : if (!cdeq.empty()) {
399 [ - + + + ]: 4385 : if (cdeq.size() == 1) {
400 : 1330 : deq.pop_back();
401 : 1330 : bitdeq.pop_back();
402 : : } else {
403 : 3055 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 3055 : auto& ref = deq[pos];
405 : 3055 : auto bitref = bitdeq[pos];
406 [ - + ]: 3055 : assert(ref == bitref);
407 : 3055 : deq.pop_back();
408 : 3055 : bitdeq.pop_back();
409 [ - + ]: 3055 : assert(ref == bitref); // references to other elements are not invalidated
410 : 3055 : }
411 : : }
412 : 5647 : },
413 : 6511 : [&] {
414 : : // pop_front()
415 [ + + ]: 6511 : if (!cdeq.empty()) {
416 [ - + + + ]: 4916 : if (cdeq.size() == 1) {
417 : 1885 : deq.pop_front();
418 : 1885 : bitdeq.pop_front();
419 : : } else {
420 : 3031 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 3031 : auto& ref = deq[pos];
422 : 3031 : auto bitref = bitdeq[pos];
423 [ - + ]: 3031 : assert(ref == bitref);
424 : 3031 : deq.pop_front();
425 : 3031 : bitdeq.pop_front();
426 [ - + ]: 3031 : assert(ref == bitref); // references to other elements are not invalidated
427 : 3031 : }
428 : : }
429 : 6511 : },
430 : 10549 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 10549 : if (!cdeq.empty()) {
433 [ - + ]: 8678 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 [ - + ]: 8678 : size_t after = cdeq.size() - 1 - before;
435 : 8678 : auto it = deq.erase(cdeq.begin() + before);
436 : 8678 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 8678 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 17356 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 10549 : },
441 : 8454 : [&] {
442 : : // erase (at front, range)
443 [ - + ]: 8454 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 8454 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 8454 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 8454 : assert(it == deq.begin());
447 [ + - ]: 8454 : assert(bitit == bitdeq.begin());
448 : 8454 : },
449 : 3354 : [&] {
450 : : // erase (at back, range)
451 [ - + ]: 3354 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 3354 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 3354 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 3354 : assert(it == deq.end());
455 [ + - ]: 3354 : assert(bitit == bitdeq.end());
456 : 3354 : },
457 : 5166 : [&] {
458 : : // erase (in middle, range)
459 [ - + ]: 5166 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 [ - + ]: 5166 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 [ - + ]: 5166 : size_t after = cdeq.size() - count - before;
462 : 5166 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 5166 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 5166 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 10332 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 5166 : },
467 : 13105 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ - + + + ]: 13105 : if (cdeq.size() < limitlen) {
470 : 12153 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 12153 : bool val = ctx.randbool();
472 : 12153 : bool do_emplace = provider.ConsumeBool();
473 : 12153 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 12153 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 12153 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 12153 : assert(it == deq.begin() + before);
477 [ + - ]: 12153 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 13105 : },
480 : 11341 : [&] {
481 : : // insert (at front, begin/end)
482 [ - + + + ]: 11341 : if (cdeq.size() < limitlen) {
483 : 10639 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 10639 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 10639 : auto rand_end = rand_begin + count;
486 : 10639 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 10639 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 10639 : assert(it == cdeq.begin());
489 [ + - ]: 10639 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 11341 : },
492 : 9102 : [&] {
493 : : // insert (at back, begin/end)
494 [ - + + + ]: 9102 : if (cdeq.size() < limitlen) {
495 : 7334 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 7334 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 7334 : auto rand_end = rand_begin + count;
498 : 7334 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 7334 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 7334 : assert(it == cdeq.end() - count);
501 [ + - ]: 7334 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 9102 : },
504 : 28686 : [&] {
505 : : // insert (in middle, range)
506 [ - + + + ]: 28686 : if (cdeq.size() < limitlen) {
507 : 23896 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 [ - + ]: 23896 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 23896 : bool val = ctx.randbool();
510 : 23896 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 23896 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 23896 : assert(it == deq.begin() + before);
513 [ + - ]: 23896 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 28686 : },
516 : 24957 : [&] {
517 : : // insert (in middle, begin/end)
518 [ - + + + ]: 24957 : if (cdeq.size() < limitlen) {
519 : 21699 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 [ - + ]: 21699 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 21699 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 21699 : auto rand_end = rand_begin + count;
523 : 21699 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 21699 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 21699 : assert(it == deq.begin() + before);
526 [ + - ]: 21699 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 24957 : });
529 : : }
530 : 1210 : {
531 [ - + - + ]: 1210 : assert(deq.size() == bitdeq.size());
532 : 1210 : auto it = deq.begin();
533 : 1210 : auto bitit = bitdeq.begin();
534 : 1210 : auto itend = deq.end();
535 [ + + ]: 14275992 : while (it != itend) {
536 [ - + ]: 14274782 : assert(*it == *bitit);
537 : 14274782 : ++it;
538 : 14274782 : ++bitit;
539 : : }
540 : : }
541 : 1210 : }
|