| 1 |
#include <pbcopper/utility/MoveAppend.h> |
| 2 |
|
| 3 |
#include <set> |
| 4 |
#include <string> |
| 5 |
#include <vector> |
| 6 |
|
| 7 |
#include <gtest/gtest.h> |
| 8 |
|
| 9 |
namespace MoveAppendTests { |
| 10 |
|
| 11 |
template <typename T, typename U> |
| 12 |
auto CheckLValueAppend(T& src1, T& src2, U& dest, const U& expected) |
| 13 |
{ |
| 14 |
PacBio::Utility::MoveAppend(src1, dest); |
| 15 |
PacBio::Utility::MoveAppend(src2, dest); |
| 16 |
ASSERT_EQ(dest.size(), expected.size()); |
| 17 |
EXPECT_TRUE(src1.empty()); |
| 18 |
EXPECT_TRUE(src2.empty()); |
| 19 |
EXPECT_EQ(dest, expected); |
| 20 |
} |
| 21 |
|
| 22 |
template <typename T, typename U> |
| 23 |
auto CheckRValueAppend(T&& src1, T&& src2, U& dest, const U& expected) |
| 24 |
{ |
| 25 |
PacBio::Utility::MoveAppend(std::move(src1), dest); |
| 26 |
PacBio::Utility::MoveAppend(std::move(src2), dest); |
| 27 |
ASSERT_EQ(dest.size(), expected.size()); |
| 28 |
EXPECT_TRUE(src1.empty()); |
| 29 |
EXPECT_TRUE(src2.empty()); |
| 30 |
EXPECT_EQ(dest, expected); |
| 31 |
} |
| 32 |
|
| 33 |
} // namespace MoveAppendTests |
| 34 |
|
| 35 |
TEST(Utility_MoveAppend, can_append_from_empty_source) |
| 36 |
{ |
| 37 |
{ |
| 38 |
std::vector<int> src1; |
| 39 |
std::vector<int> src2; |
| 40 |
std::vector<int> dest{0, 1, 2}; |
| 41 |
const std::vector<int> expected{0, 1, 2}; |
| 42 |
MoveAppendTests::CheckLValueAppend(src1, src2, dest, expected); |
| 43 |
} |
| 44 |
{ |
| 45 |
std::vector<int> src1; |
| 46 |
std::vector<int> src2; |
| 47 |
std::vector<int> dest{0, 1, 2}; |
| 48 |
const std::vector<int> expected{0, 1, 2}; |
| 49 |
MoveAppendTests::CheckRValueAppend(std::move(src1), std::move(src2), dest, expected); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
TEST(Utility_MoveAppend, can_append_into_empty_destination) |
| 54 |
{ |
| 55 |
{ |
| 56 |
std::vector<int> src1{0, 2, 4}; |
| 57 |
std::vector<int> src2{1, 3, 5}; |
| 58 |
std::vector<int> dest; |
| 59 |
const std::vector<int> expected{0, 2, 4, 1, 3, 5}; |
| 60 |
MoveAppendTests::CheckLValueAppend(src1, src2, dest, expected); |
| 61 |
} |
| 62 |
{ |
| 63 |
std::vector<int> src1{0, 2, 4}; |
| 64 |
std::vector<int> src2{1, 3, 5}; |
| 65 |
std::vector<int> dest; |
| 66 |
const std::vector<int> expected{0, 2, 4, 1, 3, 5}; |
| 67 |
MoveAppendTests::CheckRValueAppend(std::move(src1), std::move(src2), dest, expected); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
TEST(Utility_MoveAppend, can_append_vectors) |
| 72 |
{ |
| 73 |
{ |
| 74 |
std::vector<int> src1{0, 2, 4}; |
| 75 |
std::vector<int> src2{1, 3, 5}; |
| 76 |
std::vector<int> dest{20, 30, 40}; |
| 77 |
const std::vector<int> expected{20, 30, 40, 0, 2, 4, 1, 3, 5}; |
| 78 |
MoveAppendTests::CheckLValueAppend(src1, src2, dest, expected); |
| 79 |
} |
| 80 |
{ |
| 81 |
std::vector<int> src1{0, 2, 4}; |
| 82 |
std::vector<int> src2{1, 3, 5}; |
| 83 |
std::vector<int> dest{20, 30, 40}; |
| 84 |
const std::vector<int> expected{20, 30, 40, 0, 2, 4, 1, 3, 5}; |
| 85 |
MoveAppendTests::CheckRValueAppend(std::move(src1), std::move(src2), dest, expected); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
TEST(Utility_MoveAppend, can_append_strings) |
| 90 |
{ |
| 91 |
{ |
| 92 |
std::string hello{"hello "}; |
| 93 |
std::string world{"world!"}; |
| 94 |
std::string dest; |
| 95 |
const std::string expected{"hello world!"}; |
| 96 |
MoveAppendTests::CheckLValueAppend(hello, world, dest, expected); |
| 97 |
} |
| 98 |
{ |
| 99 |
std::string hello{"hello "}; |
| 100 |
std::string world{"world!"}; |
| 101 |
std::string dest; |
| 102 |
const std::string expected{"hello world!"}; |
| 103 |
MoveAppendTests::CheckRValueAppend(std::move(hello), std::move(world), dest, expected); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
TEST(Utility_MoveAppend, can_append_from_different_container_types) |
| 108 |
{ |
| 109 |
{ |
| 110 |
std::set<int> src1{0, 2, 4}; |
| 111 |
std::set<int> src2{1, 3, 5}; |
| 112 |
std::vector<int> dest{20, 30, 40}; |
| 113 |
const std::vector<int> expected{20, 30, 40, 0, 2, 4, 1, 3, 5}; |
| 114 |
MoveAppendTests::CheckLValueAppend(src1, src2, dest, expected); |
| 115 |
} |
| 116 |
{ |
| 117 |
std::set<int> src1{0, 2, 4}; |
| 118 |
std::set<int> src2{1, 3, 5}; |
| 119 |
std::vector<int> dest{20, 30, 40}; |
| 120 |
const std::vector<int> expected{20, 30, 40, 0, 2, 4, 1, 3, 5}; |
| 121 |
MoveAppendTests::CheckRValueAppend(std::move(src1), std::move(src2), dest, expected); |
| 122 |
} |
| 123 |
} |