1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "absl/algorithm/algorithm.h"
16
17 #include <algorithm>
18 #include <list>
19 #include <vector>
20
21 #include "gmock/gmock.h"
22 #include "gtest/gtest.h"
23 #include "absl/base/config.h"
24
25 namespace {
26
27 class LinearSearchTest : public testing::Test {
28 protected:
LinearSearchTest()29 LinearSearchTest() : container_{1, 2, 3} {}
30
Is3(int n)31 static bool Is3(int n) { return n == 3; }
Is4(int n)32 static bool Is4(int n) { return n == 4; }
33
34 std::vector<int> container_;
35 };
36
TEST_F(LinearSearchTest,linear_search)37 TEST_F(LinearSearchTest, linear_search) {
38 EXPECT_TRUE(absl::linear_search(container_.begin(), container_.end(), 3));
39 EXPECT_FALSE(absl::linear_search(container_.begin(), container_.end(), 4));
40 }
41
TEST_F(LinearSearchTest,linear_searchConst)42 TEST_F(LinearSearchTest, linear_searchConst) {
43 const std::vector<int> *const const_container = &container_;
44 EXPECT_TRUE(
45 absl::linear_search(const_container->begin(), const_container->end(), 3));
46 EXPECT_FALSE(
47 absl::linear_search(const_container->begin(), const_container->end(), 4));
48 }
49
50 } // namespace
51