blob: d47d8d3b4a1716d3dacbb44dfc5e92e624f10cf3 [file] [log] [blame]
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +00001#include "helpers.hpp"
Wludzik, Jozefe2362792020-10-27 17:23:55 +01002#include "utils/transform.hpp"
3
4#include <set>
5#include <vector>
6
7#include <gmock/gmock.h>
8
9using namespace testing;
10
11TEST(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 Grobelny60fee072022-01-13 16:25:04 +010016 EXPECT_TRUE(utils::detail::has_member_reserve<decltype(input)>);
17 EXPECT_TRUE(utils::detail::has_member_reserve<decltype(output)>);
Wludzik, Jozefe2362792020-10-27 17:23:55 +010018 ASSERT_THAT(output, ElementsAre("1", "2", "3"));
19}
20
21TEST(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 Grobelny60fee072022-01-13 16:25:04 +010026 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
31TEST(TestTransform, transformsArrayToVector)
32{
33 std::array<int, 3> input = {1, 2, 3};
Szymon Dompkefdb06a12022-02-11 11:04:44 +010034 std::vector<std::string> output = utils::transform<std::vector>(
35 input, [](int v) { return std::to_string(v); });
Krzysztof Grobelny60fee072022-01-13 16:25:04 +010036 EXPECT_FALSE(utils::detail::has_member_reserve<decltype(input)>);
37 EXPECT_TRUE(utils::detail::has_member_reserve<decltype(output)>);
Wludzik, Jozefe2362792020-10-27 17:23:55 +010038 ASSERT_THAT(output, ElementsAre("1", "2", "3"));
39}