Use the GTest portability headers
[folly.git] / folly / test / MergeTest.cpp
1 /*
2  * Copyright 2016 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <folly/Merge.h>
18
19 #include <map>
20 #include <vector>
21
22 #include <folly/portability/GTest.h>
23
24 TEST(MergeTest, NonOverlapping) {
25   std::vector<int> a = {0, 2, 4, 6};
26   std::vector<int> b = {1, 3, 5, 7};
27   std::vector<int> c;
28
29   folly::merge(a.begin(), a.end(),
30                b.begin(), b.end(),
31                std::back_inserter(c));
32   EXPECT_EQ(8, c.size());
33   for (int i = 0; i < 8; ++i) {
34     EXPECT_EQ(i, c[i]);
35   }
36 }
37
38 TEST(MergeTest, OverlappingInSingleInputRange) {
39   std::vector<std::pair<int, int>> a = {{0, 0}, {0, 1}};
40   std::vector<std::pair<int, int>> b = {{2, 2}, {3, 3}};
41   std::map<int, int> c;
42
43   folly::merge(a.begin(), a.end(),
44                b.begin(), b.end(),
45                std::inserter(c, c.begin()));
46   EXPECT_EQ(3, c.size());
47
48   // First value is inserted, second is not
49   EXPECT_EQ(c[0], 0);
50
51   EXPECT_EQ(c[2], 2);
52   EXPECT_EQ(c[3], 3);
53 }
54
55 TEST(MergeTest, OverlappingInDifferentInputRange) {
56   std::vector<std::pair<int, int>> a = {{0, 0}, {1, 1}};
57   std::vector<std::pair<int, int>> b = {{0, 2}, {3, 3}};
58   std::map<int, int> c;
59
60   folly::merge(a.begin(), a.end(),
61                b.begin(), b.end(),
62                std::inserter(c, c.begin()));
63   EXPECT_EQ(3, c.size());
64
65   // Value from a is inserted, value from b is not.
66   EXPECT_EQ(c[0], 0);
67
68   EXPECT_EQ(c[1], 1);
69   EXPECT_EQ(c[3], 3);
70 }