18 #include <initializer_list> 25 #include <unordered_set> 30 #include "gmock/gmock.h" 31 #include "gtest/gtest.h" 39 using ::testing::Each;
40 using ::testing::ElementsAre;
42 using ::testing::IsNull;
44 using ::testing::Pointee;
45 using ::testing::Truly;
46 using ::testing::UnorderedElementsAre;
51 class NonMutatingTest :
public testing::Test {
53 std::unordered_set<int> container_ = {1, 2, 3};
54 std::list<int> sequence_ = {1, 2, 3};
55 std::vector<int> vector_ = {1, 2, 3};
56 int array_[3] = {1, 2, 3};
59 struct AccumulateCalls {
60 void operator()(
int value) {
61 calls.push_back(value);
63 std::vector<int> calls;
66 bool Predicate(
int value) {
return value < 3; }
67 bool BinPredicate(
int v1,
int v2) {
return v1 < v2; }
68 bool Equals(
int v1,
int v2) {
return v1 == v2; }
69 bool IsOdd(
int x) {
return x % 2 != 0; }
72 TEST_F(NonMutatingTest, Distance) {
82 TEST_F(NonMutatingTest, Distance_OverloadedBeginEnd) {
85 std::initializer_list<int>
a = {1, 2, 3};
86 std::valarray<int>
b = {1, 2, 3};
94 TEST_F(NonMutatingTest, ForEach) {
97 std::sort(c.calls.begin(), c.calls.end());
98 EXPECT_EQ(vector_, c.calls);
103 std::sort(c2.calls.begin(), c2.calls.end());
104 EXPECT_EQ(vector_, c2.calls);
107 TEST_F(NonMutatingTest, FindReturnsCorrectType) {
115 TEST_F(NonMutatingTest, FindIfNot) {
119 TEST_F(NonMutatingTest, FindEnd) {
124 TEST_F(NonMutatingTest, FindEndWithPredicate) {
129 TEST_F(NonMutatingTest, FindFirstOf) {
134 TEST_F(NonMutatingTest, FindFirstOfWithPredicate) {
141 TEST_F(NonMutatingTest, AdjacentFindWithPredicate) {
147 TEST_F(NonMutatingTest, CountIf) {
149 const std::unordered_set<int>& const_container = container_;
153 TEST_F(NonMutatingTest, Mismatch) {
158 TEST_F(NonMutatingTest, MismatchWithPredicate) {
163 TEST_F(NonMutatingTest, Equal) {
168 std::vector<int> vector_plus = {1, 2, 3};
169 vector_plus.push_back(4);
174 TEST_F(NonMutatingTest, EqualWithPredicate) {
179 std::vector<int> vector_plus = {1, 2, 3};
180 vector_plus.push_back(4);
185 TEST_F(NonMutatingTest, IsPermutation) {
186 auto vector_permut_ = vector_;
187 std::next_permutation(vector_permut_.begin(), vector_permut_.end());
192 std::vector<int> vector_plus = {1, 2, 3};
193 vector_plus.push_back(4);
198 TEST_F(NonMutatingTest, IsPermutationWithPredicate) {
199 auto vector_permut_ = vector_;
200 std::next_permutation(vector_permut_.begin(), vector_permut_.end());
205 std::vector<int> vector_plus = {1, 2, 3};
206 vector_plus.push_back(4);
211 TEST_F(NonMutatingTest, Search) {
217 TEST_F(NonMutatingTest, SearchWithPredicate) {
224 TEST_F(NonMutatingTest, SearchNWithPredicate) {
228 TEST_F(NonMutatingTest, LowerBound) {
230 ASSERT_TRUE(i != sequence_.end());
231 EXPECT_EQ(2, std::distance(sequence_.begin(),
i));
235 TEST_F(NonMutatingTest, LowerBoundWithPredicate) {
236 std::vector<int>
v(vector_);
237 std::sort(
v.begin(),
v.end(), std::greater<int>());
239 EXPECT_TRUE(i ==
v.begin());
243 TEST_F(NonMutatingTest, UpperBound) {
245 ASSERT_TRUE(i != sequence_.end());
246 EXPECT_EQ(1, std::distance(sequence_.begin(),
i));
250 TEST_F(NonMutatingTest, UpperBoundWithPredicate) {
251 std::vector<int>
v(vector_);
252 std::sort(
v.begin(),
v.end(), std::greater<int>());
254 EXPECT_EQ(3, i -
v.begin());
255 EXPECT_TRUE(i ==
v.end());
258 TEST_F(NonMutatingTest, EqualRange) {
259 std::pair<std::list<int>::iterator, std::list<int>::iterator> p =
261 EXPECT_EQ(1, std::distance(sequence_.begin(), p.first));
262 EXPECT_EQ(2, std::distance(sequence_.begin(), p.second));
265 TEST_F(NonMutatingTest, EqualRangeArray) {
267 EXPECT_EQ(1, std::distance(
std::begin(array_), p.first));
268 EXPECT_EQ(2, std::distance(
std::begin(array_), p.second));
271 TEST_F(NonMutatingTest, EqualRangeWithPredicate) {
272 std::vector<int>
v(vector_);
273 std::sort(
v.begin(),
v.end(), std::greater<int>());
274 std::pair<std::vector<int>::iterator, std::vector<int>::iterator> p =
276 EXPECT_EQ(1, std::distance(
v.begin(), p.first));
277 EXPECT_EQ(2, std::distance(
v.begin(), p.second));
280 TEST_F(NonMutatingTest, BinarySearch) {
285 TEST_F(NonMutatingTest, BinarySearchWithPredicate) {
286 std::vector<int>
v(vector_);
287 std::sort(
v.begin(),
v.end(), std::greater<int>());
293 TEST_F(NonMutatingTest, MinElement) {
295 ASSERT_TRUE(i != sequence_.end());
299 TEST_F(NonMutatingTest, MinElementWithPredicate) {
300 std::list<int>::iterator i =
302 ASSERT_TRUE(i != sequence_.end());
306 TEST_F(NonMutatingTest, MaxElement) {
308 ASSERT_TRUE(i != sequence_.end());
312 TEST_F(NonMutatingTest, MaxElementWithPredicate) {
313 std::list<int>::iterator i =
315 ASSERT_TRUE(i != sequence_.end());
319 TEST_F(NonMutatingTest, LexicographicalCompare) {
331 TEST_F(NonMutatingTest, LexicographicalCopmareWithPredicate) {
333 std::greater<int>()));
343 std::vector<int>(v), std::list<int>(sequence_), std::greater<int>()));
346 TEST_F(NonMutatingTest, Includes) {
347 std::set<int> s(vector_.begin(), vector_.end());
352 TEST_F(NonMutatingTest, IncludesWithPredicate) {
353 std::vector<int> v = {3, 2, 1};
354 std::set<int, std::greater<int>> s(v.begin(), v.end());
359 class NumericMutatingTest :
public testing::Test {
361 std::list<int> list_ = {1, 2, 3};
362 std::vector<int> output_;
365 TEST_F(NumericMutatingTest, Iota) {
367 std::list<int> expected{5, 6, 7};
368 EXPECT_EQ(list_, expected);
371 TEST_F(NonMutatingTest, Accumulate) {
375 TEST_F(NonMutatingTest, AccumulateWithBinaryOp) {
380 TEST_F(NonMutatingTest, AccumulateLvalueInit) {
385 TEST_F(NonMutatingTest, AccumulateWithBinaryOpLvalueInit) {
391 TEST_F(NonMutatingTest, InnerProduct) {
393 1000 + 1 * 1 + 2 * 2 + 3 * 3);
396 TEST_F(NonMutatingTest, InnerProductWithBinaryOps) {
398 std::multiplies<int>(), std::plus<int>()),
399 10 * (1 + 1) * (2 + 2) * (3 + 3));
402 TEST_F(NonMutatingTest, InnerProductLvalueInit) {
405 1000 + 1 * 1 + 2 * 2 + 3 * 3);
408 TEST_F(NonMutatingTest, InnerProductWithBinaryOpsLvalueInit) {
411 std::multiplies<int>(), std::plus<int>()),
412 10 * (1 + 1) * (2 + 2) * (3 + 3));
415 TEST_F(NumericMutatingTest, AdjacentDifference) {
418 std::vector<int> expected{1, 2 - 1, 3 - 2, 1000};
419 EXPECT_EQ(output_, expected);
422 TEST_F(NumericMutatingTest, AdjacentDifferenceWithBinaryOp) {
424 std::multiplies<int>());
426 std::vector<int> expected{1, 2 * 1, 3 * 2, 1000};
427 EXPECT_EQ(output_, expected);
430 TEST_F(NumericMutatingTest, PartialSum) {
433 std::vector<int> expected{1, 1 + 2, 1 + 2 + 3, 1000};
434 EXPECT_EQ(output_, expected);
437 TEST_F(NumericMutatingTest, PartialSumWithBinaryOp) {
439 std::multiplies<int>());
441 std::vector<int> expected{1, 1 * 2, 1 * 2 * 3, 1000};
442 EXPECT_EQ(output_, expected);
445 TEST_F(NonMutatingTest, LinearSearch) {
451 const std::vector<int>& v = vector_;
456 TEST_F(NonMutatingTest, AnyOf) {
457 const std::vector<int>& v = vector_;
462 TEST_F(NonMutatingTest, NoneOf) {
463 const std::vector<int>& v = vector_;
468 TEST_F(NonMutatingTest, MinMaxElementLess) {
469 std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
471 EXPECT_TRUE(p.first == vector_.begin());
472 EXPECT_TRUE(p.second == vector_.begin() + 2);
475 TEST_F(NonMutatingTest, MinMaxElementGreater) {
476 std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
478 EXPECT_TRUE(p.first == vector_.begin() + 2);
479 EXPECT_TRUE(p.second == vector_.begin());
482 TEST_F(NonMutatingTest, MinMaxElementNoPredicate) {
483 std::pair<std::vector<int>::const_iterator, std::vector<int>::const_iterator>
485 EXPECT_TRUE(p.first == vector_.begin());
486 EXPECT_TRUE(p.second == vector_.begin() + 2);
489 class SortingTest :
public testing::Test {
491 std::list<int> sorted_ = {1, 2, 3, 4};
492 std::list<int> unsorted_ = {2, 4, 1, 3};
493 std::list<int> reversed_ = {4, 3, 2, 1};
496 TEST_F(SortingTest, IsSorted) {
502 TEST_F(SortingTest, IsSortedWithPredicate) {
508 TEST_F(SortingTest, IsSortedUntil) {
513 TEST_F(SortingTest, NthElement) {
514 std::vector<int> unsorted = {2, 4, 1, 3};
516 EXPECT_THAT(unsorted,
517 ElementsAre(Lt(3), Lt(3), 3, Gt(3)));
519 EXPECT_THAT(unsorted,
520 ElementsAre(Gt(2), Gt(2), 2, Lt(2)));
523 TEST(MutatingTest, IsPartitioned) {
532 TEST(MutatingTest, Partition) {
533 std::vector<int> actual = {1, 2, 3, 4, 5};
535 EXPECT_THAT(actual, Truly([](
const std::vector<int>& c) {
540 TEST(MutatingTest, StablePartition) {
541 std::vector<int> actual = {1, 2, 3, 4, 5};
543 EXPECT_THAT(actual, ElementsAre(1, 3, 5, 2, 4));
546 TEST(MutatingTest, PartitionCopy) {
547 const std::vector<int> initial = {1, 2, 3, 4, 5};
548 std::vector<int> odds, evens;
550 back_inserter(evens), IsOdd);
553 EXPECT_THAT(odds, ElementsAre(1, 3, 5, 7));
554 EXPECT_THAT(evens, ElementsAre(2, 4, 6));
557 TEST(MutatingTest, PartitionPoint) {
558 const std::vector<int> initial = {1, 3, 5, 2, 4};
560 EXPECT_EQ(2, *middle);
563 TEST(MutatingTest, CopyMiddle) {
564 const std::vector<int> initial = {4, -1, -2, -3, 5};
565 const std::list<int> input = {1, 2, 3};
566 const std::vector<int> expected = {4, 1, 2, 3, 5};
568 std::list<int> test_list(initial.begin(), initial.end());
570 EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
572 std::vector<int> test_vector = initial;
574 EXPECT_EQ(expected, test_vector);
577 TEST(MutatingTest, CopyFrontInserter) {
578 const std::list<int> initial = {4, 5};
579 const std::list<int> input = {1, 2, 3};
580 const std::list<int> expected = {3, 2, 1, 4, 5};
582 std::list<int> test_list = initial;
584 EXPECT_EQ(expected, test_list);
587 TEST(MutatingTest, CopyBackInserter) {
588 const std::vector<int> initial = {4, 5};
589 const std::list<int> input = {1, 2, 3};
590 const std::vector<int> expected = {4, 5, 1, 2, 3};
592 std::list<int> test_list(initial.begin(), initial.end());
594 EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
596 std::vector<int> test_vector = initial;
598 EXPECT_EQ(expected, test_vector);
601 TEST(MutatingTest, CopyN) {
602 const std::vector<int> initial = {1, 2, 3, 4, 5};
603 const std::vector<int> expected = {1, 2};
604 std::vector<int> actual;
606 EXPECT_EQ(expected, actual);
609 TEST(MutatingTest, CopyIf) {
610 const std::list<int> input = {1, 2, 3};
611 std::vector<int> output;
613 [](
int i) {
return i != 2; });
614 EXPECT_THAT(output, ElementsAre(1, 3));
617 TEST(MutatingTest, CopyBackward) {
618 std::vector<int> actual = {1, 2, 3, 4, 5};
619 std::vector<int> expected = {1, 2, 1, 2, 3};
621 EXPECT_EQ(expected, actual);
624 TEST(MutatingTest, Move) {
625 std::vector<std::unique_ptr<int>> src;
626 src.emplace_back(absl::make_unique<int>(1));
627 src.emplace_back(absl::make_unique<int>(2));
628 src.emplace_back(absl::make_unique<int>(3));
629 src.emplace_back(absl::make_unique<int>(4));
630 src.emplace_back(absl::make_unique<int>(5));
632 std::vector<std::unique_ptr<int>> dest = {};
634 EXPECT_THAT(src, Each(IsNull()));
635 EXPECT_THAT(dest, ElementsAre(Pointee(1), Pointee(2), Pointee(3), Pointee(4),
639 TEST(MutatingTest, MoveWithRvalue) {
640 auto MakeRValueSrc = [] {
641 std::vector<std::unique_ptr<int>> src;
642 src.emplace_back(absl::make_unique<int>(1));
643 src.emplace_back(absl::make_unique<int>(2));
644 src.emplace_back(absl::make_unique<int>(3));
648 std::vector<std::unique_ptr<int>> dest = MakeRValueSrc();
649 absl::c_move(MakeRValueSrc(), std::back_inserter(dest));
650 EXPECT_THAT(dest, ElementsAre(Pointee(1), Pointee(2), Pointee(3), Pointee(1),
651 Pointee(2), Pointee(3)));
654 TEST(MutatingTest, SwapRanges) {
655 std::vector<int> odds = {2, 4, 6};
656 std::vector<int> evens = {1, 3, 5};
658 EXPECT_THAT(odds, ElementsAre(1, 3, 5));
659 EXPECT_THAT(evens, ElementsAre(2, 4, 6));
662 TEST_F(NonMutatingTest, Transform) {
663 std::vector<int> x{0, 2, 4}, y, z;
665 EXPECT_EQ(std::vector<int>({0, -2, -4}), y);
667 EXPECT_EQ(std::vector<int>({0, -2, -4, 7}), y);
671 EXPECT_EQ(std::vector<int>({1, 5, 4}), z);
673 EXPECT_EQ(std::vector<int>({1, 5, 4, 7}), z);
676 TEST(MutatingTest, Replace) {
677 const std::vector<int> initial = {1, 2, 3, 1, 4, 5};
678 const std::vector<int> expected = {4, 2, 3, 4, 4, 5};
680 std::vector<int> test_vector = initial;
682 EXPECT_EQ(expected, test_vector);
684 std::list<int> test_list(initial.begin(), initial.end());
686 EXPECT_EQ(std::list<int>(expected.begin(), expected.end()), test_list);
689 TEST(MutatingTest, ReplaceIf) {
690 std::vector<int> actual = {1, 2, 3, 4, 5};
691 const std::vector<int> expected = {0, 2, 0, 4, 0};
694 EXPECT_EQ(expected, actual);
697 TEST(MutatingTest, ReplaceCopy) {
698 const std::vector<int> initial = {1, 2, 3, 1, 4, 5};
699 const std::vector<int> expected = {4, 2, 3, 4, 4, 5};
701 std::vector<int> actual;
703 EXPECT_EQ(expected, actual);
707 std::vector<int> test_vector = {2, 3, 1, 4};
709 EXPECT_THAT(test_vector, ElementsAre(1, 2, 3, 4));
712 TEST(MutatingTest, SortWithPredicate) {
713 std::vector<int> test_vector = {2, 3, 1, 4};
715 EXPECT_THAT(test_vector, ElementsAre(4, 3, 2, 1));
723 friend bool operator<(
const Element& e1,
const Element& e2) {
724 return e1.key < e2.key;
727 friend std::ostream&
operator<<(std::ostream&
o,
const Element& e) {
728 return o <<
"{" << e.key <<
", " << e.value <<
"}";
732 MATCHER_P2(IsElement, key,
value,
"") {
736 TEST(MutatingTest, StableSort) {
737 std::vector<Element> test_vector = {{1, 1}, {2, 1}, {2, 0}, {1, 0}, {2, 2}};
741 ElementsAre(IsElement(1, 1), IsElement(1, 0), IsElement(2, 1),
742 IsElement(2, 0), IsElement(2, 2)));
745 TEST(MutatingTest, StableSortWithPredicate) {
746 std::vector<Element> test_vector = {{1, 1}, {2, 1}, {2, 0}, {1, 0}, {2, 2}};
752 ElementsAre(IsElement(2, 1), IsElement(2, 0), IsElement(2, 2),
753 IsElement(1, 1), IsElement(1, 0)));
756 TEST(MutatingTest, ReplaceCopyIf) {
757 const std::vector<int> initial = {1, 2, 3, 4, 5};
758 const std::vector<int> expected = {0, 2, 0, 4, 0};
760 std::vector<int> actual;
762 EXPECT_EQ(expected, actual);
765 TEST(MutatingTest, Fill) {
766 std::vector<int> actual(5);
768 EXPECT_THAT(actual, ElementsAre(1, 1, 1, 1, 1));
771 TEST(MutatingTest, FillN) {
772 std::vector<int> actual(5, 0);
774 EXPECT_THAT(actual, ElementsAre(1, 1, 0, 0, 0));
777 TEST(MutatingTest, Generate) {
778 std::vector<int> actual(5);
781 EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
784 TEST(MutatingTest, GenerateN) {
785 std::vector<int> actual(5, 0);
788 EXPECT_THAT(actual, ElementsAre(1, 2, 3, 0, 0));
791 TEST(MutatingTest, RemoveCopy) {
792 std::vector<int> actual;
794 EXPECT_THAT(actual, ElementsAre(1, 3));
797 TEST(MutatingTest, RemoveCopyIf) {
798 std::vector<int> actual;
801 EXPECT_THAT(actual, ElementsAre(2));
804 TEST(MutatingTest, UniqueCopy) {
805 std::vector<int> actual;
807 back_inserter(actual));
808 EXPECT_THAT(actual, ElementsAre(1, 2, 3, 2));
811 TEST(MutatingTest, UniqueCopyWithPredicate) {
812 std::vector<int> actual;
814 back_inserter(actual),
815 [](
int x,
int y) {
return (x < 0) == (y < 0); });
816 EXPECT_THAT(actual, ElementsAre(1, -1, 1));
819 TEST(MutatingTest, Reverse) {
820 std::vector<int> test_vector = {1, 2, 3, 4};
822 EXPECT_THAT(test_vector, ElementsAre(4, 3, 2, 1));
824 std::list<int> test_list = {1, 2, 3, 4};
826 EXPECT_THAT(test_list, ElementsAre(4, 3, 2, 1));
829 TEST(MutatingTest, ReverseCopy) {
830 std::vector<int> actual;
832 EXPECT_THAT(actual, ElementsAre(4, 3, 2, 1));
836 std::vector<int> actual = {1, 2, 3, 4};
838 EXPECT_THAT(actual, testing::ElementsAreArray({3, 4, 1, 2}));
842 TEST(MutatingTest, RotateCopy) {
843 std::vector<int> initial = {1, 2, 3, 4};
844 std::vector<int> actual;
848 EXPECT_THAT(actual, ElementsAre(3, 4, 1, 2, 5));
851 TEST(MutatingTest, Shuffle) {
852 std::vector<int> actual = {1, 2, 3, 4, 5};
854 EXPECT_THAT(actual, UnorderedElementsAre(1, 2, 3, 4, 5));
857 TEST(MutatingTest, PartialSort) {
858 std::vector<int> sequence{5, 3, 42, 0};
860 EXPECT_THAT(
absl::MakeSpan(sequence.data(), 2), ElementsAre(0, 3));
862 EXPECT_THAT(
absl::MakeSpan(sequence.data(), 2), ElementsAre(42, 5));
865 TEST(MutatingTest, PartialSortCopy) {
866 const std::vector<int> initial = {5, 3, 42, 0};
867 std::vector<int> actual(2);
869 EXPECT_THAT(actual, ElementsAre(0, 3));
871 EXPECT_THAT(actual, ElementsAre(42, 5));
874 TEST(MutatingTest, Merge) {
875 std::vector<int> actual;
876 absl::c_merge(std::vector<int>{1, 3, 5}, std::vector<int>{2, 4},
877 back_inserter(actual));
878 EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
881 TEST(MutatingTest, MergeWithComparator) {
882 std::vector<int> actual;
883 absl::c_merge(std::vector<int>{5, 3, 1}, std::vector<int>{4, 2},
884 back_inserter(actual), std::greater<int>());
885 EXPECT_THAT(actual, ElementsAre(5, 4, 3, 2, 1));
888 TEST(MutatingTest, InplaceMerge) {
889 std::vector<int> actual = {1, 3, 5, 2, 4};
891 EXPECT_THAT(actual, ElementsAre(1, 2, 3, 4, 5));
894 TEST(MutatingTest, InplaceMergeWithComparator) {
895 std::vector<int> actual = {5, 3, 1, 4, 2};
897 EXPECT_THAT(actual, ElementsAre(5, 4, 3, 2, 1));
900 class SetOperationsTest :
public testing::Test {
902 std::vector<int> a_ = {1, 2, 3};
903 std::vector<int> b_ = {1, 3, 5};
905 std::vector<int> a_reversed_ = {3, 2, 1};
906 std::vector<int> b_reversed_ = {5, 3, 1};
909 TEST_F(SetOperationsTest, SetUnion) {
910 std::vector<int> actual;
912 EXPECT_THAT(actual, ElementsAre(1, 2, 3, 5));
915 TEST_F(SetOperationsTest, SetUnionWithComparator) {
916 std::vector<int> actual;
918 std::greater<int>());
919 EXPECT_THAT(actual, ElementsAre(5, 3, 2, 1));
922 TEST_F(SetOperationsTest, SetIntersection) {
923 std::vector<int> actual;
925 EXPECT_THAT(actual, ElementsAre(1, 3));
928 TEST_F(SetOperationsTest, SetIntersectionWithComparator) {
929 std::vector<int> actual;
931 std::greater<int>());
932 EXPECT_THAT(actual, ElementsAre(3, 1));
935 TEST_F(SetOperationsTest, SetDifference) {
936 std::vector<int> actual;
938 EXPECT_THAT(actual, ElementsAre(2));
941 TEST_F(SetOperationsTest, SetDifferenceWithComparator) {
942 std::vector<int> actual;
944 std::greater<int>());
945 EXPECT_THAT(actual, ElementsAre(2));
948 TEST_F(SetOperationsTest, SetSymmetricDifference) {
949 std::vector<int> actual;
951 EXPECT_THAT(actual, ElementsAre(2, 5));
954 TEST_F(SetOperationsTest, SetSymmetricDifferenceWithComparator) {
955 std::vector<int> actual;
957 back_inserter(actual), std::greater<int>());
958 EXPECT_THAT(actual, ElementsAre(5, 2));
961 TEST(HeapOperationsTest, WithoutComparator) {
962 std::vector<int> heap = {1, 2, 3};
969 EXPECT_EQ(4, heap[0]);
971 EXPECT_EQ(4, heap[3]);
974 EXPECT_THAT(heap, ElementsAre(1, 2, 3, 4));
978 TEST(HeapOperationsTest, WithComparator) {
979 using greater = std::greater<int>;
980 std::vector<int> heap = {3, 2, 1};
987 EXPECT_EQ(0, heap[0]);
989 EXPECT_EQ(0, heap[3]);
992 EXPECT_THAT(heap, ElementsAre(3, 2, 1, 0));
996 TEST(MutatingTest, PermutationOperations) {
997 std::vector<int> initial = {1, 2, 3, 4};
998 std::vector<int> permuted = initial;
1004 std::vector<int> permuted2 = initial;
1006 EXPECT_EQ(permuted, permuted2);
1009 EXPECT_EQ(initial, permuted);
void c_iota(Sequence &sequence, T &&value)
BidirectionalIterator c_copy_backward(const C &src, BidirectionalIterator dest)
bool c_is_partitioned(const C &c, Pred &&pred)
container_algorithm_internal::ContainerIter< C1 > c_find_first_of(C1 &container, C2 &options)
static void Sort(const Vec< Node *> &, Vec< int32_t > *delta)
void c_replace(Sequence &sequence, const T &old_value, const T &new_value)
OutputIterator c_replace_copy_if(const C &c, OutputIterator result, Pred &&pred, T &&new_value)
void c_pop_heap(RandomAccessContainer &sequence)
void c_shuffle(RandomAccessContainer &c, UniformRandomBitGenerator &&gen)
OutputIterator c_merge(const C1 &c1, const C2 &c2, OutputIterator result)
container_algorithm_internal::ContainerDifferenceType< const C > c_count(const C &c, T &&value)
container_algorithm_internal::ContainerIter< RandomAccessContainer > c_partial_sort_copy(const C &sequence, RandomAccessContainer &result)
bool operator<(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
container_algorithm_internal::ContainerIter< Sequence > c_max_element(Sequence &sequence)
OutputIterator c_copy_n(const C &input, Size n, OutputIterator output)
container_algorithm_internal::ContainerIterPairType< C, C > c_minmax_element(C &c)
bool c_any_of(const C &c, Pred &&pred)
void c_reverse(Sequence &sequence)
bool c_is_permutation(const C1 &c1, const C2 &c2)
container_algorithm_internal::ContainerIter< C2 > c_swap_ranges(C1 &c1, C2 &c2)
Iterator c_rotate(C &sequence, Iterator middle)
void c_nth_element(RandomAccessContainer &sequence, container_algorithm_internal::ContainerIter< RandomAccessContainer > nth)
std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
bool c_lexicographical_compare(Sequence1 &&sequence1, Sequence2 &&sequence2)
container_algorithm_internal::ContainerIter< C > c_partition_point(C &c, Pred &&pred)
container_algorithm_internal::ContainerIter< Sequence1 > c_search(Sequence1 &sequence, Sequence2 &subsequence)
container_algorithm_internal::ContainerIter< C > c_find(C &c, T &&value)
container_algorithm_internal::ContainerIter< C > c_stable_partition(C &c, Pred &&pred)
container_algorithm_internal::ContainerDifferenceType< const C > c_count_if(const C &c, Pred &&pred)
void c_fill_n(C &c, Size n, T &&value)
container_algorithm_internal::ContainerIter< RandomAccessContainer > c_is_heap_until(RandomAccessContainer &sequence)
void c_sort_heap(RandomAccessContainer &sequence)
decay_t< Function > c_for_each(C &&c, Function &&f)
OutputIterator c_remove_copy_if(const C &c, OutputIterator result, Pred &&pred)
container_algorithm_internal::ContainerIter< C > c_generate_n(C &c, Size n, Generator &&gen)
container_algorithm_internal::ContainerDifferenceType< const C > c_distance(const C &c)
OutputIterator c_remove_copy(const C &c, OutputIterator result, T &&value)
decay_t< T > c_inner_product(const Sequence1 &factors1, const Sequence2 &factors2, T &&sum)
bool c_equal(const C1 &c1, const C2 &c2)
container_algorithm_internal::ContainerIter< Sequence > c_adjacent_find(Sequence &sequence)
void c_make_heap(RandomAccessContainer &sequence)
bool c_prev_permutation(C &c)
constexpr To implicit_cast(typename absl::internal::identity_t< To > to)
OutputIterator c_rotate_copy(const C &sequence, container_algorithm_internal::ContainerIter< const C > middle, OutputIterator result)
OutputIterator c_reverse_copy(const C &sequence, OutputIterator result)
std::pair< OutputIterator1, OutputIterator2 > c_partition_copy(const C &c, OutputIterator1 out_true, OutputIterator2 out_false, Pred &&pred)
container_algorithm_internal::ContainerIterPairType< C1, C2 > c_mismatch(C1 &c1, C2 &c2)
OutputIterator c_copy(const InputSequence &input, OutputIterator output)
OutputIterator c_set_symmetric_difference(const C1 &c1, const C2 &c2, OutputIterator output)
OutputIterator c_copy_if(const InputSequence &input, OutputIterator output, Pred &&pred)
OutputIterator c_unique_copy(const C &c, OutputIterator result)
TEST_F(GraphCyclesTest, NoCycle)
static uint64_t Rotate(uint64_t val, int shift)
bool c_includes(const C1 &c1, const C2 &c2)
bool c_binary_search(Sequence &&sequence, T &&value)
void c_inplace_merge(C &c, container_algorithm_internal::ContainerIter< C > middle)
void c_fill(C &c, T &&value)
container_algorithm_internal::ContainerIterPairType< Sequence, Sequence > c_equal_range(Sequence &sequence, T &&value)
OutputIterator c_move(C &&src, OutputIterator dest)
bool c_linear_search(const C &c, EqualityComparable &&value)
bool c_all_of(const C &c, Pred &&pred)
container_algorithm_internal::ContainerIter< C > c_find_if(C &c, Pred &&pred)
OutputIt c_adjacent_difference(const InputSequence &input, OutputIt output_first)
container_algorithm_internal::ContainerIter< Sequence > c_search_n(Sequence &sequence, Size count, T &&value)
bool c_next_permutation(C &c)
container_algorithm_internal::ContainerIter< Sequence > c_min_element(Sequence &sequence)
OutputIterator c_replace_copy(const C &c, OutputIterator result, T &&old_value, T &&new_value)
bool c_is_heap(const RandomAccessContainer &sequence)
void c_push_heap(RandomAccessContainer &sequence)
void c_generate(C &c, Generator &&gen)
#define ABSL_ARRAYSIZE(array)
container_algorithm_internal::ContainerIter< Sequence > c_upper_bound(Sequence &sequence, T &&value)
OutputIterator c_set_intersection(const C1 &c1, const C2 &c2, OutputIterator output)
OutputIt c_partial_sum(const InputSequence &input, OutputIt output_first)
OutputIterator c_transform(const InputSequence &input, OutputIterator output, UnaryOp &&unary_op)
container_algorithm_internal::ContainerIter< Sequence1 > c_find_end(Sequence1 &sequence, Sequence2 &subsequence)
decay_t< T > c_accumulate(const Sequence &sequence, T &&init)
void c_partial_sort(RandomAccessContainer &sequence, container_algorithm_internal::ContainerIter< RandomAccessContainer > middle)
OutputIterator c_set_union(const C1 &c1, const C2 &c2, OutputIterator output)
TEST(Symbolize, Unimplemented)
bool c_is_sorted(const C &c)
void c_replace_if(C &c, Pred &&pred, T &&new_value)
constexpr Span< T > MakeSpan(T *ptr, size_t size) noexcept
container_algorithm_internal::ContainerIter< C > c_partition(C &c, Pred &&pred)
container_algorithm_internal::ContainerIter< C > c_find_if_not(C &c, Pred &&pred)
container_algorithm_internal::ContainerIter< Sequence > c_lower_bound(Sequence &sequence, T &&value)
OutputIterator c_set_difference(const C1 &c1, const C2 &c2, OutputIterator output)
bool c_none_of(const C &c, Pred &&pred)
container_algorithm_internal::ContainerIter< C > c_is_sorted_until(C &c)