15 #include "absl/algorithm/algorithm.h"
21 #include "gmock/gmock.h"
22 #include "gtest/gtest.h"
23 #include "absl/base/config.h"
27 TEST(EqualTest, DefaultComparisonRandomAccess) {
28 std::vector<int> v1{1, 2, 3};
29 std::vector<int> v2 = v1;
30 std::vector<int> v3 = {1, 2};
31 std::vector<int> v4 = {1, 2, 4};
38 TEST(EqualTest, DefaultComparison) {
39 std::list<int> lst1{1, 2, 3};
40 std::list<int> lst2 = lst1;
41 std::list<int> lst3{1, 2};
42 std::list<int> lst4{1, 2, 4};
49 TEST(EqualTest, EmptyRange) {
50 std::vector<int> v1{1, 2, 3};
51 std::vector<int> empty1;
52 std::vector<int> empty2;
55 #if ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(12, 0)
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wnonnull"
60 #if ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(12, 0)
61 #pragma GCC diagnostic pop
65 absl::equal(empty1.begin(), empty1.end(), empty2.begin(), empty2.end()));
68 TEST(EqualTest, MixedIterTypes) {
69 std::vector<int> v1{1, 2, 3};
70 std::list<int> lst1{v1.begin(), v1.end()};
71 std::list<int> lst2{1, 2, 4};
72 std::list<int> lst3{1, 2};
79 TEST(EqualTest, MixedValueTypes) {
80 std::vector<int> v1{1, 2, 3};
81 std::vector<char> v2{1, 2, 3};
82 std::vector<char> v3{1, 2};
83 std::vector<char> v4{1, 2, 4};
90 TEST(EqualTest, WeirdIterators) {
91 std::vector<bool> v1{
true,
false};
92 std::vector<bool> v2 = v1;
93 std::vector<bool> v3{
true};
94 std::vector<bool> v4{
true,
true,
true};
101 TEST(EqualTest, CustomComparison) {
102 int n[] = {1, 2, 3, 4};
103 std::vector<int*> v1{&
n[0], &
n[1], &
n[2]};
104 std::vector<int*> v2 = v1;
105 std::vector<int*> v3{&
n[0], &
n[1], &
n[3]};
106 std::vector<int*> v4{&
n[0], &
n[1]};
108 auto eq = [](
int*
a,
int*
b) {
return *
a == *
b; };
115 TEST(EqualTest, MoveOnlyPredicate) {
116 std::vector<int> v1{1, 2, 3};
117 std::vector<int> v2{4, 5, 6};
123 Eq(
const Eq &) =
delete;
124 Eq &operator=(
const Eq &) =
delete;
125 bool operator()(
const int a,
const int b)
const {
return a ==
b; }
132 struct CountingTrivialPred {
134 bool operator()(
int,
int)
const {
140 TEST(EqualTest, RandomAccessComplexity) {
141 std::vector<int> v1{1, 1, 3};
142 std::vector<int> v2 = v1;
143 std::vector<int> v3{1, 2};
147 absl::equal(v1.begin(), v1.end(), v2.begin(), v2.end(),
148 CountingTrivialPred{&count});
150 }
while (std::next_permutation(v2.begin(), v2.end()));
153 absl::equal(v1.begin(), v1.end(), v3.begin(), v3.end(),
154 CountingTrivialPred{&count});
160 LinearSearchTest() : container_{1, 2, 3} {}
162 static bool Is3(
int n) {
return n == 3; }
163 static bool Is4(
int n) {
return n == 4; }
165 std::vector<int> container_;
173 TEST_F(LinearSearchTest, linear_searchConst) {
174 const std::vector<int> *
const const_container = &container_;
182 std::vector<int>
v{0, 1, 2, 3, 4};
186 std::list<int>
l{0, 1, 2, 3, 4};