mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
UnitTest: added method expectWithinAbsoluteError for floating point comparisons.
This commit is contained in:
parent
74554a206c
commit
b4e1e68869
1 changed files with 21 additions and 0 deletions
|
|
@ -157,6 +157,27 @@ public:
|
|||
expect (result, failureMessage);
|
||||
}
|
||||
|
||||
/** Computes the difference between two values, and if it is larger than a
|
||||
specified value, prints out a message containing the expected and actual
|
||||
difference.
|
||||
*/
|
||||
template <class ValueType>
|
||||
void expectWithinAbsoluteError (ValueType actual, ValueType expected, ValueType maxAbsoluteError, String failureMessage = String())
|
||||
{
|
||||
const ValueType diff = std::abs (actual - expected);
|
||||
const bool result = diff <= maxAbsoluteError;
|
||||
|
||||
if (! result)
|
||||
{
|
||||
if (failureMessage.isNotEmpty())
|
||||
failureMessage << " -- ";
|
||||
|
||||
failureMessage << "Expected value: " << expected << ", Actual value: " << actual << " Max absolute error: " << maxAbsoluteError << " Actual difference: " << diff;
|
||||
}
|
||||
|
||||
expect (result, failureMessage);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/** Checks that the result of an expression does not throw an exception. */
|
||||
#define expectDoesNotThrow(expr) \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue