52# include <gtest/gtest.h>
61using namespace std::chrono;
62using namespace testing;
66 vector <int>
a = {3, 2, 1, 0, 4, 5, 6, 7, 8, 9};
67 Array <int>
b = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
68 Array <string>
c = {
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j"};
76 for (
int i = 0;
i < n;
i++)
99 ASSERT_EQ(a, vector<int>({ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
101 ASSERT_EQ(
to_vector(b), vector<int>({ 3, 2, 1, 0, 4, 5, 6, 7, 8, 9 }));
104 vector<string>({
"d",
"c",
"b",
"a",
"e",
"f",
"g",
"h",
"i",
"j"}));
109 auto start = high_resolution_clock::now();
110 in_place_multisort_arrays(std::less <int>(), a, b, c, d, e, f, g,
h, i, j);
111 auto stop = high_resolution_clock::now();
112 auto duration = duration_cast <milliseconds>(stop - start);
113 cout <<
"Time taken by function: "
114 << duration.count() <<
" milliseconds" << endl;
117TEST(MultiSortArrays, stable_with_duplicates)
119 vector<int>
keys = {2, 1, 2, 1, 2};
120 vector<char> aux = {
'a',
'b',
'c',
'd',
'e'};
121 vector<int> expect_keys = {1, 1, 2, 2, 2};
122 vector<char> expect_aux = {
'b',
'd',
'a',
'c',
'e'};
126 EXPECT_EQ(
keys, expect_keys);
127 EXPECT_EQ(aux, expect_aux);
130TEST(MultiSortArrays, size_mismatch_throws)
132 vector<int>
keys = {1, 0};
133 vector<int> aux = {10};
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
Conversion utilities between Aleph-w containers and STL containers.
String manipulation utilities.
High-level sorting functions for Aleph containers.
A random number generator with the sequences of GSL's gsl_rng_mt19937.
unsigned long uniform_int(const unsigned long n)
An integer in [0, n), each with the same probability, as gsl_rng_uniform_int(r, n).
Main namespace for Aleph-w library functions.
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
void in_place_multisort_arrays(Cmp cmp, const bool stable, C &first, Args &... args)
Sorts multiple arrays in place, using the first array as the key.
std::vector< typename C::Item_Type > to_vector(const C &c)
Convert a container to a std::vector.
TEST_F(SimpleArray, sort)
static vector< int > rand_vec(int n, Gsl_Compatible_Rng &rng)