1 #include "helpers.hpp"
2 #include "utils/transform.hpp"
3
4 #include <set>
5 #include <vector>
6
7 #include <gmock/gmock.h>
8
9 using namespace testing;
10
TEST(TestTransform,transformsVector)11 TEST(TestTransform, transformsVector)
12 {
13 std::vector<int> input = {1, 2, 3};
14 std::vector<std::string> output =
15 utils::transform(input, [](int v) { return std::to_string(v); });
16 EXPECT_TRUE(utils::detail::has_member_reserve<decltype(input)>);
17 EXPECT_TRUE(utils::detail::has_member_reserve<decltype(output)>);
18 ASSERT_THAT(output, ElementsAre("1", "2", "3"));
19 }
20
TEST(TestTransform,transformsSet)21 TEST(TestTransform, transformsSet)
22 {
23 std::set<int> input = {1, 2, 3};
24 std::set<std::string> output =
25 utils::transform(input, [](int v) { return std::to_string(v); });
26 EXPECT_FALSE(utils::detail::has_member_reserve<decltype(input)>);
27 EXPECT_FALSE(utils::detail::has_member_reserve<decltype(output)>);
28 ASSERT_THAT(output, ElementsAre("1", "2", "3"));
29 }
30
TEST(TestTransform,transformsArrayToVector)31 TEST(TestTransform, transformsArrayToVector)
32 {
33 std::array<int, 3> input = {1, 2, 3};
34 std::vector<std::string> output = utils::transform<std::vector>(
35 input, [](int v) { return std::to_string(v); });
36 EXPECT_FALSE(utils::detail::has_member_reserve<decltype(input)>);
37 EXPECT_TRUE(utils::detail::has_member_reserve<decltype(output)>);
38 ASSERT_THAT(output, ElementsAre("1", "2", "3"));
39 }
40