Stop using random_shuffle in the libc++ test suite. It's going to be removed in c++17. Use shuffle() instead. No change to libc++, just the tests.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294328 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -15,14 +15,17 @@
|
||||
// make_heap(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void test(int N)
|
||||
{
|
||||
int* ia = new int [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N);
|
||||
assert(std::is_heap(ia, ia+N));
|
||||
delete [] ia;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
@@ -29,6 +30,7 @@ struct indirect_less
|
||||
{return *x < *y;}
|
||||
};
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void test(int N)
|
||||
{
|
||||
@@ -36,7 +38,7 @@ void test(int N)
|
||||
{
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N, std::greater<int>());
|
||||
assert(std::is_heap(ia, ia+N, std::greater<int>()));
|
||||
}
|
||||
@@ -64,7 +66,7 @@ void test(int N)
|
||||
// Random
|
||||
{
|
||||
binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>()));
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N, std::ref(pred));
|
||||
assert(pred.count() <= 3u*N);
|
||||
assert(std::is_heap(ia, ia+N, pred));
|
||||
@@ -90,7 +92,7 @@ int main()
|
||||
std::unique_ptr<int>* ia = new std::unique_ptr<int> [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i].reset(new int(i));
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N, indirect_less());
|
||||
assert(std::is_heap(ia, ia+N, indirect_less()));
|
||||
delete [] ia;
|
||||
|
||||
@@ -15,14 +15,17 @@
|
||||
// pop_heap(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void test(int N)
|
||||
{
|
||||
int* ia = new int [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N);
|
||||
for (int i = N; i > 0; --i)
|
||||
{
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
#include <memory>
|
||||
|
||||
|
||||
struct indirect_less
|
||||
{
|
||||
template <class P>
|
||||
@@ -29,12 +31,14 @@ struct indirect_less
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void test(int N)
|
||||
{
|
||||
int* ia = new int [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N, std::greater<int>());
|
||||
for (int i = N; i > 0; --i)
|
||||
{
|
||||
@@ -55,7 +59,7 @@ int main()
|
||||
std::unique_ptr<int>* ia = new std::unique_ptr<int> [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i].reset(new int(i));
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N, indirect_less());
|
||||
for (int i = N; i > 0; --i)
|
||||
{
|
||||
|
||||
@@ -16,14 +16,17 @@
|
||||
// push_heap(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void test(int N)
|
||||
{
|
||||
int* ia = new int [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
for (int i = 0; i <= N; ++i)
|
||||
{
|
||||
std::push_heap(ia, ia+i);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
#include <memory>
|
||||
@@ -30,12 +31,14 @@ struct indirect_less
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void test(int N)
|
||||
{
|
||||
int* ia = new int [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
for (int i = 0; i <= N; ++i)
|
||||
{
|
||||
std::push_heap(ia, ia+i, std::greater<int>());
|
||||
@@ -54,7 +57,7 @@ int main()
|
||||
std::unique_ptr<int>* ia = new std::unique_ptr<int> [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i].reset(new int(i));
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
for (int i = 0; i <= N; ++i)
|
||||
{
|
||||
std::push_heap(ia, ia+i, indirect_less());
|
||||
|
||||
@@ -15,14 +15,17 @@
|
||||
// sort_heap(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void test(int N)
|
||||
{
|
||||
int* ia = new int [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N);
|
||||
std::sort_heap(ia, ia+N);
|
||||
assert(std::is_sorted(ia, ia+N));
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
#include <memory>
|
||||
@@ -29,12 +30,14 @@ struct indirect_less
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void test(int N)
|
||||
{
|
||||
int* ia = new int [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N, std::greater<int>());
|
||||
std::sort_heap(ia, ia+N, std::greater<int>());
|
||||
assert(std::is_sorted(ia, ia+N, std::greater<int>()));
|
||||
@@ -56,7 +59,7 @@ int main()
|
||||
std::unique_ptr<int>* ia = new std::unique_ptr<int> [N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i].reset(new int(i));
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::make_heap(ia, ia+N, indirect_less());
|
||||
std::sort_heap(ia, ia+N, indirect_less());
|
||||
assert(std::is_sorted(ia, ia+N, indirect_less()));
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// inplace_merge(Iter first, Iter middle, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
@@ -42,6 +43,8 @@ struct S {
|
||||
};
|
||||
#endif
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test_one(unsigned N, unsigned M)
|
||||
@@ -51,7 +54,7 @@ test_one(unsigned N, unsigned M)
|
||||
value_type* ia = new value_type[N];
|
||||
for (unsigned i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::sort(ia, ia+M);
|
||||
std::sort(ia+M, ia+N);
|
||||
std::inplace_merge(Iter(ia), Iter(ia+M), Iter(ia+N));
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
@@ -58,6 +59,8 @@ struct S {
|
||||
#include "test_iterators.h"
|
||||
#include "counting_predicates.hpp"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test_one(unsigned N, unsigned M)
|
||||
@@ -67,7 +70,7 @@ test_one(unsigned N, unsigned M)
|
||||
value_type* ia = new value_type[N];
|
||||
for (unsigned i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::sort(ia, ia+M, std::greater<value_type>());
|
||||
std::sort(ia+M, ia+N, std::greater<value_type>());
|
||||
binary_counting_predicate<std::greater<value_type>, value_type, value_type> pred((std::greater<value_type>()));
|
||||
@@ -130,7 +133,7 @@ int main()
|
||||
std::unique_ptr<int>* ia = new std::unique_ptr<int>[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i].reset(new int(i));
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::shuffle(ia, ia+N, randomness);
|
||||
std::sort(ia, ia+M, indirect_less());
|
||||
std::sort(ia+M, ia+N, indirect_less());
|
||||
std::inplace_merge(ia, ia+M, ia+N, indirect_less());
|
||||
|
||||
@@ -19,10 +19,13 @@
|
||||
// merge(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, OutIter result);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class InIter1, class InIter2, class OutIter>
|
||||
void
|
||||
test()
|
||||
@@ -53,7 +56,7 @@ test()
|
||||
int* ic = new int[2*N];
|
||||
for (unsigned i = 0; i < 2*N; ++i)
|
||||
ic[i] = i;
|
||||
std::random_shuffle(ic, ic+2*N);
|
||||
std::shuffle(ic, ic+2*N, randomness);
|
||||
std::copy(ic, ic+N, ia);
|
||||
std::copy(ic+N, ic+2*N, ib);
|
||||
std::sort(ia, ia+N);
|
||||
|
||||
@@ -22,11 +22,14 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
#include "counting_predicates.hpp"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class InIter1, class InIter2, class OutIter>
|
||||
void
|
||||
test()
|
||||
@@ -61,7 +64,7 @@ test()
|
||||
int* ic = new int[2*N];
|
||||
for (unsigned i = 0; i < 2*N; ++i)
|
||||
ic[i] = i;
|
||||
std::random_shuffle(ic, ic+2*N);
|
||||
std::shuffle(ic, ic+2*N, randomness);
|
||||
std::copy(ic, ic+N, ia);
|
||||
std::copy(ic+N, ic+2*N, ib);
|
||||
std::sort(ia, ia+N, std::greater<int>());
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
// max_element(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test(Iter first, Iter last)
|
||||
@@ -40,7 +43,7 @@ test(int N)
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = i;
|
||||
std::random_shuffle(a, a+N);
|
||||
std::shuffle(a, a+N, randomness);
|
||||
test(Iter(a), Iter(a+N));
|
||||
delete [] a;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test(Iter first, Iter last)
|
||||
@@ -42,7 +45,7 @@ test(int N)
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = i;
|
||||
std::random_shuffle(a, a+N);
|
||||
std::shuffle(a, a+N, randomness);
|
||||
test(Iter(a), Iter(a+N));
|
||||
delete [] a;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
// min_element(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test(Iter first, Iter last)
|
||||
@@ -40,7 +43,7 @@ test(int N)
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = i;
|
||||
std::random_shuffle(a, a+N);
|
||||
std::shuffle(a, a+N, randomness);
|
||||
test(Iter(a), Iter(a+N));
|
||||
delete [] a;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test(Iter first, Iter last)
|
||||
@@ -42,7 +45,7 @@ test(int N)
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = i;
|
||||
std::random_shuffle(a, a+N);
|
||||
std::shuffle(a, a+N, randomness);
|
||||
test(Iter(a), Iter(a+N));
|
||||
delete [] a;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
// minmax_element(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test(Iter first, Iter last)
|
||||
@@ -46,7 +49,7 @@ test(int N)
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = i;
|
||||
std::random_shuffle(a, a+N);
|
||||
std::shuffle(a, a+N, randomness);
|
||||
test(Iter(a), Iter(a+N));
|
||||
delete [] a;
|
||||
}
|
||||
@@ -66,7 +69,7 @@ test()
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = 5;
|
||||
std::random_shuffle(a, a+N);
|
||||
std::shuffle(a, a+N, randomness);
|
||||
std::pair<Iter, Iter> p = std::minmax_element(Iter(a), Iter(a+N));
|
||||
assert(base(p.first) == a);
|
||||
assert(base(p.second) == a+N-1);
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test(Iter first, Iter last)
|
||||
@@ -50,7 +53,7 @@ test(int N)
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = i;
|
||||
std::random_shuffle(a, a+N);
|
||||
std::shuffle(a, a+N, randomness);
|
||||
test(Iter(a), Iter(a+N));
|
||||
delete [] a;
|
||||
}
|
||||
@@ -70,7 +73,7 @@ test()
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = 5;
|
||||
std::random_shuffle(a, a+N);
|
||||
std::shuffle(a, a+N, randomness);
|
||||
typedef std::greater<int> Compare;
|
||||
Compare comp;
|
||||
std::pair<Iter, Iter> p = std::minmax_element(Iter(a), Iter(a+N), comp);
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
// nth_element(Iter first, Iter nth, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void
|
||||
test_one(int N, int M)
|
||||
{
|
||||
@@ -26,7 +29,7 @@ test_one(int N, int M)
|
||||
int* array = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
array[i] = i;
|
||||
std::random_shuffle(array, array+N);
|
||||
std::shuffle(array, array+N, randomness);
|
||||
std::nth_element(array, array+M, array+N);
|
||||
assert(array[M] == M);
|
||||
std::nth_element(array, array+N, array+N); // begin, end, end
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
@@ -32,6 +33,8 @@ struct indirect_less
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void
|
||||
test_one(int N, int M)
|
||||
{
|
||||
@@ -40,7 +43,7 @@ test_one(int N, int M)
|
||||
int* array = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
array[i] = i;
|
||||
std::random_shuffle(array, array+N);
|
||||
std::shuffle(array, array+N, randomness);
|
||||
std::nth_element(array, array+M, array+N, std::greater<int>());
|
||||
assert(array[M] == N-M-1);
|
||||
std::nth_element(array, array+N, array+N, std::greater<int>()); // begin, end, end
|
||||
|
||||
@@ -18,10 +18,13 @@
|
||||
// partial_sort_copy(InIter first, InIter last, RAIter result_first, RAIter result_last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test_larger_sorts(int N, int M)
|
||||
@@ -30,7 +33,7 @@ test_larger_sorts(int N, int M)
|
||||
int* output = new int[M];
|
||||
for (int i = 0; i < N; ++i)
|
||||
input[i] = i;
|
||||
std::random_shuffle(input, input+N);
|
||||
std::shuffle(input, input+N, randomness);
|
||||
int* r = std::partial_sort_copy(Iter(input), Iter(input+N), output, output+M);
|
||||
int* e = output + std::min(N, M);
|
||||
assert(r == e);
|
||||
|
||||
@@ -21,10 +21,13 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test_larger_sorts(int N, int M)
|
||||
@@ -33,7 +36,7 @@ test_larger_sorts(int N, int M)
|
||||
int* output = new int[M];
|
||||
for (int i = 0; i < N; ++i)
|
||||
input[i] = i;
|
||||
std::random_shuffle(input, input+N);
|
||||
std::shuffle(input, input+N, randomness);
|
||||
int* r = std::partial_sort_copy(Iter(input), Iter(input+N), output, output+M,
|
||||
std::greater<int>());
|
||||
int* e = output + std::min(N, M);
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
// partial_sort(Iter first, Iter middle, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void
|
||||
test_larger_sorts(int N, int M)
|
||||
{
|
||||
@@ -26,7 +29,7 @@ test_larger_sorts(int N, int M)
|
||||
int* array = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
array[i] = i;
|
||||
std::random_shuffle(array, array+N);
|
||||
std::shuffle(array, array+N, randomness);
|
||||
std::partial_sort(array, array+M, array+N);
|
||||
for (int i = 0; i < M; ++i)
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
@@ -32,6 +33,8 @@ struct indirect_less
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
void
|
||||
test_larger_sorts(int N, int M)
|
||||
{
|
||||
@@ -40,7 +43,7 @@ test_larger_sorts(int N, int M)
|
||||
int* array = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
array[i] = i;
|
||||
std::random_shuffle(array, array+N);
|
||||
std::shuffle(array, array+N, randomness);
|
||||
std::partial_sort(array, array+M, array+N, std::greater<int>());
|
||||
for (int i = 0; i < M; ++i)
|
||||
{
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class RI>
|
||||
void
|
||||
test_sort_helper(RI f, RI l)
|
||||
@@ -92,7 +95,7 @@ test_larger_sorts(int N, int M)
|
||||
std::sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test random pattern
|
||||
std::random_shuffle(array, array+N);
|
||||
std::shuffle(array, array+N, randomness);
|
||||
std::sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test sorted pattern
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class RI>
|
||||
void
|
||||
test_sort_helper(RI f, RI l)
|
||||
@@ -92,7 +95,7 @@ test_larger_sorts(int N, int M)
|
||||
std::stable_sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test random pattern
|
||||
std::random_shuffle(array, array+N);
|
||||
std::shuffle(array, array+N, randomness);
|
||||
std::stable_sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test sorted pattern
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
@@ -32,6 +33,8 @@ struct indirect_less
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
struct first_only
|
||||
{
|
||||
bool operator()(const std::pair<int, int>& x, const std::pair<int, int>& y)
|
||||
@@ -59,7 +62,7 @@ void test()
|
||||
}
|
||||
for (int i = 0; i < N - M; i += M)
|
||||
{
|
||||
std::random_shuffle(v.begin() + i, v.begin() + i + M);
|
||||
std::shuffle(v.begin() + i, v.begin() + i + M, randomness);
|
||||
}
|
||||
std::stable_sort(v.begin(), v.end(), first_only());
|
||||
assert(std::is_sorted(v.begin(), v.end()));
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class C>
|
||||
void test(int N)
|
||||
{
|
||||
@@ -27,7 +30,7 @@ void test(int N)
|
||||
V v;
|
||||
for (int i = 0; i < N; ++i)
|
||||
v.push_back(i);
|
||||
std::random_shuffle(v.begin(), v.end());
|
||||
std::shuffle(v.begin(), v.end(), randomness);
|
||||
C c(v.begin(), v.end());
|
||||
c.sort();
|
||||
assert(distance(c.begin(), c.end()) == N);
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
#include "min_allocator.h"
|
||||
|
||||
std::mt19937 randomness;
|
||||
|
||||
template <class C>
|
||||
void test(int N)
|
||||
{
|
||||
@@ -28,7 +31,7 @@ void test(int N)
|
||||
V v;
|
||||
for (int i = 0; i < N; ++i)
|
||||
v.push_back(i);
|
||||
std::random_shuffle(v.begin(), v.end());
|
||||
std::shuffle(v.begin(), v.end(), randomness);
|
||||
C c(v.begin(), v.end());
|
||||
c.sort(std::greater<T>());
|
||||
assert(distance(c.begin(), c.end()) == N);
|
||||
|
||||
Reference in New Issue
Block a user