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 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 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 31 TEST(TestTransform, transformsArrayToVector) 32 { 33 std::array<int, 3> input = {1, 2, 3}; 34 std::vector<std::string> output = 35 utils::transform<std::vector<std::string>>( 36 input, [](int v) { return std::to_string(v); }); 37 EXPECT_FALSE(utils::detail::has_member_reserve<decltype(input)>); 38 EXPECT_TRUE(utils::detail::has_member_reserve<decltype(output)>); 39 ASSERT_THAT(output, ElementsAre("1", "2", "3")); 40 } 41