| 1 |
#include <pbcopper/utility/Shuffle.h> |
| 2 |
|
| 3 |
#include <vector> |
| 4 |
|
| 5 |
#include <gtest/gtest.h> |
| 6 |
|
| 7 |
using namespace PacBio; |
| 8 |
|
| 9 |
TEST(Utility_Shuffle, can_stably_shuffle_container) |
| 10 |
{ |
| 11 |
const std::vector<int> expected{5, 1, 3, 6, 7, 8, 0, 9, 2, 4}; |
| 12 |
|
| 13 |
std::vector<int> v{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 14 |
Utility::Shuffle(v, 42); |
| 15 |
EXPECT_EQ(v, expected); |
| 16 |
} |
| 17 |
|
| 18 |
TEST(Utility_Shuffle, can_stably_shuffle_range) |
| 19 |
{ |
| 20 |
// clang-format off |
| 21 |
const std::vector<int> expected{ |
| 22 |
2, 0, 3, 1, 4, // shuffled |
| 23 |
5, 6, 7, 8, 9}; // untouched |
| 24 |
// clang-format on |
| 25 |
|
| 26 |
std::vector<int> v{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 27 |
Utility::Shuffle(v.begin(), v.begin() + 5, 42); |
| 28 |
EXPECT_EQ(v, expected); |
| 29 |
} |
| 30 |
|
| 31 |
TEST(Utility_Shuffle, can_stably_shuffle_container_reusing_mte) |
| 32 |
{ |
| 33 |
const std::vector<int> expected{5, 1, 3, 6, 7, 8, 0, 9, 2, 4}; |
| 34 |
|
| 35 |
std::vector<int> v{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 36 |
std::mt19937_64 eng; |
| 37 |
Utility::Shuffle(v, eng, 42); |
| 38 |
EXPECT_EQ(v, expected); |
| 39 |
} |
| 40 |
|
| 41 |
TEST(Utility_Shuffle, can_stably_shuffle_range_reusing_mte) |
| 42 |
{ |
| 43 |
// clang-format off |
| 44 |
const std::vector<int> expected{ |
| 45 |
2, 0, 3, 1, 4, // shuffled |
| 46 |
5, 6, 7, 8, 9}; // untouched |
| 47 |
// clang-format on |
| 48 |
|
| 49 |
std::vector<int> v{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 50 |
std::mt19937_64 eng; |
| 51 |
Utility::Shuffle(v.begin(), v.begin() + 5, eng, 42); |
| 52 |
EXPECT_EQ(v, expected); |
| 53 |
} |