2 * Copyright 2016 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <glog/logging.h>
20 #include <gtest/gtest.h>
22 #include <folly/Memory.h>
23 #include <folly/gen/Base.h>
24 #include <folly/gen/ParallelMap.h>
26 using namespace folly;
27 using namespace folly::gen;
29 TEST(Pmap, InfiniteEquivalent) {
34 | map([](int x) { return x * x; })
35 | until([](int x) { return x > 1000 * 1000; })
36 | as<std::vector<int>>();
40 | pmap([](int x) { return x * x; }, 4)
41 | until([](int x) { return x > 1000 * 1000; })
42 | as<std::vector<int>>();
44 EXPECT_EQ(pmapResult, mapResult);
51 | map([](int x) { return x * x; })
52 | as<std::vector<int>>();
56 | pmap([](int x) { return x * x; }, 4)
57 | as<std::vector<int>>();
59 EXPECT_EQ(pmapResult, mapResult);
68 | map([](int x) { return x * x; })
69 | until([](int) { return true; })
70 | as<std::vector<int>>();
74 | pmap([](int x) { return x * x; }, 4)
75 | until([](int) { return true; })
76 | as<std::vector<int>>();
78 EXPECT_EQ(mapResult.size(), 0);
79 EXPECT_EQ(pmapResult, mapResult);
86 | map([](int x) { return x * x; })
87 | as<std::vector<int>>();
91 | pmap([](int x) { return x * x; }, 4)
92 | as<std::vector<int>>();
94 EXPECT_EQ(mapResult.size(), 0);
95 EXPECT_EQ(pmapResult, mapResult);
104 | map([](int x) { return make_unique<int>(x); })
105 | map([](std::unique_ptr<int> x) { return make_unique<int>(*x * *x); })
106 | map([](std::unique_ptr<int> x) { return *x; })
112 | pmap([](int x) { return make_unique<int>(x); })
113 | pmap([](std::unique_ptr<int> x) { return make_unique<int>(*x * *x); })
114 | pmap([](std::unique_ptr<int> x) { return *x; })
118 EXPECT_EQ(pmapResult, mapResult);
125 | map([](int x) { return make_unique<int>(x); })
126 | map([](std::unique_ptr<int> x) { return make_unique<int>(*x * *x); })
127 | map([](std::unique_ptr<int> x) { return *x; })
132 | pmap([](int x) { return make_unique<int>(x); })
133 | pmap([](std::unique_ptr<int> x) { return make_unique<int>(*x * *x); })
134 | pmap([](std::unique_ptr<int> x) { return *x; })
137 EXPECT_EQ(pmapResult, mapResult);
141 int main(int argc, char *argv[]) {
142 testing::InitGoogleTest(&argc, argv);
143 gflags::ParseCommandLineFlags(&argc, &argv, true);
144 return RUN_ALL_TESTS();