mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Split RNG related things into its own file
This further removes 2 function declarations from the common path
This commit is contained in:
parent
48db47c737
commit
0673b9be35
@ -161,6 +161,7 @@ set(INTERNAL_HEADERS
|
|||||||
${HEADER_DIR}/internal/catch_objc_arc.hpp
|
${HEADER_DIR}/internal/catch_objc_arc.hpp
|
||||||
${HEADER_DIR}/internal/catch_option.hpp
|
${HEADER_DIR}/internal/catch_option.hpp
|
||||||
${HEADER_DIR}/internal/catch_platform.h
|
${HEADER_DIR}/internal/catch_platform.h
|
||||||
|
${HEADER_DIR}/internal/catch_random_number_generator.h
|
||||||
${HEADER_DIR}/internal/catch_reenable_warnings.h
|
${HEADER_DIR}/internal/catch_reenable_warnings.h
|
||||||
${HEADER_DIR}/internal/catch_reporter_registrars.hpp
|
${HEADER_DIR}/internal/catch_reporter_registrars.hpp
|
||||||
${HEADER_DIR}/internal/catch_reporter_registry.hpp
|
${HEADER_DIR}/internal/catch_reporter_registry.hpp
|
||||||
@ -218,6 +219,7 @@ set(IMPL_SOURCES
|
|||||||
${HEADER_DIR}/internal/catch_notimplemented_exception.cpp
|
${HEADER_DIR}/internal/catch_notimplemented_exception.cpp
|
||||||
${HEADER_DIR}/internal/catch_registry_hub.cpp
|
${HEADER_DIR}/internal/catch_registry_hub.cpp
|
||||||
${HEADER_DIR}/internal/catch_interfaces_reporter.cpp
|
${HEADER_DIR}/internal/catch_interfaces_reporter.cpp
|
||||||
|
${HEADER_DIR}/internal/catch_random_number_generator.cpp
|
||||||
${HEADER_DIR}/internal/catch_result_type.cpp
|
${HEADER_DIR}/internal/catch_result_type.cpp
|
||||||
${HEADER_DIR}/internal/catch_run_context.cpp
|
${HEADER_DIR}/internal/catch_run_context.cpp
|
||||||
${HEADER_DIR}/internal/catch_section.cpp
|
${HEADER_DIR}/internal/catch_section.cpp
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "internal/catch_test_spec.hpp"
|
#include "internal/catch_test_spec.hpp"
|
||||||
#include "internal/catch_version.h"
|
#include "internal/catch_version.h"
|
||||||
#include "internal/catch_interfaces_reporter.h"
|
#include "internal/catch_interfaces_reporter.h"
|
||||||
|
#include "internal/catch_random_number_generator.h"
|
||||||
#include "internal/catch_startup_exception_registry.h"
|
#include "internal/catch_startup_exception_registry.h"
|
||||||
#include "internal/catch_text.h"
|
#include "internal/catch_text.h"
|
||||||
|
|
||||||
|
@ -29,14 +29,6 @@ namespace Catch {
|
|||||||
return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
|
return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void seedRng( IConfig const& config ) {
|
|
||||||
if( config.rngSeed() != 0 )
|
|
||||||
std::srand( config.rngSeed() );
|
|
||||||
}
|
|
||||||
unsigned int rngSeed() {
|
|
||||||
return getCurrentContext().getConfig()->rngSeed();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
|
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
|
||||||
#ifndef __GNUG__
|
#ifndef __GNUG__
|
||||||
os << info.file << '(' << info.line << ')';
|
os << info.file << '(' << info.line << ')';
|
||||||
|
@ -67,9 +67,6 @@ namespace Catch {
|
|||||||
bool alwaysTrue();
|
bool alwaysTrue();
|
||||||
bool alwaysFalse();
|
bool alwaysFalse();
|
||||||
|
|
||||||
void seedRng( IConfig const& config );
|
|
||||||
unsigned int rngSeed();
|
|
||||||
|
|
||||||
// Use this in variadic streaming macros to allow
|
// Use this in variadic streaming macros to allow
|
||||||
// >> +StreamEndStop
|
// >> +StreamEndStop
|
||||||
// as well as
|
// as well as
|
||||||
|
31
include/internal/catch_random_number_generator.cpp
Normal file
31
include/internal/catch_random_number_generator.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 30/08/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_random_number_generator.h"
|
||||||
|
#include "catch_context.h"
|
||||||
|
#include "catch_interfaces_config.h"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
void seedRng( IConfig const& config ) {
|
||||||
|
if( config.rngSeed() != 0 )
|
||||||
|
std::srand( config.rngSeed() );
|
||||||
|
}
|
||||||
|
unsigned int rngSeed() {
|
||||||
|
return getCurrentContext().getConfig()->rngSeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const {
|
||||||
|
return std::rand() % n;
|
||||||
|
}
|
||||||
|
RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const {
|
||||||
|
return std::rand() % max();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
include/internal/catch_random_number_generator.h
Normal file
40
include/internal/catch_random_number_generator.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 30/08/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_RANDOM_NUMBER_GENERATOR_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_RANDOM_NUMBER_GENERATOR_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_random_number_generator.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct IConfig;
|
||||||
|
|
||||||
|
void seedRng( IConfig const& config );
|
||||||
|
|
||||||
|
unsigned int rngSeed();
|
||||||
|
|
||||||
|
struct RandomNumberGenerator {
|
||||||
|
using result_type = std::ptrdiff_t;
|
||||||
|
|
||||||
|
static constexpr result_type min() { return 0; }
|
||||||
|
static constexpr result_type max() { return 1000000; }
|
||||||
|
|
||||||
|
result_type operator()( result_type n ) const;
|
||||||
|
result_type operator()() const;
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
static void shuffle( V& vector ) {
|
||||||
|
RandomNumberGenerator rng;
|
||||||
|
std::shuffle( vector.begin(), vector.end(), rng );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_RANDOM_NUMBER_GENERATOR_H_INCLUDED
|
@ -1,6 +1,7 @@
|
|||||||
#include "catch_run_context.hpp"
|
#include "catch_run_context.hpp"
|
||||||
#include "catch_context.h"
|
#include "catch_context.h"
|
||||||
#include "catch_enforce.h"
|
#include "catch_enforce.h"
|
||||||
|
#include "catch_random_number_generator.h"
|
||||||
#include "catch_stream.h"
|
#include "catch_stream.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "catch_context.h"
|
#include "catch_context.h"
|
||||||
#include "catch_enforce.h"
|
#include "catch_enforce.h"
|
||||||
#include "catch_interfaces_registry_hub.h"
|
#include "catch_interfaces_registry_hub.h"
|
||||||
|
#include "catch_random_number_generator.h"
|
||||||
#include "catch_string_manip.h"
|
#include "catch_string_manip.h"
|
||||||
#include "catch_test_case_info.h"
|
#include "catch_test_case_info.h"
|
||||||
|
|
||||||
@ -17,9 +18,6 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const { return std::rand() % n; }
|
|
||||||
RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const { return std::rand() % max(); }
|
|
||||||
|
|
||||||
std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
|
std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
|
||||||
|
|
||||||
std::vector<TestCase> sorted = unsortedTestCases;
|
std::vector<TestCase> sorted = unsortedTestCases;
|
||||||
|
@ -22,21 +22,6 @@ namespace Catch {
|
|||||||
class TestCase;
|
class TestCase;
|
||||||
struct IConfig;
|
struct IConfig;
|
||||||
|
|
||||||
struct RandomNumberGenerator {
|
|
||||||
using result_type = std::ptrdiff_t;
|
|
||||||
|
|
||||||
result_type operator()( result_type n ) const;
|
|
||||||
|
|
||||||
static constexpr result_type min() { return 0; }
|
|
||||||
static constexpr result_type max() { return 1000000; }
|
|
||||||
result_type operator()() const;
|
|
||||||
template<typename V>
|
|
||||||
static void shuffle( V& vector ) {
|
|
||||||
RandomNumberGenerator rng;
|
|
||||||
std::shuffle( vector.begin(), vector.end(), rng );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
|
std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
|
||||||
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
|
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user