1 // Demonstration of rules when an iterator is considered to be valid if the soft
2 // iterator invalidation definition is applied.
3 // Note: The soft iterator invalidation definition CAN NOT be applied
4 // to the space optimized circular buffer.
6 // Copyright (c) 2003-2008 Jan Gaspar
8 // Use, modification, and distribution is subject to the Boost Software
9 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
14 // test of the example (introduced in the documentation)
15 void validity_example_test() {
17 circular_buffer
<int> cb(3);
23 circular_buffer
<int>::iterator it
= cb
.begin();
25 BOOST_CHECK(*it
== 1);
29 BOOST_CHECK(*it
== 4);
32 void validity_insert_test() {
34 int array
[] = { 1, 2, 3 };
36 // memory placement: { 1, 2, 3 }
37 // circular buffer: { 1, 2, 3 }
38 circular_buffer
<int> cb(4, array
, array
+ 3);
40 // it1 -> 1, it2 -> 2, it3 -> 3
41 circular_buffer
<int>::iterator it1
= cb
.begin();
42 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
43 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
45 cb
.insert(cb
.begin() + 1, 4);
47 // memory placement: { 1, 4, 2, 3 }
48 // circular buffer: { 1, 4, 2, 3 }
49 BOOST_CHECK(*it1
== 1);
50 BOOST_CHECK(*it2
== 4);
51 BOOST_CHECK(*it3
== 2);
52 BOOST_CHECK(cb
[0] == 1);
53 BOOST_CHECK(cb
[1] == 4);
54 BOOST_CHECK(cb
[2] == 2);
55 BOOST_CHECK(cb
[3] == 3);
58 circular_buffer
<int>::iterator it4
= it1
+ 3;
60 cb
.insert(cb
.begin() + 1, 5);
62 // memory placement: { 3, 5, 4, 2 }
63 // circular buffer: { 5, 4, 2, 3 }
64 BOOST_CHECK(*it1
== 3);
65 BOOST_CHECK(*it2
== 5);
66 BOOST_CHECK(*it3
== 4);
67 BOOST_CHECK(*it4
== 2);
68 BOOST_CHECK(cb
[0] == 5);
69 BOOST_CHECK(cb
[1] == 4);
70 BOOST_CHECK(cb
[2] == 2);
71 BOOST_CHECK(cb
[3] == 3);
74 void validity_insert_n_test() {
76 // memory placement: { 1, 2, 3 }
77 // circular buffer: { 1, 2, 3 }
78 circular_buffer
<int> cb(5);
83 // it1 -> 1, it2 -> 2, it3 -> 3
84 circular_buffer
<int>::iterator it1
= cb
.begin();
85 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
86 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
88 cb
.insert(cb
.begin() + 1, 2, 4);
90 // memory placement: { 1, 4, 4, 2, 3 }
91 // circular buffer: { 1, 4, 4, 2, 3 }
92 BOOST_CHECK(*it1
== 1);
93 BOOST_CHECK(*it2
== 4);
94 BOOST_CHECK(*it3
== 4);
95 BOOST_CHECK(cb
[0] == 1);
96 BOOST_CHECK(cb
[1] == 4);
97 BOOST_CHECK(cb
[2] == 4);
98 BOOST_CHECK(cb
[3] == 2);
99 BOOST_CHECK(cb
[4] == 3);
101 // it4 -> 2, it5 -> 3
102 circular_buffer
<int>::iterator it4
= it1
+ 3;
103 circular_buffer
<int>::iterator it5
= it1
+ 4;
105 cb
.insert(cb
.begin() + 1, 2, 5);
107 // memory placement: { 3, 5, 4, 4, 2 } - 5 inserted only once
108 // circular buffer: { 5, 4, 4, 2, 3 }
109 BOOST_CHECK(*it1
== 3);
110 BOOST_CHECK(*it2
== 5);
111 BOOST_CHECK(*it3
== 4);
112 BOOST_CHECK(*it4
== 4);
113 BOOST_CHECK(*it5
== 2);
114 BOOST_CHECK(cb
[0] == 5);
115 BOOST_CHECK(cb
[1] == 4);
116 BOOST_CHECK(cb
[2] == 4);
117 BOOST_CHECK(cb
[3] == 2);
118 BOOST_CHECK(cb
[4] == 3);
121 void validity_insert_range_test() {
132 // memory placement: { 1, 2, 3 }
133 // circular buffer: { 1, 2, 3 }
134 circular_buffer
<int> cb1(5);
139 // it11 -> 1, it12 -> 2, it13 -> 3
140 circular_buffer
<int>::iterator it11
= cb1
.begin();
141 circular_buffer
<int>::iterator it12
= cb1
.begin() + 1;
142 circular_buffer
<int>::iterator it13
= cb1
.begin() + 2;
144 cb1
.insert(cb1
.begin() + 1, v1
.begin(), v1
.end());
146 // memory placement: { 1, 4, 5, 2, 3 }
147 // circular buffer: { 1, 4, 5, 2, 3 }
148 BOOST_CHECK(*it11
== 1);
149 BOOST_CHECK(*it12
== 4);
150 BOOST_CHECK(*it13
== 5);
151 BOOST_CHECK(cb1
[0] == 1);
152 BOOST_CHECK(cb1
[1] == 4);
153 BOOST_CHECK(cb1
[2] == 5);
154 BOOST_CHECK(cb1
[3] == 2);
155 BOOST_CHECK(cb1
[4] == 3);
157 // it14 -> 2, it15 -> 3
158 circular_buffer
<int>::iterator it14
= it11
+ 3;
159 circular_buffer
<int>::iterator it15
= it11
+ 4;
161 cb1
.insert(cb1
.begin() + 1, v2
.begin(), v2
.end());
163 // memory placement: { 3, 7, 4, 5, 2 } - 7 inserted only
164 // circular buffer: { 7, 4, 5, 2, 3 }
165 BOOST_CHECK(*it11
== 3);
166 BOOST_CHECK(*it12
== 7);
167 BOOST_CHECK(*it13
== 4);
168 BOOST_CHECK(*it14
== 5);
169 BOOST_CHECK(*it15
== 2);
170 BOOST_CHECK(cb1
[0] == 7);
171 BOOST_CHECK(cb1
[1] == 4);
172 BOOST_CHECK(cb1
[2] == 5);
173 BOOST_CHECK(cb1
[3] == 2);
174 BOOST_CHECK(cb1
[4] == 3);
176 // memory placement: { 1, 2, 3 }
177 // circular buffer: { 1, 2, 3 }
178 circular_buffer
<int> cb2(5);
183 // it21 -> 1, it22 -> 2, it23 -> 3
184 circular_buffer
<int>::iterator it21
= cb2
.begin();
185 circular_buffer
<int>::iterator it22
= cb2
.begin() + 1;
186 circular_buffer
<int>::iterator it23
= cb2
.begin() + 2;
188 cb2
.insert(cb2
.begin() + 1, MyInputIterator(v1
.begin()), MyInputIterator(v1
.end()));
190 // memory placement: { 1, 4, 5, 2, 3 }
191 // circular buffer: { 1, 4, 5, 2, 3 }
192 BOOST_CHECK(*it21
== 1);
193 BOOST_CHECK(*it22
== 4);
194 BOOST_CHECK(*it23
== 5);
195 BOOST_CHECK(cb2
[0] == 1);
196 BOOST_CHECK(cb2
[1] == 4);
197 BOOST_CHECK(cb2
[2] == 5);
198 BOOST_CHECK(cb2
[3] == 2);
199 BOOST_CHECK(cb2
[4] == 3);
201 // it24 -> 2, it25 -> 3
202 circular_buffer
<int>::iterator it24
= it21
+ 3;
203 circular_buffer
<int>::iterator it25
= it21
+ 4;
205 cb2
.insert(cb2
.begin() + 1, MyInputIterator(v2
.begin()), MyInputIterator(v2
.end()));
207 // memory placement: { 2, 3, 7, 4, 5 } - using input iterator inserts all items even if they are later replaced
208 // circular buffer: { 7, 4, 5, 2, 3 }
209 BOOST_CHECK(*it21
== 2);
210 BOOST_CHECK(*it22
== 3);
211 BOOST_CHECK(*it23
== 7);
212 BOOST_CHECK(*it24
== 4);
213 BOOST_CHECK(*it25
== 5);
214 BOOST_CHECK(cb2
[0] == 7);
215 BOOST_CHECK(cb2
[1] == 4);
216 BOOST_CHECK(cb2
[2] == 5);
217 BOOST_CHECK(cb2
[3] == 2);
218 BOOST_CHECK(cb2
[4] == 3);
221 void validity_rinsert_test() {
223 int array
[] = { 1, 2, 3 };
225 // memory placement: { 1, 2, 3 }
226 // circular buffer: { 1, 2, 3 }
227 circular_buffer
<int> cb(4, array
, array
+ 3);
229 // it1 -> 1, it2 -> 2, it3 -> 3
230 circular_buffer
<int>::iterator it1
= cb
.begin();
231 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
232 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
234 cb
.rinsert(cb
.begin() + 2, 4);
236 // memory placement: { 2, 4, 3, 1 }
237 // circular buffer: { 1, 2, 4, 3 }
238 BOOST_CHECK(*it1
== 2);
239 BOOST_CHECK(*it2
== 4);
240 BOOST_CHECK(*it3
== 3);
241 BOOST_CHECK(cb
[0] == 1);
242 BOOST_CHECK(cb
[1] == 2);
243 BOOST_CHECK(cb
[2] == 4);
244 BOOST_CHECK(cb
[3] == 3);
247 circular_buffer
<int>::iterator it4
= it1
- 1;
249 cb
.rinsert(cb
.begin() + 2, 5);
251 // memory placement: { 5, 4, 1, 2 }
252 // circular buffer: { 1, 2, 5, 4 }
253 BOOST_CHECK(*it1
== 5);
254 BOOST_CHECK(*it2
== 4);
255 BOOST_CHECK(*it3
== 1);
256 BOOST_CHECK(*it4
== 2);
257 BOOST_CHECK(cb
[0] == 1);
258 BOOST_CHECK(cb
[1] == 2);
259 BOOST_CHECK(cb
[2] == 5);
260 BOOST_CHECK(cb
[3] == 4);
263 void validity_rinsert_n_test() {
265 // memory placement: { 1, 2, 3 }
266 // circular buffer: { 1, 2, 3 }
267 circular_buffer
<int> cb(5);
272 // it1 -> 1, it2 -> 2, it3 -> 3
273 circular_buffer
<int>::iterator it1
= cb
.begin();
274 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
275 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
277 cb
.rinsert(cb
.begin() + 2, 2, 4);
279 // memory placement: { 4, 4, 3, 1, 2 }
280 // circular buffer: { 1, 2, 4, 4, 3 }
281 BOOST_CHECK(*it1
== 4);
282 BOOST_CHECK(*it2
== 4);
283 BOOST_CHECK(*it3
== 3);
284 BOOST_CHECK(cb
[0] == 1);
285 BOOST_CHECK(cb
[1] == 2);
286 BOOST_CHECK(cb
[2] == 4);
287 BOOST_CHECK(cb
[3] == 4);
288 BOOST_CHECK(cb
[4] == 3);
290 // it4 -> 1, it5 -> 2
291 circular_buffer
<int>::iterator it4
= it1
- 2;
292 circular_buffer
<int>::iterator it5
= it1
- 1;
294 cb
.rinsert(cb
.begin() + 4, 2, 5);
296 // memory placement: { 4, 5, 1, 2, 4 } - 5 inserted only once
297 // circular buffer: { 1, 2, 4, 4, 5 }
298 BOOST_CHECK(*it1
== 4);
299 BOOST_CHECK(*it2
== 5);
300 BOOST_CHECK(*it3
== 1);
301 BOOST_CHECK(*it4
== 2);
302 BOOST_CHECK(*it5
== 4);
303 BOOST_CHECK(cb
[0] == 1);
304 BOOST_CHECK(cb
[1] == 2);
305 BOOST_CHECK(cb
[2] == 4);
306 BOOST_CHECK(cb
[3] == 4);
307 BOOST_CHECK(cb
[4] == 5);
310 void validity_rinsert_range_test() {
321 // memory placement: { 1, 2, 3 }
322 // circular buffer: { 1, 2, 3 }
323 circular_buffer
<int> cb1(5);
328 // it1 -> 1, it2 -> 2, it3 -> 3
329 circular_buffer
<int>::iterator it11
= cb1
.begin();
330 circular_buffer
<int>::iterator it12
= cb1
.begin() + 1;
331 circular_buffer
<int>::iterator it13
= cb1
.begin() + 2;
333 cb1
.rinsert(cb1
.begin() + 2, v1
.begin(), v1
.end());
335 // memory placement: { 4, 5, 3, 1, 2 }
336 // circular buffer: { 1, 2, 4, 5, 3 }
337 BOOST_CHECK(*it11
== 4);
338 BOOST_CHECK(*it12
== 5);
339 BOOST_CHECK(*it13
== 3);
340 BOOST_CHECK(cb1
[0] == 1);
341 BOOST_CHECK(cb1
[1] == 2);
342 BOOST_CHECK(cb1
[2] == 4);
343 BOOST_CHECK(cb1
[3] == 5);
344 BOOST_CHECK(cb1
[4] == 3);
346 // it14 -> 1, it15 -> 2
347 circular_buffer
<int>::iterator it14
= it11
- 2;
348 circular_buffer
<int>::iterator it15
= it11
- 1;
350 cb1
.rinsert(cb1
.begin() + 4, v2
.begin(), v2
.end());
352 // memory placement: { 5, 6, 1, 2, 4 } - 6 inserted only
353 // circular buffer: { 1, 2, 4, 5, 6 }
354 BOOST_CHECK(*it11
== 5);
355 BOOST_CHECK(*it12
== 6);
356 BOOST_CHECK(*it13
== 1);
357 BOOST_CHECK(*it14
== 2);
358 BOOST_CHECK(*it15
== 4);
359 BOOST_CHECK(cb1
[0] == 1);
360 BOOST_CHECK(cb1
[1] == 2);
361 BOOST_CHECK(cb1
[2] == 4);
362 BOOST_CHECK(cb1
[3] == 5);
363 BOOST_CHECK(cb1
[4] == 6);
365 // memory placement: { 1, 2, 3 }
366 // circular buffer: { 1, 2, 3 }
367 circular_buffer
<int> cb2(5);
372 // it1 -> 1, it2 -> 2, it3 -> 3
373 circular_buffer
<int>::iterator it21
= cb2
.begin();
374 circular_buffer
<int>::iterator it22
= cb2
.begin() + 1;
375 circular_buffer
<int>::iterator it23
= cb2
.begin() + 2;
377 cb2
.rinsert(cb2
.begin() + 2, MyInputIterator(v1
.begin()), MyInputIterator(v1
.end()));
379 // memory placement: { 4, 5, 3, 1, 2 }
380 // circular buffer: { 1, 2, 4, 5, 3 }
381 BOOST_CHECK(*it21
== 4);
382 BOOST_CHECK(*it22
== 5);
383 BOOST_CHECK(*it23
== 3);
384 BOOST_CHECK(cb2
[0] == 1);
385 BOOST_CHECK(cb2
[1] == 2);
386 BOOST_CHECK(cb2
[2] == 4);
387 BOOST_CHECK(cb2
[3] == 5);
388 BOOST_CHECK(cb2
[4] == 3);
390 // it24 -> 1, it25 -> 2
391 circular_buffer
<int>::iterator it24
= it21
- 2;
392 circular_buffer
<int>::iterator it25
= it21
- 1;
394 cb2
.rinsert(cb2
.begin() + 4, MyInputIterator(v2
.begin()), MyInputIterator(v2
.end()));
396 // memory placement: { 5, 6, 1, 2, 4 }
397 // circular buffer: { 1, 2, 4, 5, 6 }
398 BOOST_CHECK(*it21
== 5);
399 BOOST_CHECK(*it22
== 6);
400 BOOST_CHECK(*it23
== 1);
401 BOOST_CHECK(*it24
== 2);
402 BOOST_CHECK(*it25
== 4);
403 BOOST_CHECK(cb2
[0] == 1);
404 BOOST_CHECK(cb2
[1] == 2);
405 BOOST_CHECK(cb2
[2] == 4);
406 BOOST_CHECK(cb2
[3] == 5);
407 BOOST_CHECK(cb2
[4] == 6);
410 void validity_erase_test() {
412 // memory placement: { 4, 5, 1, 2, 3 }
413 // circular buffer: { 1, 2, 3, 4, 5 }
414 circular_buffer
<int> cb(5);
423 // it1 -> 1, it2 -> 2, it3 -> 3, it4 -> 4
424 circular_buffer
<int>::iterator it1
= cb
.begin();
425 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
426 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
427 circular_buffer
<int>::iterator it4
= cb
.begin() + 3;
429 cb
.erase(cb
.begin() + 1);
431 // memory placement: { 5, X, 1, 3, 4 }
432 // circular buffer: { 1, 3, 4, 5 }
433 BOOST_CHECK(*it1
== 1);
434 BOOST_CHECK(*it2
== 3);
435 BOOST_CHECK(*it3
== 4);
436 BOOST_CHECK(*it4
== 5);
437 BOOST_CHECK(cb
[0] == 1);
438 BOOST_CHECK(cb
[1] == 3);
439 BOOST_CHECK(cb
[2] == 4);
440 BOOST_CHECK(cb
[3] == 5);
443 void validity_erase_range_test() {
445 // memory placement: { 4, 5, 6, 1, 2, 3 }
446 // circular buffer: { 1, 2, 3, 4, 5, 6 }
447 circular_buffer
<int> cb(6);
458 // it1 -> 1, it2 -> 2, it3 -> 3, it4 -> 4
459 circular_buffer
<int>::iterator it1
= cb
.begin();
460 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
461 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
462 circular_buffer
<int>::iterator it4
= cb
.begin() + 3;
464 cb
.erase(cb
.begin() + 2, cb
.begin() + 4);
466 // memory placement: { 6, X, X, 1, 2, 5 }
467 // circular buffer: { 1, 2, 5, 6 }
468 BOOST_CHECK(*it1
== 1);
469 BOOST_CHECK(*it2
== 2);
470 BOOST_CHECK(*it3
== 5);
471 BOOST_CHECK(*it4
== 6);
472 BOOST_CHECK(cb
[0] == 1);
473 BOOST_CHECK(cb
[1] == 2);
474 BOOST_CHECK(cb
[2] == 5);
475 BOOST_CHECK(cb
[3] == 6);
478 void validity_rerase_test() {
480 // memory placement: { 4, 5, 1, 2, 3 }
481 // circular buffer: { 1, 2, 3, 4, 5 }
482 circular_buffer
<int> cb(5);
491 // it1 -> 2, it2 -> 3, it3 -> 4, it4 -> 5
492 circular_buffer
<int>::iterator it1
= cb
.begin() + 1;
493 circular_buffer
<int>::iterator it2
= cb
.begin() + 2;
494 circular_buffer
<int>::iterator it3
= cb
.begin() + 3;
495 circular_buffer
<int>::iterator it4
= cb
.begin() + 4;
497 cb
.rerase(cb
.begin() + 1);
499 // memory placement: { 4, 5, X, 1, 3 }
500 // circular buffer: { 1, 3, 4, 5 }
501 BOOST_CHECK(*it1
== 1);
502 BOOST_CHECK(*it2
== 3);
503 BOOST_CHECK(*it3
== 4);
504 BOOST_CHECK(*it4
== 5);
505 BOOST_CHECK(cb
[0] == 1);
506 BOOST_CHECK(cb
[1] == 3);
507 BOOST_CHECK(cb
[2] == 4);
508 BOOST_CHECK(cb
[3] == 5);
511 void validity_rerase_range_test() {
513 // memory placement: { 4, 5, 6, 1, 2, 3 }
514 // circular buffer: { 1, 2, 3, 4, 5, 6 }
515 circular_buffer
<int> cb(6);
526 // it1 -> 3, it2 -> 4, it3 -> 5, it4 -> 6
527 circular_buffer
<int>::iterator it1
= cb
.begin() + 2;
528 circular_buffer
<int>::iterator it2
= cb
.begin() + 3;
529 circular_buffer
<int>::iterator it3
= cb
.begin() + 4;
530 circular_buffer
<int>::iterator it4
= cb
.begin() + 5;
532 cb
.rerase(cb
.begin() + 2, cb
.begin() + 4);
534 // memory placement: { 2, 5, 6, X, X, 1 }
535 // circular buffer: { 1, 2, 5, 6 }
536 BOOST_CHECK(*it1
== 1);
537 BOOST_CHECK(*it2
== 2);
538 BOOST_CHECK(*it3
== 5);
539 BOOST_CHECK(*it4
== 6);
540 BOOST_CHECK(cb
[0] == 1);
541 BOOST_CHECK(cb
[1] == 2);
542 BOOST_CHECK(cb
[2] == 5);
543 BOOST_CHECK(cb
[3] == 6);
546 void validity_linearize_test() {
548 // memory placement: { 3, 1, 2 }
549 // circular buffer: { 1, 2, 3 }
550 circular_buffer
<int> cb(3);
556 // it1 -> 1, it2 -> 2, it3 -> 3
557 circular_buffer
<int>::iterator it1
= cb
.begin();
558 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
559 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
563 // memory placement: { 1, 2, 3 }
564 // circular buffer: { 1, 2, 3 }
565 BOOST_CHECK(*it1
== 2);
566 BOOST_CHECK(*it2
== 3);
567 BOOST_CHECK(*it3
== 1);
568 BOOST_CHECK(cb
[0] == 1);
569 BOOST_CHECK(cb
[1] == 2);
570 BOOST_CHECK(cb
[2] == 3);
573 void validity_swap_test() {
575 // memory placement: { 3, 1, 2 }
576 // circular buffer: { 1, 2, 3 }
577 circular_buffer
<int> cb1(3);
583 // it11 -> 1, it12 -> 2, it13 -> 3
584 circular_buffer
<int>::iterator it11
= cb1
.begin();
585 circular_buffer
<int>::iterator it12
= cb1
.begin() + 1;
586 circular_buffer
<int>::iterator it13
= cb1
.begin() + 2;
588 // memory placement: { 4, 5, 6 }
589 // circular buffer: { 4, 5, 6 }
590 circular_buffer
<int> cb2(5);
595 // it21 -> 4, it22 -> 5, it23 -> 6
596 circular_buffer
<int>::iterator it21
= cb2
.begin();
597 circular_buffer
<int>::iterator it22
= cb2
.begin() + 1;
598 circular_buffer
<int>::iterator it23
= cb2
.begin() + 2;
602 // Although iterators refer to the original elements,
603 // their interal state is inconsistent and no other operation
604 // (except dereferencing) can be invoked on them any more.
605 BOOST_CHECK(*it11
== 1);
606 BOOST_CHECK(*it12
== 2);
607 BOOST_CHECK(*it13
== 3);
608 BOOST_CHECK(*it21
== 4);
609 BOOST_CHECK(*it22
== 5);
610 BOOST_CHECK(*it23
== 6);
611 BOOST_CHECK(cb1
[0] == 4);
612 BOOST_CHECK(cb1
[1] == 5);
613 BOOST_CHECK(cb1
[2] == 6);
614 BOOST_CHECK(cb2
[0] == 1);
615 BOOST_CHECK(cb2
[1] == 2);
616 BOOST_CHECK(cb2
[2] == 3);
619 void validity_push_back_test() {
621 // memory placement: { 3, 1, 2 }
622 // circular buffer: { 1, 2, 3 }
623 circular_buffer
<int> cb(3);
629 // it1 -> 1, it2 -> 2, it3 -> 3
630 circular_buffer
<int>::iterator it1
= cb
.begin();
631 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
632 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
636 // memory placement: { 3, 4, 2 }
637 // circular buffer: { 2, 3, 4 }
638 BOOST_CHECK(*it1
== 4);
639 BOOST_CHECK(*it2
== 2);
640 BOOST_CHECK(*it3
== 3);
641 BOOST_CHECK(cb
[0] == 2);
642 BOOST_CHECK(cb
[1] == 3);
643 BOOST_CHECK(cb
[2] == 4);
646 void validity_push_front_test() {
648 // memory placement: { 3, 1, 2 }
649 // circular buffer: { 1, 2, 3 }
650 circular_buffer
<int> cb(3);
656 // it1 -> 1, it2 -> 2, it3 -> 3
657 circular_buffer
<int>::iterator it1
= cb
.begin();
658 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
659 circular_buffer
<int>::iterator it3
= cb
.begin() + 2;
663 // memory placement: { 4, 1, 2 }
664 // circular buffer: { 4, 1, 2 }
665 BOOST_CHECK(*it1
== 1);
666 BOOST_CHECK(*it2
== 2);
667 BOOST_CHECK(*it3
== 4);
668 BOOST_CHECK(cb
[0] == 4);
669 BOOST_CHECK(cb
[1] == 1);
670 BOOST_CHECK(cb
[2] == 2);
673 void validity_pop_back_test() {
675 // memory placement: { 3, 1, 2 }
676 // circular buffer: { 1, 2, 3 }
677 circular_buffer
<int> cb(3);
683 // it1 -> 1, it2 -> 2
684 circular_buffer
<int>::iterator it1
= cb
.begin();
685 circular_buffer
<int>::iterator it2
= cb
.begin() + 1;
689 // memory placement: { X, 1, 2 }
690 // circular buffer: { 1, 2 }
691 BOOST_CHECK(*it1
== 1);
692 BOOST_CHECK(*it2
== 2);
693 BOOST_CHECK(cb
[0] == 1);
694 BOOST_CHECK(cb
[1] == 2);
697 void validity_pop_front_test() {
699 // memory placement: { 3, 1, 2 }
700 // circular buffer: { 1, 2, 3 }
701 circular_buffer
<int> cb(3);
707 // it1 -> 2, it2 -> 3
708 circular_buffer
<int>::iterator it1
= cb
.begin() + 1;
709 circular_buffer
<int>::iterator it2
= cb
.begin() + 2;
713 // memory placement: { 3, X, 2 }
714 // circular buffer: { 2, 3 }
715 BOOST_CHECK(*it1
== 2);
716 BOOST_CHECK(*it2
== 3);
717 BOOST_CHECK(cb
[0] == 2);
718 BOOST_CHECK(cb
[1] == 3);
722 test_suite
* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
724 test_suite
* tests
= BOOST_TEST_SUITE("Unit tests for the iterator of the circular_buffer.");
726 tests
->add(BOOST_TEST_CASE(&validity_example_test
));
727 tests
->add(BOOST_TEST_CASE(&validity_insert_test
));
728 tests
->add(BOOST_TEST_CASE(&validity_insert_n_test
));
729 tests
->add(BOOST_TEST_CASE(&validity_insert_range_test
));
730 tests
->add(BOOST_TEST_CASE(&validity_rinsert_test
));
731 tests
->add(BOOST_TEST_CASE(&validity_rinsert_n_test
));
732 tests
->add(BOOST_TEST_CASE(&validity_rinsert_range_test
));
733 tests
->add(BOOST_TEST_CASE(&validity_erase_test
));
734 tests
->add(BOOST_TEST_CASE(&validity_erase_range_test
));
735 tests
->add(BOOST_TEST_CASE(&validity_rerase_test
));
736 tests
->add(BOOST_TEST_CASE(&validity_rerase_range_test
));
737 tests
->add(BOOST_TEST_CASE(&validity_linearize_test
));
738 tests
->add(BOOST_TEST_CASE(&validity_swap_test
));
739 tests
->add(BOOST_TEST_CASE(&validity_push_back_test
));
740 tests
->add(BOOST_TEST_CASE(&validity_push_front_test
));
741 tests
->add(BOOST_TEST_CASE(&validity_pop_back_test
));
742 tests
->add(BOOST_TEST_CASE(&validity_pop_front_test
));