mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-28 02:30:05 +00:00
Change to the way options are passed to the UnitTestRunner.
This commit is contained in:
parent
438cc245ad
commit
a0a7fd994a
4 changed files with 76 additions and 14 deletions
|
|
@ -873,12 +873,12 @@ void BigInteger::inverseModulo (const BigInteger& modulus)
|
|||
|
||||
while (! a2.isOne())
|
||||
{
|
||||
BigInteger temp1, temp2, multiplier (a1);
|
||||
BigInteger temp1, multiplier (a1);
|
||||
multiplier.divideBy (a2, temp1);
|
||||
|
||||
temp1 = a2;
|
||||
temp1 *= multiplier;
|
||||
temp2 = a1;
|
||||
BigInteger temp2 (a1);
|
||||
temp2 -= temp1;
|
||||
a1 = a2;
|
||||
a2 = temp2;
|
||||
|
|
|
|||
|
|
@ -137,4 +137,42 @@ void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numB
|
|||
arrayToChange.setBit (startBit + numBits, nextBool());
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
#if JUCE_UNIT_TESTS
|
||||
|
||||
class RandomTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
RandomTests() : UnitTest ("Random") {}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
beginTest ("Random");
|
||||
|
||||
for (int j = 10; --j >= 0;)
|
||||
{
|
||||
Random r;
|
||||
r.setSeedRandomly();
|
||||
|
||||
for (int i = 20; --i >= 0;)
|
||||
{
|
||||
expect (r.nextDouble() >= 0.0 && r.nextDouble() < 1.0);
|
||||
expect (r.nextFloat() >= 0.0f && r.nextFloat() < 1.0f);
|
||||
expect (r.nextInt (5) >= 0 && r.nextInt (5) < 5);
|
||||
expect (r.nextInt (1) == 0);
|
||||
|
||||
int n = r.nextInt (50) + 1;
|
||||
expect (r.nextInt (n) >= 0 && r.nextInt (n) < n);
|
||||
|
||||
n = r.nextInt (0x7ffffffe) + 1;
|
||||
expect (r.nextInt (n) >= 0 && r.nextInt (n) < n);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static RandomTests randomTests;
|
||||
|
||||
#endif
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -76,7 +76,9 @@ void UnitTest::expect (const bool result, const String& failureMessage)
|
|||
|
||||
//==============================================================================
|
||||
UnitTestRunner::UnitTestRunner()
|
||||
: currentTest (nullptr), assertOnFailure (false)
|
||||
: currentTest (nullptr),
|
||||
assertOnFailure (false),
|
||||
logPasses (false)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -84,6 +86,16 @@ UnitTestRunner::~UnitTestRunner()
|
|||
{
|
||||
}
|
||||
|
||||
void UnitTestRunner::setAssertOnFailure (bool shouldAssert) noexcept
|
||||
{
|
||||
assertOnFailure = shouldAssert;
|
||||
}
|
||||
|
||||
void UnitTestRunner::setPassesAreLogged (bool shouldDisplayPasses) noexcept
|
||||
{
|
||||
logPasses = shouldDisplayPasses;
|
||||
}
|
||||
|
||||
int UnitTestRunner::getNumResults() const noexcept
|
||||
{
|
||||
return results.size();
|
||||
|
|
@ -98,10 +110,9 @@ void UnitTestRunner::resultsUpdated()
|
|||
{
|
||||
}
|
||||
|
||||
void UnitTestRunner::runTests (const Array<UnitTest*>& tests, const bool assertOnFailure_)
|
||||
void UnitTestRunner::runTests (const Array<UnitTest*>& tests)
|
||||
{
|
||||
results.clear();
|
||||
assertOnFailure = assertOnFailure_;
|
||||
resultsUpdated();
|
||||
|
||||
for (int i = 0; i < tests.size(); ++i)
|
||||
|
|
@ -119,9 +130,9 @@ void UnitTestRunner::runTests (const Array<UnitTest*>& tests, const bool assertO
|
|||
endTest();
|
||||
}
|
||||
|
||||
void UnitTestRunner::runAllTests (const bool assertOnFailure_)
|
||||
void UnitTestRunner::runAllTests()
|
||||
{
|
||||
runTests (UnitTest::getAllTests(), assertOnFailure_);
|
||||
runTests (UnitTest::getAllTests());
|
||||
}
|
||||
|
||||
void UnitTestRunner::logMessage (const String& message)
|
||||
|
|
@ -135,11 +146,11 @@ void UnitTestRunner::beginNewTest (UnitTest* const test, const String& subCatego
|
|||
currentTest = test;
|
||||
|
||||
TestResult* const r = new TestResult();
|
||||
results.add (r);
|
||||
r->unitTestName = test->getName();
|
||||
r->subcategoryName = subCategory;
|
||||
r->passes = 0;
|
||||
r->failures = 0;
|
||||
results.add (r);
|
||||
|
||||
logMessage ("-----------------------------------------------------------------");
|
||||
logMessage ("Starting test: " + r->unitTestName + " / " + subCategory + "...");
|
||||
|
|
@ -180,9 +191,12 @@ void UnitTestRunner::addPass()
|
|||
|
||||
r->passes++;
|
||||
|
||||
String message ("Test ");
|
||||
message << (r->failures + r->passes) << " passed";
|
||||
logMessage (message);
|
||||
if (logPasses)
|
||||
{
|
||||
String message ("Test ");
|
||||
message << (r->failures + r->passes) << " passed";
|
||||
logMessage (message);
|
||||
}
|
||||
}
|
||||
|
||||
resultsUpdated();
|
||||
|
|
|
|||
|
|
@ -198,12 +198,22 @@ public:
|
|||
The tests are performed in order, and the results are logged. To run all the
|
||||
registered UnitTest objects that exist, use runAllTests().
|
||||
*/
|
||||
void runTests (const Array<UnitTest*>& tests, bool assertOnFailure);
|
||||
void runTests (const Array<UnitTest*>& tests);
|
||||
|
||||
/** Runs all the UnitTest objects that currently exist.
|
||||
This calls runTests() for all the objects listed in UnitTest::getAllTests().
|
||||
*/
|
||||
void runAllTests (bool assertOnFailure);
|
||||
void runAllTests();
|
||||
|
||||
/** Sets a flag to indicate whether an assertion should be triggered if a test fails.
|
||||
This is true by default.
|
||||
*/
|
||||
void setAssertOnFailure (bool shouldAssert) noexcept;
|
||||
|
||||
/** Sets a flag to indicate whether successful tests should be logged.
|
||||
By default, this is set to false, so that only failures will be displayed in the log.
|
||||
*/
|
||||
void setPassesAreLogged (bool shouldDisplayPasses) noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** Contains the results of a test.
|
||||
|
|
@ -257,7 +267,7 @@ private:
|
|||
UnitTest* currentTest;
|
||||
String currentSubCategory;
|
||||
OwnedArray <TestResult, CriticalSection> results;
|
||||
bool assertOnFailure;
|
||||
bool assertOnFailure, logPasses;
|
||||
|
||||
void beginNewTest (UnitTest* test, const String& subCategory);
|
||||
void endTest();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue