Better random number facilities in UnitTest

This commit is contained in:
Vinnie Falco
2013-09-12 19:41:09 -07:00
parent 550b8e55ee
commit e96ce99d3d
3 changed files with 27 additions and 7 deletions

View File

@@ -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)
{