mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Use std::shuffle instead of (deprecated) std::random_shuffle if C++14 detected
This commit is contained in:
parent
a74d760d74
commit
be3570ef22
@ -36,10 +36,18 @@
|
|||||||
|
|
||||||
// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
|
// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
|
||||||
|
|
||||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
# if __cplusplus >= 201103L
|
||||||
# define CATCH_CPP11_OR_GREATER
|
# define CATCH_CPP11_OR_GREATER
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# if __cplusplus >= 201402L
|
||||||
|
# define CATCH_CPP14_OR_GREATER
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
|
|
||||||
# if __has_feature(cxx_nullptr)
|
# if __has_feature(cxx_nullptr)
|
||||||
|
@ -19,13 +19,30 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#ifdef CATCH_CPP14_OR_GREATER
|
||||||
|
#include <random>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct LexSort {
|
|
||||||
bool operator() (TestCase i,TestCase j) const { return (i<j);}
|
|
||||||
};
|
|
||||||
struct RandomNumberGenerator {
|
struct RandomNumberGenerator {
|
||||||
int operator()( int n ) const { return std::rand() % n; }
|
typedef int result_type;
|
||||||
|
|
||||||
|
result_type operator()( result_type n ) const { return std::rand() % n; }
|
||||||
|
|
||||||
|
#ifdef CATCH_CPP14_OR_GREATER
|
||||||
|
static constexpr result_type min() { return 0; }
|
||||||
|
static constexpr result_type max() { return 1000000; }
|
||||||
|
result_type operator()() const { return std::rand() % max(); }
|
||||||
|
#endif
|
||||||
|
template<typename V>
|
||||||
|
static void shuffle( V& vector ) {
|
||||||
|
#ifdef CATCH_CPP14_OR_GREATER
|
||||||
|
std::shuffle( vector.begin(), vector.end(), RandomNumberGenerator() );
|
||||||
|
#else
|
||||||
|
std::random_shuffle( vector.begin(), vector.end(), RandomNumberGenerator() );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
|
inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
|
||||||
@ -34,14 +51,12 @@ namespace Catch {
|
|||||||
|
|
||||||
switch( config.runOrder() ) {
|
switch( config.runOrder() ) {
|
||||||
case RunTests::InLexicographicalOrder:
|
case RunTests::InLexicographicalOrder:
|
||||||
std::sort( sorted.begin(), sorted.end(), LexSort() );
|
std::sort( sorted.begin(), sorted.end() );
|
||||||
break;
|
break;
|
||||||
case RunTests::InRandomOrder:
|
case RunTests::InRandomOrder:
|
||||||
{
|
{
|
||||||
seedRng( config );
|
seedRng( config );
|
||||||
|
RandomNumberGenerator::shuffle( sorted );
|
||||||
RandomNumberGenerator rng;
|
|
||||||
std::random_shuffle( sorted.begin(), sorted.end(), rng );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RunTests::InDeclarationOrder:
|
case RunTests::InDeclarationOrder:
|
||||||
|
Loading…
Reference in New Issue
Block a user