Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 1 | #include "helpers.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 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); }); |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 16 | EXPECT_TRUE(utils::detail::has_member_reserve<decltype(input)>); |
| 17 | EXPECT_TRUE(utils::detail::has_member_reserve<decltype(output)>); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 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); }); |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 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}; |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 34 | std::vector<std::string> output = utils::transform<std::vector>( |
| 35 | input, [](int v) { return std::to_string(v); }); |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 36 | EXPECT_FALSE(utils::detail::has_member_reserve<decltype(input)>); |
| 37 | EXPECT_TRUE(utils::detail::has_member_reserve<decltype(output)>); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 38 | ASSERT_THAT(output, ElementsAre("1", "2", "3")); |
| 39 | } |