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 [ + - ]: 1259 : FUZZ_TARGET(bitdeque, .init = InitRandData)
35 : : {
36 : 801 : FuzzedDataProvider provider(buffer.data(), buffer.size());
37 : : FastRandomContext ctx(true);
38 : :
39 : 801 : size_t maxlen = (1U << provider.ConsumeIntegralInRange<size_t>(0, LEN_BITS)) - 1;
40 : 801 : size_t limitlen = 4 * maxlen;
41 : :
42 [ + - ]: 801 : std::deque<bool> deq;
43 [ + - ]: 801 : bitdeque_type bitdeq;
44 : :
45 : 801 : const auto& cdeq = deq;
46 : 801 : const auto& cbitdeq = bitdeq;
47 : :
48 : 801 : size_t initlen = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
49 [ + + ]: 6392539 : while (initlen) {
50 : 6390937 : bool val = ctx.randbool();
51 [ + - ]: 6390937 : deq.push_back(val);
52 [ + - ]: 6390937 : bitdeq.push_back(val);
53 : 6390937 : --initlen;
54 : : }
55 : :
56 [ + + ]: 801 : const auto iter_limit{maxlen > 6000 ? 90U : 900U};
57 [ + + + + ]: 274167 : LIMITED_WHILE(provider.remaining_bytes() > 0, iter_limit)
58 : : {
59 [ + - ]: 273366 : CallOneOf(
60 : : provider,
61 : 19142 : [&] {
62 : : // constructor()
63 : 38284 : deq = std::deque<bool>{};
64 : 19142 : bitdeq = bitdeque_type{};
65 : 19142 : },
66 : 4992 : [&] {
67 : : // clear()
68 : 4992 : deq.clear();
69 : 4992 : bitdeq.clear();
70 : 4992 : },
71 : 7391 : [&] {
72 : : // resize()
73 : 7391 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
74 : 7391 : deq.resize(count);
75 : 7391 : bitdeq.resize(count);
76 : 7391 : },
77 : 9684 : [&] {
78 : : // assign(count, val)
79 : 9684 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
80 : 9684 : bool val = ctx.randbool();
81 : 9684 : deq.assign(count, val);
82 : 9684 : bitdeq.assign(count, val);
83 : 9684 : },
84 : 3296 : [&] {
85 : : // constructor(count, val)
86 : 3296 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
87 : 3296 : bool val = ctx.randbool();
88 : 6592 : deq = std::deque<bool>(count, val);
89 : 3296 : bitdeq = bitdeque_type(count, val);
90 : 3296 : },
91 : 2518 : [&] {
92 : : // constructor(count)
93 : 2518 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
94 : 5036 : deq = std::deque<bool>(count);
95 : 2518 : bitdeq = bitdeque_type(count);
96 : 2518 : },
97 : 4709 : [&] {
98 : : // construct(begin, end)
99 : 4709 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
100 : 4709 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
101 : 4709 : auto rand_end = rand_begin + count;
102 : 9418 : deq = std::deque<bool>(rand_begin, rand_end);
103 : 4709 : bitdeq = bitdeque_type(rand_begin, rand_end);
104 : 4709 : },
105 : 8173 : [&] {
106 : : // assign(begin, end)
107 : 8173 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
108 : 8173 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
109 : 8173 : auto rand_end = rand_begin + count;
110 : 8173 : deq.assign(rand_begin, rand_end);
111 : 8173 : bitdeq.assign(rand_begin, rand_end);
112 : 8173 : },
113 : 7448 : [&] {
114 : : // construct(initializer_list)
115 : 7448 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool(), ctx.randbool()};
116 : 14896 : deq = std::deque<bool>(ilist);
117 : 7448 : bitdeq = bitdeque_type(ilist);
118 : 7448 : },
119 : 12078 : [&] {
120 : : // assign(initializer_list)
121 : 12078 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
122 : 12078 : deq.assign(ilist);
123 : 12078 : bitdeq.assign(ilist);
124 : 12078 : },
125 : 12235 : [&] {
126 : : // operator=(const&)
127 : 12235 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
128 : 12235 : bool val = ctx.randbool();
129 : 12235 : const std::deque<bool> deq2(count, val);
130 [ + - ]: 12235 : deq = deq2;
131 [ + - ]: 12235 : const bitdeque_type bitdeq2(count, val);
132 [ + - ]: 12235 : bitdeq = bitdeq2;
133 : 12235 : },
134 : 3544 : [&] {
135 : : // operator=(&&)
136 : 3544 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
137 : 3544 : bool val = ctx.randbool();
138 : 3544 : std::deque<bool> deq2(count, val);
139 : 3544 : deq = std::move(deq2);
140 [ + - ]: 3544 : bitdeque_type bitdeq2(count, val);
141 : 3544 : bitdeq = std::move(bitdeq2);
142 : 3544 : },
143 : 3455 : [&] {
144 : : // deque swap
145 : 3455 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
146 : 3455 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
147 : 3455 : auto rand_end = rand_begin + count;
148 : 3455 : std::deque<bool> deq2(rand_begin, rand_end);
149 [ + - ]: 3455 : bitdeque_type bitdeq2(rand_begin, rand_end);
150 : 3455 : using std::swap;
151 [ - + - + ]: 3455 : assert(deq.size() == bitdeq.size());
152 [ - + - + ]: 3455 : assert(deq2.size() == bitdeq2.size());
153 : 3455 : swap(deq, deq2);
154 : 3455 : swap(bitdeq, bitdeq2);
155 [ - + - + ]: 3455 : assert(deq.size() == bitdeq.size());
156 [ - + - + ]: 3455 : assert(deq2.size() == bitdeq2.size());
157 : 3455 : },
158 : 5998 : [&] {
159 : : // deque.swap
160 : 5998 : auto count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
161 : 5998 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
162 : 5998 : auto rand_end = rand_begin + count;
163 : 5998 : std::deque<bool> deq2(rand_begin, rand_end);
164 [ + - ]: 5998 : bitdeque_type bitdeq2(rand_begin, rand_end);
165 [ - + - + ]: 5998 : assert(deq.size() == bitdeq.size());
166 [ - + - + ]: 5998 : assert(deq2.size() == bitdeq2.size());
167 : 5998 : deq.swap(deq2);
168 : 5998 : bitdeq.swap(bitdeq2);
169 [ - + - + ]: 5998 : assert(deq.size() == bitdeq.size());
170 [ - + - + ]: 5998 : assert(deq2.size() == bitdeq2.size());
171 : 5998 : },
172 : 7234 : [&] {
173 : : // operator=(initializer_list)
174 : 7234 : std::initializer_list<bool> ilist{ctx.randbool(), ctx.randbool(), ctx.randbool()};
175 : 7234 : deq = ilist;
176 : 7234 : bitdeq = ilist;
177 : 7234 : },
178 : 7547 : [&] {
179 : : // iterator arithmetic
180 [ - + ]: 7547 : auto pos1 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
181 [ - + ]: 7547 : auto pos2 = provider.ConsumeIntegralInRange<long>(0, cdeq.size());
182 : 7547 : auto it = deq.begin() + pos1;
183 : 7547 : auto bitit = bitdeq.begin() + pos1;
184 [ - + + + : 7547 : if ((size_t)pos1 != cdeq.size()) assert(*it == *bitit);
- + ]
185 [ - + ]: 7547 : assert(it - deq.begin() == pos1);
186 [ - + ]: 7547 : assert(bitit - bitdeq.begin() == pos1);
187 [ + + ]: 7547 : if (provider.ConsumeBool()) {
188 : 4840 : it += pos2 - pos1;
189 : 4840 : bitit += pos2 - pos1;
190 : : } else {
191 : 2707 : it -= pos1 - pos2;
192 : 2707 : bitit -= pos1 - pos2;
193 : : }
194 [ - + + + : 7547 : if ((size_t)pos2 != cdeq.size()) assert(*it == *bitit);
- + ]
195 [ - + ]: 7547 : assert(deq.end() - it == bitdeq.end() - bitit);
196 [ + + ]: 7547 : if (provider.ConsumeBool()) {
197 [ - + + + ]: 4599 : if ((size_t)pos2 != cdeq.size()) {
198 : 3032 : ++it;
199 : 3032 : ++bitit;
200 : : }
201 : : } else {
202 [ + + ]: 2948 : if (pos2 != 0) {
203 : 2296 : --it;
204 : 2296 : --bitit;
205 : : }
206 : : }
207 [ - + ]: 7547 : assert(deq.end() - it == bitdeq.end() - bitit);
208 : 7547 : },
209 : 2295 : [&] {
210 : : // begin() and end()
211 [ - + ]: 2295 : assert(deq.end() - deq.begin() == bitdeq.end() - bitdeq.begin());
212 : 2295 : },
213 : 2568 : [&] {
214 : : // begin() and end() (const)
215 [ - + ]: 2568 : assert(cdeq.end() - cdeq.begin() == cbitdeq.end() - cbitdeq.begin());
216 : 2568 : },
217 : 2029 : [&] {
218 : : // rbegin() and rend()
219 [ - + ]: 2029 : assert(deq.rend() - deq.rbegin() == bitdeq.rend() - bitdeq.rbegin());
220 : 2029 : },
221 : 2624 : [&] {
222 : : // rbegin() and rend() (const)
223 [ - + ]: 2624 : assert(cdeq.rend() - cdeq.rbegin() == cbitdeq.rend() - cbitdeq.rbegin());
224 : 2624 : },
225 : 1416 : [&] {
226 : : // cbegin() and cend()
227 [ - + ]: 1416 : assert(cdeq.cend() - cdeq.cbegin() == cbitdeq.cend() - cbitdeq.cbegin());
228 : 1416 : },
229 : 1570 : [&] {
230 : : // crbegin() and crend()
231 [ - + ]: 1570 : assert(cdeq.crend() - cdeq.crbegin() == cbitdeq.crend() - cbitdeq.crbegin());
232 : 1570 : },
233 : 2226 : [&] {
234 : : // size() and maxsize()
235 [ - + - + ]: 2226 : assert(cdeq.size() == cbitdeq.size());
236 [ - + ]: 2226 : assert(cbitdeq.size() <= cbitdeq.max_size());
237 : 2226 : },
238 : 2496 : [&] {
239 : : // empty
240 [ - + ]: 2496 : assert(cdeq.empty() == cbitdeq.empty());
241 : 2496 : },
242 : 4095 : [&] {
243 : : // at (in range) and flip
244 [ + + ]: 4095 : if (!cdeq.empty()) {
245 [ - + ]: 3441 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
246 : 3441 : auto& ref = deq.at(pos);
247 : 3441 : auto bitref = bitdeq.at(pos);
248 [ - + ]: 3441 : assert(ref == bitref);
249 [ + + ]: 3441 : if (ctx.randbool()) {
250 : 1699 : ref = !ref;
251 : 1699 : bitref.flip();
252 : : }
253 : 3441 : }
254 : 4095 : },
255 : 7431 : [&] {
256 : : // at (maybe out of range) and bit assign
257 [ - + ]: 7431 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
258 : 7431 : bool newval = ctx.randbool();
259 : 7431 : bool throw_deq{false}, throw_bitdeq{false};
260 : 7431 : bool val_deq{false}, val_bitdeq{false};
261 : 7431 : try {
262 [ + + ]: 7431 : auto& ref = deq.at(pos);
263 : 2774 : val_deq = ref;
264 : 2774 : ref = newval;
265 [ - + ]: 4657 : } catch (const std::out_of_range&) {
266 : 4657 : throw_deq = true;
267 : 4657 : }
268 : 7431 : try {
269 [ + + ]: 7431 : auto ref = bitdeq.at(pos);
270 : 2774 : val_bitdeq = ref;
271 : 2774 : ref = newval;
272 [ - + ]: 7431 : } catch (const std::out_of_range&) {
273 : 4657 : throw_bitdeq = true;
274 : 4657 : }
275 [ - + ]: 7431 : assert(throw_deq == throw_bitdeq);
276 [ - + - + ]: 7431 : assert(throw_bitdeq == (pos >= cdeq.size()));
277 [ + + - + ]: 7431 : if (!throw_deq) assert(val_deq == val_bitdeq);
278 : 7431 : },
279 : 2095 : [&] {
280 : : // at (maybe out of range) (const)
281 [ - + ]: 2095 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() + maxlen);
282 : 2095 : bool throw_deq{false}, throw_bitdeq{false};
283 : 2095 : bool val_deq{false}, val_bitdeq{false};
284 : 2095 : try {
285 [ + + ]: 2095 : auto& ref = cdeq.at(pos);
286 : 1080 : val_deq = ref;
287 [ - + ]: 1015 : } catch (const std::out_of_range&) {
288 : 1015 : throw_deq = true;
289 : 1015 : }
290 : 2095 : try {
291 [ + + ]: 2095 : auto ref = cbitdeq.at(pos);
292 : : val_bitdeq = ref;
293 [ - + ]: 1015 : } catch (const std::out_of_range&) {
294 : 1015 : throw_bitdeq = true;
295 : 1015 : }
296 [ - + ]: 2095 : assert(throw_deq == throw_bitdeq);
297 [ - + - + ]: 2095 : assert(throw_bitdeq == (pos >= cdeq.size()));
298 [ + + - + ]: 2095 : if (!throw_deq) assert(val_deq == val_bitdeq);
299 : 2095 : },
300 : 3818 : [&] {
301 : : // operator[]
302 [ + + ]: 3818 : if (!cdeq.empty()) {
303 [ - + ]: 3280 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
304 [ - + ]: 3280 : assert(deq[pos] == bitdeq[pos]);
305 [ + + ]: 3280 : if (ctx.randbool()) {
306 : 1642 : deq[pos] = !deq[pos];
307 : 1642 : bitdeq[pos].flip();
308 : : }
309 : : }
310 : 3818 : },
311 : 2203 : [&] {
312 : : // operator[] const
313 [ + + ]: 2203 : if (!cdeq.empty()) {
314 [ - + ]: 1701 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
315 [ - + ]: 1701 : assert(deq[pos] == bitdeq[pos]);
316 : : }
317 : 2203 : },
318 : 3939 : [&] {
319 : : // front()
320 [ + + ]: 3939 : if (!cdeq.empty()) {
321 [ - + ]: 3187 : auto& ref = deq.front();
322 : 3187 : auto bitref = bitdeq.front();
323 [ - + ]: 3187 : assert(ref == bitref);
324 [ + + ]: 3187 : if (ctx.randbool()) {
325 : 1524 : ref = !ref;
326 : 1524 : bitref = !bitref;
327 : : }
328 : 3187 : }
329 : 3939 : },
330 : 1532 : [&] {
331 : : // front() const
332 [ + + ]: 1532 : if (!cdeq.empty()) {
333 [ - + ]: 1129 : auto& ref = cdeq.front();
334 : 1129 : auto bitref = cbitdeq.front();
335 [ - + ]: 1129 : assert(ref == bitref);
336 : : }
337 : 1532 : },
338 : 4337 : [&] {
339 : : // back() and swap(bool, ref)
340 [ + + ]: 4337 : if (!cdeq.empty()) {
341 : 3692 : auto& ref = deq.back();
342 : 3692 : auto bitref = bitdeq.back();
343 [ - + ]: 3692 : assert(ref == bitref);
344 [ + + ]: 3692 : if (ctx.randbool()) {
345 : 1834 : ref = !ref;
346 : 1834 : bitref.flip();
347 : : }
348 : 3692 : }
349 : 4337 : },
350 : 3906 : [&] {
351 : : // back() const
352 [ + + ]: 3906 : if (!cdeq.empty()) {
353 : 2786 : const auto& cdeq = deq;
354 : 2786 : const auto& cbitdeq = bitdeq;
355 : 2786 : auto& ref = cdeq.back();
356 : 2786 : auto bitref = cbitdeq.back();
357 [ - + ]: 2786 : assert(ref == bitref);
358 : : }
359 : 3906 : },
360 : 5833 : [&] {
361 : : // push_back()
362 [ - + + + ]: 5833 : if (cdeq.size() < limitlen) {
363 : 4978 : bool val = ctx.randbool();
364 [ + + ]: 4978 : if (cdeq.empty()) {
365 : 1929 : deq.push_back(val);
366 : 1929 : bitdeq.push_back(val);
367 : : } else {
368 [ - + ]: 3049 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
369 : 3049 : auto& ref = deq[pos];
370 : 3049 : auto bitref = bitdeq[pos];
371 [ - + ]: 3049 : assert(ref == bitref);
372 : 3049 : deq.push_back(val);
373 : 3049 : bitdeq.push_back(val);
374 [ - + ]: 3049 : assert(ref == bitref); // references are not invalidated
375 : 3049 : }
376 : : }
377 : 5833 : },
378 : 8507 : [&] {
379 : : // push_front()
380 [ - + + + ]: 8507 : if (cdeq.size() < limitlen) {
381 : 7823 : bool val = ctx.randbool();
382 [ + + ]: 7823 : if (cdeq.empty()) {
383 : 3126 : deq.push_front(val);
384 : 3126 : bitdeq.push_front(val);
385 : : } else {
386 [ - + ]: 4697 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
387 : 4697 : auto& ref = deq[pos];
388 : 4697 : auto bitref = bitdeq[pos];
389 [ - + ]: 4697 : assert(ref == bitref);
390 : 4697 : deq.push_front(val);
391 : 4697 : bitdeq.push_front(val);
392 [ - + ]: 4697 : assert(ref == bitref); // references are not invalidated
393 : 4697 : }
394 : : }
395 : 8507 : },
396 : 4152 : [&] {
397 : : // pop_back()
398 [ + + ]: 4152 : if (!cdeq.empty()) {
399 [ - + + + ]: 3290 : if (cdeq.size() == 1) {
400 : 917 : deq.pop_back();
401 : 917 : bitdeq.pop_back();
402 : : } else {
403 : 2373 : size_t pos = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 2);
404 : 2373 : auto& ref = deq[pos];
405 : 2373 : auto bitref = bitdeq[pos];
406 [ - + ]: 2373 : assert(ref == bitref);
407 : 2373 : deq.pop_back();
408 : 2373 : bitdeq.pop_back();
409 [ - + ]: 2373 : assert(ref == bitref); // references to other elements are not invalidated
410 : 2373 : }
411 : : }
412 : 4152 : },
413 : 6073 : [&] {
414 : : // pop_front()
415 [ + + ]: 6073 : if (!cdeq.empty()) {
416 [ - + + + ]: 4852 : if (cdeq.size() == 1) {
417 : 1965 : deq.pop_front();
418 : 1965 : bitdeq.pop_front();
419 : : } else {
420 : 2887 : size_t pos = provider.ConsumeIntegralInRange<size_t>(1, cdeq.size() - 1);
421 : 2887 : auto& ref = deq[pos];
422 : 2887 : auto bitref = bitdeq[pos];
423 [ - + ]: 2887 : assert(ref == bitref);
424 : 2887 : deq.pop_front();
425 : 2887 : bitdeq.pop_front();
426 [ - + ]: 2887 : assert(ref == bitref); // references to other elements are not invalidated
427 : 2887 : }
428 : : }
429 : 6073 : },
430 : 6265 : [&] {
431 : : // erase (in middle, single)
432 [ + + ]: 6265 : if (!cdeq.empty()) {
433 [ - + ]: 5247 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - 1);
434 [ - + ]: 5247 : size_t after = cdeq.size() - 1 - before;
435 : 5247 : auto it = deq.erase(cdeq.begin() + before);
436 : 5247 : auto bitit = bitdeq.erase(cbitdeq.begin() + before);
437 [ + - - + ]: 5247 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
438 [ + - + - ]: 10494 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
439 : : }
440 : 6265 : },
441 : 5930 : [&] {
442 : : // erase (at front, range)
443 [ - + ]: 5930 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
444 : 5930 : auto it = deq.erase(cdeq.begin(), cdeq.begin() + count);
445 : 5930 : auto bitit = bitdeq.erase(cbitdeq.begin(), cbitdeq.begin() + count);
446 [ - + ]: 5930 : assert(it == deq.begin());
447 [ + - ]: 5930 : assert(bitit == bitdeq.begin());
448 : 5930 : },
449 : 2195 : [&] {
450 : : // erase (at back, range)
451 [ - + ]: 2195 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
452 : 2195 : auto it = deq.erase(cdeq.end() - count, cdeq.end());
453 : 2195 : auto bitit = bitdeq.erase(cbitdeq.end() - count, cbitdeq.end());
454 [ - + ]: 2195 : assert(it == deq.end());
455 [ + - ]: 2195 : assert(bitit == bitdeq.end());
456 : 2195 : },
457 : 3521 : [&] {
458 : : // erase (in middle, range)
459 [ - + ]: 3521 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
460 [ - + ]: 3521 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size() - count);
461 [ - + ]: 3521 : size_t after = cdeq.size() - count - before;
462 : 3521 : auto it = deq.erase(cdeq.begin() + before, cdeq.end() - after);
463 : 3521 : auto bitit = bitdeq.erase(cbitdeq.begin() + before, cbitdeq.end() - after);
464 [ + - - + ]: 3521 : assert(it == cdeq.begin() + before && it == cdeq.end() - after);
465 [ + - + - ]: 7042 : assert(bitit == cbitdeq.begin() + before && bitit == cbitdeq.end() - after);
466 : 3521 : },
467 : 9751 : [&] {
468 : : // insert/emplace (in middle, single)
469 [ - + + + ]: 9751 : if (cdeq.size() < limitlen) {
470 : 9125 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
471 : 9125 : bool val = ctx.randbool();
472 : 9125 : bool do_emplace = provider.ConsumeBool();
473 : 9125 : auto it = deq.insert(cdeq.begin() + before, val);
474 [ + + ]: 9125 : auto bitit = do_emplace ? bitdeq.emplace(cbitdeq.begin() + before, val)
475 : 9125 : : bitdeq.insert(cbitdeq.begin() + before, val);
476 [ - + ]: 9125 : assert(it == deq.begin() + before);
477 [ + - ]: 9125 : assert(bitit == bitdeq.begin() + before);
478 : : }
479 : 9751 : },
480 : 7231 : [&] {
481 : : // insert (at front, begin/end)
482 [ - + + + ]: 7231 : if (cdeq.size() < limitlen) {
483 : 6751 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
484 : 6751 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
485 : 6751 : auto rand_end = rand_begin + count;
486 : 6751 : auto it = deq.insert(cdeq.begin(), rand_begin, rand_end);
487 : 6751 : auto bitit = bitdeq.insert(cbitdeq.begin(), rand_begin, rand_end);
488 [ - + ]: 6751 : assert(it == cdeq.begin());
489 [ + - ]: 6751 : assert(bitit == cbitdeq.begin());
490 : : }
491 : 7231 : },
492 : 6115 : [&] {
493 : : // insert (at back, begin/end)
494 [ - + + + ]: 6115 : if (cdeq.size() < limitlen) {
495 : 4961 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
496 : 4961 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
497 : 4961 : auto rand_end = rand_begin + count;
498 : 4961 : auto it = deq.insert(cdeq.end(), rand_begin, rand_end);
499 : 4961 : auto bitit = bitdeq.insert(cbitdeq.end(), rand_begin, rand_end);
500 [ - + ]: 4961 : assert(it == cdeq.end() - count);
501 [ + - ]: 4961 : assert(bitit == cbitdeq.end() - count);
502 : : }
503 : 6115 : },
504 : 21679 : [&] {
505 : : // insert (in middle, range)
506 [ - + + + ]: 21679 : if (cdeq.size() < limitlen) {
507 : 17473 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
508 [ - + ]: 17473 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
509 : 17473 : bool val = ctx.randbool();
510 : 17473 : auto it = deq.insert(cdeq.begin() + before, count, val);
511 : 17473 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, count, val);
512 [ - + ]: 17473 : assert(it == deq.begin() + before);
513 [ + - ]: 17473 : assert(bitit == bitdeq.begin() + before);
514 : : }
515 : 21679 : },
516 : 16090 : [&] {
517 : : // insert (in middle, begin/end)
518 [ - + + + ]: 16090 : if (cdeq.size() < limitlen) {
519 : 14142 : size_t count = provider.ConsumeIntegralInRange<size_t>(0, maxlen);
520 [ - + ]: 14142 : size_t before = provider.ConsumeIntegralInRange<size_t>(0, cdeq.size());
521 : 14142 : auto rand_begin = RANDDATA.begin() + ctx.randbits(RANDDATA_BITS);
522 : 14142 : auto rand_end = rand_begin + count;
523 : 14142 : auto it = deq.insert(cdeq.begin() + before, rand_begin, rand_end);
524 : 14142 : auto bitit = bitdeq.insert(cbitdeq.begin() + before, rand_begin, rand_end);
525 [ - + ]: 14142 : assert(it == deq.begin() + before);
526 [ + - ]: 14142 : assert(bitit == bitdeq.begin() + before);
527 : : }
528 : 16090 : });
529 : : }
530 : 801 : {
531 [ - + - + ]: 801 : assert(deq.size() == bitdeq.size());
532 : 801 : auto it = deq.begin();
533 : 801 : auto bitit = bitdeq.begin();
534 : 801 : auto itend = deq.end();
535 [ + + ]: 9576451 : while (it != itend) {
536 [ - + ]: 9575650 : assert(*it == *bitit);
537 : 9575650 : ++it;
538 : 9575650 : ++bitit;
539 : : }
540 : : }
541 : 801 : }
|