| 61 | } |
| 62 | |
| 63 | void ExpectSortPermutation(std::vector<std::string> unsorted, |
| 64 | std::vector<int64_t> expected_indices, |
| 65 | size_t expected_cycle_count) { |
| 66 | auto actual_indices = ArgSort(unsorted); |
| 67 | EXPECT_THAT(actual_indices, ::testing::ContainerEq(expected_indices)); |
| 68 | |
| 69 | auto sorted = unsorted; |
| 70 | std::sort(sorted.begin(), sorted.end()); |
| 71 | |
| 72 | auto permuted = unsorted; |
| 73 | EXPECT_EQ(Permute(expected_indices, &permuted), expected_cycle_count); |
| 74 | |
| 75 | EXPECT_THAT(permuted, ::testing::ContainerEq(sorted)); |
| 76 | } |
| 77 | |
| 78 | TEST(StlUtilTest, ArgSortPermute) { |
| 79 | std::string f = "foxtrot", a = "alpha", b = "bravo", d = "delta", c = "charlie", |