mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Better random number facilities in UnitTest
This commit is contained in:
@@ -69,10 +69,12 @@ void UnitTest::shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
ScopedPointer <UnitTest::Suite>& UnitTest::run (UnitTests* const runner)
|
||||
ScopedPointer <UnitTest::Suite>& UnitTest::run (
|
||||
UnitTests* const runner)
|
||||
{
|
||||
bassert (runner != nullptr);
|
||||
m_runner = runner;
|
||||
m_random = m_runner->m_random;
|
||||
|
||||
m_suite = new Suite (m_className, m_packageName);
|
||||
|
||||
@@ -191,6 +193,14 @@ void UnitTest::failException ()
|
||||
m_runner->onFailure ();
|
||||
}
|
||||
|
||||
Random& UnitTest::random()
|
||||
{
|
||||
// This method's only valid while the test is being run!
|
||||
bassert (m_runner != nullptr);
|
||||
|
||||
return m_random;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void UnitTest::finishCase ()
|
||||
@@ -339,13 +349,17 @@ UnitTests::TestList UnitTests::selectStartupTests (TestList const& tests) const
|
||||
return list;
|
||||
}
|
||||
|
||||
void UnitTests::runSelectedTests (String const& match, TestList const& tests)
|
||||
void UnitTests::runSelectedTests (String const& match, TestList const& tests, int64 randomSeed)
|
||||
{
|
||||
runTests (selectTests (match, tests));
|
||||
runTests (selectTests (match, tests), randomSeed);
|
||||
}
|
||||
|
||||
void UnitTests::runTests (TestList const& tests)
|
||||
void UnitTests::runTests (TestList const& tests, int64 randomSeed)
|
||||
{
|
||||
if (randomSeed == 0)
|
||||
randomSeed = Random().nextInt (0x7fffffff);
|
||||
m_random = Random (randomSeed);
|
||||
|
||||
m_results = new Results;
|
||||
for (int i = 0; i < tests.size (); ++i)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user