mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 04:07:10 +01:00 
			
		
		
		
	Moved RandomNumberGenerator out of function and pass in a named instance instead of a temporary - both for C++03 compatibility reasons
This commit is contained in:
		| @@ -22,6 +22,13 @@ | |||||||
| namespace Catch { | namespace Catch { | ||||||
|  |  | ||||||
|     class TestRegistry : public ITestCaseRegistry { |     class TestRegistry : public ITestCaseRegistry { | ||||||
|  |         struct LexSort { | ||||||
|  |             bool operator() (TestCase i,TestCase j) const { return (i<j);} | ||||||
|  |         }; | ||||||
|  |         struct RandomNumberGenerator { | ||||||
|  |             int operator()( int n ) const { return std::rand() % n; } | ||||||
|  |         }; | ||||||
|  |  | ||||||
|     public: |     public: | ||||||
|         TestRegistry() : m_unnamedCount( 0 ) {} |         TestRegistry() : m_unnamedCount( 0 ) {} | ||||||
|         virtual ~TestRegistry(); |         virtual ~TestRegistry(); | ||||||
| @@ -60,15 +67,7 @@ namespace Catch { | |||||||
|             return m_nonHiddenFunctions; |             return m_nonHiddenFunctions; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases ) const { |         virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases ) const { | ||||||
|             struct LexSort { |  | ||||||
|                 bool operator() (TestCase i,TestCase j) const { return (i<j);} |  | ||||||
|             }; |  | ||||||
|             struct RandomNumberGenerator { |  | ||||||
|                 int operator()( int n ) const { return std::rand() % n; } |  | ||||||
|             }; |  | ||||||
|  |  | ||||||
|             for( std::vector<TestCase>::const_iterator  it = m_functionsInOrder.begin(), |             for( std::vector<TestCase>::const_iterator  it = m_functionsInOrder.begin(), | ||||||
|                                                         itEnd = m_functionsInOrder.end(); |                                                         itEnd = m_functionsInOrder.end(); | ||||||
| @@ -82,7 +81,10 @@ namespace Catch { | |||||||
|                     std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() ); |                     std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() ); | ||||||
|                     break; |                     break; | ||||||
|                 case RunTests::InRandomOrder: |                 case RunTests::InRandomOrder: | ||||||
|                     std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), RandomNumberGenerator() ); |                     { | ||||||
|  |                         RandomNumberGenerator rng; | ||||||
|  |                         std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng ); | ||||||
|  |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case RunTests::InDeclarationOrder: |                 case RunTests::InDeclarationOrder: | ||||||
|                     // already in declaration order |                     // already in declaration order | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash