-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathplf_list_test_suite.cpp
2145 lines (1439 loc) · 48.3 KB
/
plf_list_test_suite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#if defined(_MSC_VER) && !defined(__clang__) && !defined(__GNUC__)
#if _MSC_VER >= 1600
#define PLF_TEST_MOVE_SEMANTICS_SUPPORT
#endif
#if _MSC_VER >= 1700
#define PLF_TEST_TYPE_TRAITS_SUPPORT
#endif
#if _MSC_VER >= 1800
#define PLF_TEST_VARIADICS_SUPPORT // Variadics, in this context, means both variadic templates and variadic macros are supported
#define PLF_TEST_INITIALIZER_LIST_SUPPORT
#endif
#if defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L) && _MSC_VER >= 1929
#define PLF_TEST_CPP20_SUPPORT
#endif
#elif defined(__cplusplus) && __cplusplus >= 201103L // C++11 support, at least
#define PLF_TEST_MOVE_SEMANTICS_SUPPORT
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__clang__) // If compiler is GCC/G++
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 // 4.2 and below do not support variadic templates
#define PLF_TEST_MOVE_SEMANTICS_SUPPORT
#define PLF_TEST_VARIADICS_SUPPORT
#endif
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __GNUC__ > 4 // 4.3 and below do not support initializer lists
#define PLF_TEST_INITIALIZER_LIST_SUPPORT
#endif
#if __GNUC__ >= 5 // GCC v4.9 and below do not support std::is_trivially_copyable
#define PLF_TEST_TYPE_TRAITS_SUPPORT
#endif
#elif defined(__clang__) && !defined(__GLIBCXX__) && !defined(_LIBCPP_CXX03_LANG)
#if __clang_major__ >= 3 // clang versions < 3 don't support __has_feature() or traits
#define PLF_TEST_TYPE_TRAITS_SUPPORT
#if __has_feature(cxx_rvalue_references) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
#define PLF_TEST_MOVE_SEMANTICS_SUPPORT
#endif
#if __has_feature(cxx_variadic_templates) && !defined(_LIBCPP_HAS_NO_VARIADICS)
#define PLF_TEST_VARIADICS_SUPPORT
#endif
#if (__clang_major__ == 3 && __clang_minor__ >= 1) || __clang_major__ > 3
#define PLF_TEST_INITIALIZER_LIST_SUPPORT
#endif
#endif
#elif defined(__GLIBCXX__)
#if __GLIBCXX__ >= 20080606
#define PLF_TEST_MOVE_SEMANTICS_SUPPORT
#define PLF_TEST_VARIADICS_SUPPORT
#endif
#if __GLIBCXX__ >= 20090421
#define PLF_TEST_INITIALIZER_LIST_SUPPORT
#endif
#if __GLIBCXX__ >= 20150422
#define PLF_TEST_TYPE_TRAITS_SUPPORT
#endif
#elif !(defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) || defined(_LIBCPP_HAS_NO_VARIADICS))
// Assume full support for other compilers and standard libraries
#define PLF_TEST_VARIADICS_SUPPORT
#define PLF_TEST_TYPE_TRAITS_SUPPORT
#define PLF_TEST_MOVE_SEMANTICS_SUPPORT
#define PLF_TEST_INITIALIZER_LIST_SUPPORT
#endif
#if __cplusplus > 201704L && ((((defined(__clang__) && !defined(__APPLE_CC__) && __clang_major__ >= 14) || (defined(__GNUC__) && (__GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ > 0)))) && ((defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 14) || (defined(__GLIBCXX__) && __GLIBCXX__ >= 201806L))) || (!defined(__clang__) && !defined(__GNUC__)))
#define PLF_TEST_CPP20_SUPPORT
#endif
#endif
#include <functional> // std::greater
#include <vector> // range-insert testing
#include <iostream>
#include <algorithm> // std::find
#include <cstdio> // log redirection
#include <cstdlib> // abort
#ifdef PLF_TEST_MOVE_SEMANTICS_SUPPORT
#include <utility> // std::move
#include <memory> // std::shared_ptr
#endif
#include "plf_list.h"
void title1(const char *title_text)
{
std::cout << std::endl << std::endl << std::endl << "*** " << title_text << " ***" << std::endl;
std::cout << "===========================================" << std::endl << std::endl << std::endl;
}
void title2(const char *title_text)
{
std::cout << std::endl << std::endl << "--- " << title_text << " ---" << std::endl << std::endl;
}
void title3(const char *title_text)
{
std::cout << std::endl << title_text << std::endl;
}
void failpass(const char *test_type, bool condition)
{
std::cout << "\n" << test_type << ": ";
if (condition)
{
std::cout << "Pass\n\n";
}
else
{
std::cout << "Fail" << std::endl;
std::cin.get();
abort();
}
}
struct small_struct
{
double *empty_field_1;
double unused_number;
unsigned int empty_field2;
double *empty_field_3;
int number;
unsigned int empty_field4;
small_struct(const int num): number(num) {};
};
// For remove_if testing:
template <class T>
struct larger_than_fifteen
{
bool operator() (const T &value)
{
return value > 15;
}
};
#ifdef PLF_TEST_VARIADICS_SUPPORT
struct perfect_forwarding_test
{
const bool success;
perfect_forwarding_test(int&& /*perfect1*/, int& perfect2)
: success(true)
{
perfect2 = 1;
}
template <typename T, typename U>
perfect_forwarding_test(T&& /*imperfect1*/, U&& /*imperfect2*/)
: success(false)
{}
};
#endif
unsigned int generic_global = 0;
struct small_struct_non_trivial
{
double *empty_field_1;
double unused_number;
unsigned int empty_field2;
double *empty_field_3;
double number;
unsigned int empty_field4;
int operator * () const { return number; };
bool operator == (const small_struct_non_trivial &source) const { return source.number == number; };
bool operator != (const small_struct_non_trivial &source) const { return source.number != number; };
bool operator > (const small_struct_non_trivial &source) const { return number > source.number; };
bool operator < (const small_struct_non_trivial &source) const { return number < source.number; };
bool operator >= (const small_struct_non_trivial &source) const { return number >= source.number; };
bool operator <= (const small_struct_non_trivial &source) const { return number <= source.number; };
small_struct_non_trivial(const unsigned int num): number(num) {};
~small_struct_non_trivial()
{
++generic_global;
}
};
int main()
{
freopen("errors.log","w", stderr);
using namespace plf;
#if defined(PLF_TEST_INITIALIZER_LIST_SUPPORT) || defined(PLF_TEST_MOVE_SEMANTICS_SUPPORT)
bool passed = true;
#endif
#ifndef PLF_TEST_INITIALIZER_LIST_SUPPORT
std::cout << "Initializer_list support (C++11 or higher) is required for most tests. Most tests will skipped without it. Press ENTER to continue." << std::endl;
std::cin.get();
#endif
for (unsigned int prime_loop_counter = 0; prime_loop_counter != 50; ++prime_loop_counter)
{
int test_counter = 1;
{
title2("Non-trivial type tests");
plf::list<small_struct_non_trivial> sslist1;
for (int counter = 0; counter != 50; ++counter)
{
sslist1.push_back(small_struct_non_trivial(counter));
}
unsigned int size = sslist1.size();
failpass("Non-trivial insert test", size == 50);
for (plf::list<small_struct_non_trivial>::iterator it = sslist1.begin(); it != sslist1.end();)
{
if ((rand() & 7) == 0)
{
it = sslist1.erase(it);
--size;
}
else
{
++it;
}
}
failpass("Non-trivial erase test", sslist1.size() == size);
}
#ifdef PLF_TEST_INITIALIZER_LIST_SUPPORT
{
title2("Merge tests");
plf::list<int> list1;
list1.insert(list1.end(), {1, 3, 5, 7, 9});
plf::list<int> list2 = {2, 4, 6, 8, 10};
list1.merge(list2);
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if (test_counter++ != *it)
{
passed = false;
}
}
failpass("Merge test", passed);
title2("Clear tests");
list1.clear();
list2.clear();
list1.push_back(15);
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
++test_counter;
}
failpass("Push_back singular post-clear test", list1.size() == static_cast<unsigned int>(test_counter) && list1.size() == 1);
list1.insert(list1.begin(), 14);
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
++test_counter;
}
failpass("Insert singular post-clear test", list1.size() == static_cast<unsigned int>(test_counter) && list1.size() == 2);
list1.clear();
title2("Splice tests");
list1 = {1, 2, 3, 4, 5};
list2 = {6, 7, 8, 9, 10};
list1.splice(list1.end(), list2);
test_counter = 1;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if (test_counter++ != *it)
{
passed = false;
}
}
failpass("Test splice at end", passed);
list1.clear();
list2.clear();
list1 = {1, 2, 3, 4, 5};
list2 = {6, 7, 8, 9, 10};
list1.splice(list1.begin(), list2);
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
test_counter += *it;
}
failpass("Test splice at begin", test_counter == 55);
list1.clear();
list2.clear();
list1 = {1, 2, 3, 4, 5};
list2 = {6, 7, 8, 9, 10};
plf::list<int>::iterator it2 = list1.begin();
std::advance(it2, 3);
list1.splice(it2, list2);
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
test_counter += *it;
}
list1.clear();
list2.clear();
for (int counter = 1; counter != 25; ++counter)
{
list1.push_back(counter);
list2.push_back(counter + 25);
}
plf::list<int>::iterator it3 = list1.begin();
std::advance(it3, 18);
list1.splice(it3, list2);
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
test_counter += *it;
}
failpass("Test splice past middle", test_counter == 1200);
list1.clear();
list2.clear();
for (int counter = 5; counter != 36; ++counter)
{
list1.push_back(counter);
list2.push_front(counter);
}
list1.splice(list1.begin(), list2);
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
test_counter += *it;
}
failpass("Large list splice", test_counter == 1240);
title2("Sort tests");
list1.sort();
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if(*it < test_counter)
{
passed = false;
}
test_counter = *it;
}
failpass("Sort ((default) less than)", passed);
list1.sort(std::greater<int>());
test_counter = 65535;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if(*it > test_counter)
{
passed = false;
}
test_counter = *it;
}
failpass("Sort ((predicate), greater than)", passed);
title2("Reverse tests");
list1.reverse();
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if(*it < test_counter)
{
passed = false;
}
test_counter = *it;
}
failpass("Reverse test 1", passed);
list2.clear();
plf::list<int> list3;
int counter2 = 50000;
for (int counter = 0; counter != 50000; ++counter)
{
list2.push_back(counter);
list3.push_back(--counter2);
}
list2.reverse();
it2 = list2.begin(), it3 = list3.begin();
do
{
if (*it2++ != *it3++)
{
passed = false;
break;
}
} while(it2 != list2.end());
failpass("Reverse test 2", passed);
title2("Unique tests");
list1.unique();
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if(*it == test_counter)
{
passed = false;
}
test_counter = *it;
}
failpass("Unique test", passed);
title2("Remove tests");
list1.remove_if(larger_than_fifteen<int>());
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if (*it > 15)
{
passed = false;
}
}
failpass("remove_if ( > 15) test", passed);
list1.clear();
list2.clear();
list1 = {5, 5, 4, 4};
list1.remove(5);
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if(*it == 5)
{
passed = false;
}
}
failpass("remove ( == 5) test", passed);
list1.remove(4);
failpass("Remove to create empty list test", list1.empty());
title2("Reserve tests");
list1.clear();
list2.clear();
list1.reserve(4097);
std::cout << "\nInitial capacity after reserve = " << list1.capacity() << std::endl;
failpass("Reserve from empty test", list1.capacity() >= 4097);
list1.push_back(15);
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
++test_counter;
}
failpass("Push_back singular test post-reserve", list1.size() == static_cast<unsigned int>(test_counter));
list1.insert(list1.end(), 10000, 15);
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
++test_counter;
}
std::cout << "\nSize (after iteration) = " << test_counter << std::endl;
std::cout << "\nCapacity after insertion = " << list1.capacity() << std::endl;
failpass("Fill-insert test", list1.size() == 10001 && test_counter == 10001 && list1.capacity() >= 10001);
list1.reserve(15000);
std::cout << "\nCapacity after 2nd reserve = " << list1.capacity() << std::endl;
failpass("Reserve post-insertion test", list1.capacity() >= 15000);
title2("Resize tests");
list1.resize(2);
std::cout << "\nCapacity after resize = " << list1.capacity() << std::endl;
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
++test_counter;
}
failpass("Resize test", list1.size() == 2 && test_counter == 2);
title2("Assign tests");
std::vector<int> test_vector = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
list1.assign(test_vector.begin(), test_vector.end());
std::cout << "\nCapacity after range-assign = " << list1.capacity() << std::endl;
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if (++test_counter != *it)
{
passed = false;
}
}
failpass("Range-assign test", list1.size() == 10 && test_counter == 10 && passed);
list1.assign(20, 1);
std::cout << "\nCapacity after fill-assign = " << list1.capacity() << std::endl;
test_counter = 0;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
++test_counter;
if (*it != 1)
{
passed = false;
}
}
failpass("Fill-assign test", list1.size() == 20 && test_counter == 20 && passed);
std::initializer_list<int> inlist = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
list1.assign(inlist);
std::cout << "\nCapacity after initializer-list assign = " << list1.capacity() << std::endl;
test_counter = 11;
for (plf::list<int>::iterator it = list1.begin(); it != list1.end(); ++it)
{
std::cout << *it << ", ";
if (--test_counter != *it)
{
passed = false;
}
}
failpass("Initializer-list assign test", list1.size() == 10 && test_counter == 1 && passed);
title2("Insert tests");
list2.insert(list2.end(), test_vector.begin(), test_vector.end());
test_counter = 1;
for (plf::list<int>::iterator it = list2.begin(); it != list2.end(); ++it)
{
std::cout << *it << ", ";
if (test_counter++ != *it)
{
passed = false;
}
}
failpass("Range-insert test", passed);
#ifdef PLF_TEST_CPP20_SUPPORT
{
plf::list<int> list5(list2.begin(), list2.cend());
failpass("Range construction with differing iterators test", list5.size() == list2.size());
plf::list<int> list6;
list6.insert(list6.end(), list2.begin(), list2.cend());
failpass("Range insertion with differing iterators test", list6.size() == list2.size());
}
#endif
list2.insert(list2.begin(), 50, 50000);
test_counter = 0;
for (plf::list<int>::iterator it = list2.begin(); it != list2.end(); ++it)
{
++test_counter;
}
failpass("Fill-insert post range-insert test", test_counter == 60 && list2.size() == 60);
test_counter = 0;
while (!list2.empty())
{
for (plf::list<int>::iterator it = list2.begin(); it != list2.end();)
{
if ((rand() & 15) == 0)
{
list2.insert(it, 13);
}
if ((rand() & 7) == 0)
{
it = list2.erase(it);
}
else
{
++it;
}
++test_counter;
}
unsigned int size_counter = 0;
for (plf::list<int>::iterator it = list2.begin(); it != list2.end(); ++it)
{
++size_counter;
}
if (size_counter != list2.size())
{
std::cout << "Failing at counter == " << test_counter << std::endl;
std::cin.get();
abort();
}
}
failpass("Erase and insert randomly till empty test", list2.empty());
list1.clear();
list2.clear();
test_counter = 0;
for (unsigned int counter = 0; counter != 500; ++counter)
{
list1.emplace_back(1);
list2.emplace_front(1);
test_counter += 2;
for (counter2 = 0; counter2 != 50; ++counter2)
{
if ((rand() & 7) == 0)
{
list1.emplace_back(counter2);
++test_counter;
}
if ((rand() & 15) == 0)
{
list2.emplace_back(counter2);
++test_counter;
}
}
for (plf::list<int>::iterator it = list1.begin(); it != list1.end();)
{
if ((rand() & 7) == 0)
{
list1.insert(it, 13);
++test_counter;
}
if ((rand() & 3) == 0)
{
it = list1.erase(it);
--test_counter;
}
else
{
++it;
}
}
for (plf::list<int>::iterator it = --list2.end(); it != list2.begin();)
{
if ((rand() & 7) == 0)
{
list2.insert(it, 13);
++test_counter;
}
if ((rand() & 7) == 0)
{
it = list2.erase(it);
--test_counter;
}
--it;
}
list2.splice(++list2.begin(), list1);
test_counter -= static_cast<int>(list2.remove(1));
unsigned int size_counter = 0;
for (plf::list<int>::iterator it = list2.begin(); it != list2.end(); ++it)
{
++size_counter;
}
if (size_counter != list2.size())
{
std::cout << "Failing at counter == " << counter << std::endl;
std::cin.get();
abort();
}
}
failpass("Erase and insert randomly + splicing test", test_counter == static_cast<int>(list2.size()));
}
#endif
#if defined(PLF_TEST_MOVE_SEMANTICS_SUPPORT) && defined(PLF_TEST_VARIADICS_SUPPORT)
{
title2("Emplace, move and Reverse iterate tests");
plf::list<small_struct> s_list1;
for (int counter = 0; counter != 254; ++counter)
{
s_list1.emplace_back(counter);
}
small_struct temp = s_list1.emplace_back(254);
failpass("Emplace_back return value test", temp.number == 254);
test_counter = 0;
for (plf::list<small_struct>::iterator it = s_list1.begin(); it != s_list1.end(); ++it)
{
if (test_counter++ != it->number)
{
passed = false;
break;
}
}
failpass("Emplace_back test", passed);
for (plf::list<small_struct>::reverse_iterator rit = s_list1.rbegin(); rit != s_list1.rend(); ++rit)
{
if (--test_counter != rit->number)
{
passed = false;
break;
}
}
failpass("Reverse iteration test", passed);
for (int counter = -1; counter != -255; --counter)
{
s_list1.emplace_front(counter);
}
temp = s_list1.emplace_front(-255);
failpass("Emplace_front return value test", temp.number == -255);
test_counter = -255;
for (plf::list<small_struct>::iterator it = s_list1.begin(); it != s_list1.end(); ++it)
{
if (test_counter++ != it->number)
{
passed = false;
break;
}
}
failpass("Emplace_front test", passed);
test_counter = 255;
for (plf::list<small_struct>::reverse_iterator rit = s_list1.rbegin(); rit != s_list1.rend(); ++rit)
{
if (--test_counter != rit->number)
{
passed = false;
break;
}
}
failpass("Reverse iteration test 2", passed);
title2("Move tests");
plf::list<small_struct> s_list2(std::move(s_list1));
test_counter = 255;
for (plf::list<small_struct>::reverse_iterator rit = s_list2.rbegin(); rit != s_list2.rend(); ++rit)
{
if (--test_counter != rit->number)
{
passed = false;
break;
}
}
failpass("Move constructor", passed && s_list1.empty());
s_list1.emplace_back(3); // Reuse the moved list will cause segmentation fault
failpass("Emplace post-moved-list test", s_list1.size() == 1);
s_list1 = std::move(s_list2);
test_counter = 255;
for (plf::list<small_struct>::reverse_iterator rit = s_list1.rbegin(); rit != s_list1.rend(); ++rit)
{
if (--test_counter != rit->number)
{
passed = false;
break;
}
}
failpass("Move assignment", passed && s_list2.empty());
title2("Copy tests");
s_list2 = s_list1;