8#ifndef META_OCEAN_TEST_VALIDATION_PRECISION_H
9#define META_OCEAN_TEST_VALIDATION_PRECISION_H
69 inline void setInaccurate(
const T& expected,
const T& actual,
const char* file,
const int line);
150 [[nodiscard]]
inline bool succeeded()
const override;
157 [[nodiscard]]
inline double accuracy()
const;
188#ifndef OCEAN_SET_INACCURATE
189 #define OCEAN_SET_INACCURATE(scopedIteration, ...) scopedIteration.setInaccurate(__VA_ARGS__, __FILE__, __LINE__);
200 validationPrecision_.addIteration(accurate_);
213 ocean_assert(file !=
nullptr);
216 Log::error() <<
"ScopedIteration::setInaccurate() in '" << file <<
"', in line " << line <<
": expected " << expected <<
", got " << actual << validationPrecision_.randomGeneratorOutput();
229 ocean_assert(failureRate > 0.0);
231 const double idealIterations = 1.0 / failureRate;
233 ocean_assert(idealIterations <= 1000000000u);
234 necessaryIterations_ = std::max(minimumIterations, (
unsigned int)(std::ceil(idealIterations) * 2.0));
252 ocean_assert(failureRate > 0.0);
254 const double idealIterations = 1.0 / failureRate;
256 ocean_assert(idealIterations <= 1000000000u);
257 necessaryIterations_ = std::max(minimumIterations, (
unsigned int)(std::ceil(idealIterations) * 2.0));
277 ocean_assert(accurateIterations <=
iterations);
316 if (threshold_ <= 0.0 || threshold_ > 1.0)
325#ifdef OCEAN_USE_GTEST
331 stream <<
"Not enough iterations for the specified success threshold (executed " <<
iterations_ <<
" of " <<
necessaryIterations_ <<
" necessary iterations)\n";
354 ocean_assert(percent >= 0.0 && percent <= 1.0);
390template <
bool tActive>
393 if (validation.hasSetFailed())
395 messageObject <<
"FAILED!" << validation.randomGeneratorOutput();
399 if (validation.accuracy() < validation.threshold())
401 messageObject <<
"FAILED with only " <<
String::toAString(validation.accuracy() * 100.0, 1u) <<
"%, threshold is " <<
String::toAString(validation.threshold() * 100.0, 1u) <<
"%" << validation.randomGeneratorOutput();
405 messageObject <<
String::toAString(validation.accuracy() * 100.0, 1u) <<
"% succeeded.";
409 return messageObject;
412template <
bool tActive>
413MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const ValidationPrecision& validation)
415 if (validation.hasSetFailed())
417 messageObject <<
"FAILED!" << validation.randomGeneratorOutput();
421 if (validation.accuracy() < validation.threshold())
423 messageObject <<
"FAILED with only " <<
String::toAString(validation.accuracy() * 100.0, 1u) <<
"%, threshold is " <<
String::toAString(validation.threshold() * 100.0, 1u) <<
"%" << validation.randomGeneratorOutput();
427 messageObject <<
String::toAString(validation.accuracy() * 100.0, 1u) <<
"% succeeded.";
431 return messageObject;
static MessageObject error()
Returns the message for error messages.
Definition Messenger.h:1095
Messenger object, one object for each message.
Definition Messenger.h:448
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
static std::string toAString(const char value)
Converts a value to a string with 8bit character.
This class implements a helper class to validate tests.
Definition Validation.h:105
bool succeededChecked_
True, if the success state of this validation has been checked.
Definition Validation.h:397
void setSucceededFalse()
Sets the succeeded state to false.
Definition Validation.h:913
std::string randomGeneratorOutput() const
Returns a string containing the random generator's initial seed, if any.
Definition Validation.h:903
bool succeeded_
True, if the validation has succeeded; False, if the validation has failed.
Definition Validation.h:390
Creates a new scoped iteration representing one iteration in a precision test.
Definition ValidationPrecision.h:41
ScopedIteration(const ScopedIteration &&)=delete
Disabled move constructor.
void setInaccurate()
Sets this iteration to be not precise enough.
Definition ValidationPrecision.h:203
ValidationPrecision & validationPrecision_
The owner of this scoped object.
Definition ValidationPrecision.h:94
ScopedIteration(const ScopedIteration &)=delete
Disabled copy constructor.
bool accurate_
True, if the iteration is accurate; False, if the iteration was not accurate enough.
Definition ValidationPrecision.h:91
~ScopedIteration()
Destructs this scoped object and forwards the information to the owning validation.
Definition ValidationPrecision.h:198
ScopedIteration()=delete
Disabled default constructor.
This class implements a helper class to validate the precision of algorithms or objects across multip...
Definition ValidationPrecision.h:33
double threshold() const
Returns the defined threshold.
Definition ValidationPrecision.h:359
void addIterations(const size_t accurateIterations, const size_t iterations)
Explicitly adds new iterations for which the amount of accurate iterations is known.
Definition ValidationPrecision.h:275
uint64_t iterations_
The overall number of iterations which have been added.
Definition ValidationPrecision.h:182
ValidationPrecision(const double threshold, const unsigned int minimumIterations=1u)
Creates a new precision-based validation object with specified threshold.
Definition ValidationPrecision.h:220
uint64_t accurateIterations_
The number of iterations which were precise enough, with range [0, iterations_].
Definition ValidationPrecision.h:185
bool needMoreIterations() const
Returns whether the number of iterations is not yet sufficient to determine a success or failure.
Definition ValidationPrecision.h:301
double accuracy() const
Returns the accuracy of all iterations.
Definition ValidationPrecision.h:342
void addIteration(const bool accurate)
Explicitly adds a new iteration which is either accurate or not.
Definition ValidationPrecision.h:265
bool succeeded() const override
Returns if this validation has succeeded.
Definition ValidationPrecision.h:308
uint64_t necessaryIterations() const
Returns the necessary iterations to allow determining success or failure based on the specified succe...
Definition ValidationPrecision.h:294
double threshold_
The necessary percent of accurate iterations necessary for a successful verification,...
Definition ValidationPrecision.h:176
uint64_t iterations() const
Returns the number of iterations in which the precision has been determined.
Definition ValidationPrecision.h:289
uint64_t necessaryIterations_
The number of iterations needed to determine success or failure.
Definition ValidationPrecision.h:179
bool hasSetFailed() const
Returns whether this validation object has been set to failed explicitly.
Definition ValidationPrecision.h:364
std::ostream & operator<<(std::ostream &stream, const TestResult &testResult)
Writes a test result to a stream.
Definition TestResult.h:200
The namespace covering the entire Ocean framework.
Definition Accessor.h:15