@@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(limits__binary_search_native__sorted_contained__expected)
88
88
BOOST_AUTO_TEST_CASE (limits__binary_search_native__reverse_sorted_contained__unlucky)
89
89
{
90
90
const std::string unsorted = " zyxwvutscba" ;
91
- const auto value = ' x' ;
91
+ constexpr auto value = ' x' ;
92
92
BOOST_REQUIRE_EQUAL (binary_search (unsorted, value), -1 );
93
93
}
94
94
@@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(collection__pop__empty__empty_default)
173
173
174
174
BOOST_AUTO_TEST_CASE (collection__pop__single__empty_expected)
175
175
{
176
- const uint8_t expected = 42u ;
176
+ constexpr uint8_t expected = 42u ;
177
177
data_chunk stack{ expected };
178
178
const auto value = pop (stack);
179
179
BOOST_REQUIRE (stack.empty ());
@@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(collection__pop_front__empty__empty_default)
203
203
204
204
BOOST_AUTO_TEST_CASE (collection__pop_front__single__empty_expected)
205
205
{
206
- const uint8_t expected = 42u ;
206
+ constexpr uint8_t expected = 42u ;
207
207
data_queue queue{ expected };
208
208
const auto value = pop_front (queue);
209
209
BOOST_REQUIRE (queue.empty ());
@@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(collection__pop_front__single__empty_expected)
212
212
213
213
BOOST_AUTO_TEST_CASE (collection__pop_front__multiple__popped_expected)
214
214
{
215
- const uint8_t expected_value = 42u ;
215
+ constexpr uint8_t expected_value = 42u ;
216
216
data_queue queue{ expected_value, 0 , 1 , 2 , 3 };
217
217
const data_queue expected_queue{ 0 , 1 , 2 , 3 };
218
218
const auto value = pop_front (queue);
@@ -435,6 +435,98 @@ BOOST_AUTO_TEST_CASE(collection__difference__subtrahend_subset__expected)
435
435
BOOST_REQUIRE_EQUAL (difference (minuend, subtrahend), expected);
436
436
}
437
437
438
+ // part
439
+
440
+ BOOST_AUTO_TEST_CASE (collection__part__vector__true)
441
+ {
442
+ std::vector<int > from = { 1 , 2 , 4 , 7 , 8 , 3 , 1 , 5 , 3 };
443
+ std::vector<int > to{};
444
+ BOOST_REQUIRE (part (from, to, 3 ));
445
+ BOOST_REQUIRE_EQUAL (from, (std::vector<int >{1 , 2 , 4 , 7 , 8 }));
446
+ BOOST_REQUIRE_EQUAL (to, (std::vector<int >{3 , 1 , 5 , 3 }));
447
+ }
448
+
449
+ BOOST_AUTO_TEST_CASE (collection__part__list__true)
450
+ {
451
+ std::list<int > from = { 1 , 2 , 4 , 7 , 8 , 3 , 1 , 5 , 3 };
452
+ std::list<int > to{};
453
+ BOOST_REQUIRE (part (from, to, 3 ));
454
+ BOOST_REQUIRE (from == (std::list<int >{1 , 2 , 4 , 7 , 8 }));
455
+ BOOST_REQUIRE (to == (std::list<int >{3 , 1 , 5 , 3 }));
456
+ }
457
+
458
+ BOOST_AUTO_TEST_CASE (collection__part__deque__true)
459
+ {
460
+ std::deque<int > from = { 1 , 2 , 4 , 7 , 8 , 3 , 1 , 5 , 3 };
461
+ std::deque<int > to{};
462
+ BOOST_REQUIRE (part (from, to, 3 ));
463
+ BOOST_REQUIRE (from == (std::deque<int >{1 , 2 , 4 , 7 , 8 }));
464
+ BOOST_REQUIRE (to == (std::deque<int >{3 , 1 , 5 , 3 }));
465
+ }
466
+
467
+ BOOST_AUTO_TEST_CASE (collection__part__vector_empty__false)
468
+ {
469
+ std::vector<int > from{};
470
+ std::vector<int > to{};
471
+ BOOST_REQUIRE (!part (from, to, 3 ));
472
+ BOOST_REQUIRE_EQUAL (from, (std::vector<int >{}));
473
+ BOOST_REQUIRE_EQUAL (to, (std::vector<int >{}));
474
+ }
475
+
476
+ BOOST_AUTO_TEST_CASE (collection__part__vector_no_equal__false)
477
+ {
478
+ std::vector<int > from = { 1 , 2 , 4 , 5 };
479
+ std::vector<int > to{};
480
+ BOOST_REQUIRE (!part (from, to, 3 ));
481
+ BOOST_REQUIRE_EQUAL (from, (std::vector<int >{1 , 2 , 4 , 5 }));
482
+ BOOST_REQUIRE_EQUAL (to, (std::vector<int >{}));
483
+ }
484
+
485
+ BOOST_AUTO_TEST_CASE (collection__part__list_first_equal__true)
486
+ {
487
+ std::list<int > from = { 3 , 6 , 7 , 8 };
488
+ std::list<int > to{};
489
+ BOOST_REQUIRE (part (from, to, 3 ));
490
+ BOOST_REQUIRE (from == (std::list<int >{}));
491
+ BOOST_REQUIRE (to == (std::list<int >{3 , 6 , 7 , 8 }));
492
+ }
493
+
494
+ BOOST_AUTO_TEST_CASE (collection__part__vector_non_empty_to__true)
495
+ {
496
+ std::vector<int > from = { 1 , 3 , 4 , 5 };
497
+ std::vector<int > to = { 10 , 11 };
498
+ BOOST_REQUIRE (part (from, to, 3 ));
499
+ BOOST_REQUIRE_EQUAL (from, (std::vector<int >{1 }));
500
+ BOOST_REQUIRE_EQUAL (to, (std::vector<int >{10 , 11 , 3 , 4 , 5 }));
501
+ }
502
+
503
+ BOOST_AUTO_TEST_CASE (collection__part__string_list__true)
504
+ {
505
+ string_list from = { " apple" , " date" , " banana" , " cherry" };
506
+ string_list to{};
507
+ BOOST_REQUIRE (part (from, to, std::string (" date" )));
508
+ BOOST_REQUIRE_EQUAL (from, (string_list{ " apple" }));
509
+ BOOST_REQUIRE_EQUAL (to, (string_list{ " date" , " banana" , " cherry" }));
510
+ }
511
+
512
+ BOOST_AUTO_TEST_CASE (collection__part__string_list_first_equal__true)
513
+ {
514
+ string_list from = { " apple" , " banana" , " cherry" , " date" };
515
+ string_list to{};
516
+ BOOST_REQUIRE (part (from, to, std::string (" apple" )));
517
+ BOOST_REQUIRE_EQUAL (from, (string_list{}));
518
+ BOOST_REQUIRE_EQUAL (to, (string_list{ " apple" , " banana" , " cherry" , " date" }));
519
+ }
520
+
521
+ BOOST_AUTO_TEST_CASE (collection__part__string_list_last_equal__true)
522
+ {
523
+ string_list from = { " banana" , " cherry" , " date" , " apple" };
524
+ string_list to{};
525
+ BOOST_REQUIRE (part (from, to, std::string (" apple" )));
526
+ BOOST_REQUIRE_EQUAL (from, (string_list{ " banana" , " cherry" , " date" }));
527
+ BOOST_REQUIRE_EQUAL (to, (string_list{ " apple" }));
528
+ }
529
+
438
530
// reverse
439
531
440
532
BOOST_AUTO_TEST_CASE (collection__reverse_move__empty__empty)
@@ -444,7 +536,7 @@ BOOST_AUTO_TEST_CASE(collection__reverse_move__empty__empty)
444
536
445
537
BOOST_AUTO_TEST_CASE (collection__reverse_move__single__unchanged)
446
538
{
447
- const uint8_t expected = 42 ;
539
+ constexpr uint8_t expected = 42 ;
448
540
BOOST_REQUIRE_EQUAL (reverse (data_chunk{ expected }).front (), expected);
449
541
}
450
542
@@ -472,7 +564,7 @@ BOOST_AUTO_TEST_CASE(collection__sort_move__empty__empty)
472
564
473
565
BOOST_AUTO_TEST_CASE (collection__sort_move__single__unchanged)
474
566
{
475
- const uint8_t expected = 42 ;
567
+ constexpr uint8_t expected = 42 ;
476
568
BOOST_REQUIRE_EQUAL (sort (data_chunk{ expected }).front (), expected);
477
569
}
478
570
0 commit comments