8 #ifndef META_OCEAN_TEST_VALIDATION_PRECISION_H
9 #define META_OCEAN_TEST_VALIDATION_PRECISION_H
65 inline void setInaccurate(
const T& expected,
const T& actual,
const char* file,
const int line);
143 inline void setFailed(
const char* file,
const int line);
167 [[nodiscard]]
inline bool succeeded()
const;
174 [[nodiscard]]
inline double accuracy()
const;
234 #ifndef OCEAN_SET_INACCURATE
235 #define OCEAN_SET_INACCURATE(scopedIteration, expected, actual) scopedIteration.setInaccurate(expected, actual, __FILE__, __LINE__);
246 validationPrecision_.addIteration(accurate_);
254 template <
typename T>
259 ocean_assert(file !=
nullptr);
262 Log::error() <<
"ScopedIteration::setInaccurate() in '" << file <<
"', in line " << line <<
": expected " << expected <<
", got " << actual << validationPrecision_.randomGeneratorOutput();
275 ocean_assert(failureRate > 0.0);
277 const double idealIterations = 1.0 / failureRate;
279 ocean_assert(idealIterations <= 1000000000u);
280 necessaryIterations_ = std::max(minimumIterations, (
unsigned int)(std::ceil(idealIterations) * 2.0));
297 ocean_assert(
succeededChecked_ &&
"The verifier has not been check for success");
313 ocean_assert(accurateIterations <=
iterations);
334 ocean_assert(file !=
nullptr);
337 #ifdef OCEAN_USE_GTEST
338 std::cerr <<
"\nValidationPrecision::setFailed() in '" << file <<
"', in line " << line <<
randomGeneratorOutput() <<
"\n" << std::endl;
372 if (threshold_ <= 0.0 || threshold_ > 1.0)
381 #ifdef OCEAN_USE_GTEST
387 stream <<
"Not enough iterations for the specified success threshold (executed " <<
iterations_ <<
" of " <<
necessaryIterations_ <<
" necessary iterations)\n";
410 ocean_assert(percent >= 0.0 && percent <= 1.0);
432 return std::string();
461 template <
bool tActive>
464 if (validation.hasSetFailed())
466 messageObject <<
"FAILED!" << validation.randomGeneratorOutput();
470 if (validation.accuracy() < validation.threshold())
472 messageObject <<
"FAILED with only " <<
String::toAString(validation.accuracy() * 100.0, 1u) <<
"%, threshold is " <<
String::toAString(validation.threshold() * 100.0, 1u) <<
"%" << validation.randomGeneratorOutput();
476 messageObject <<
String::toAString(validation.accuracy() * 100.0, 1u) <<
"% succeeded.";
480 return messageObject;
483 template <
bool tActive>
484 MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const ValidationPrecision& validation)
486 if (validation.hasSetFailed())
488 messageObject <<
"FAILED!" << validation.randomGeneratorOutput();
492 if (validation.accuracy() < validation.threshold())
494 messageObject <<
"FAILED with only " <<
String::toAString(validation.accuracy() * 100.0, 1u) <<
"%, threshold is " <<
String::toAString(validation.threshold() * 100.0, 1u) <<
"%" << validation.randomGeneratorOutput();
498 messageObject <<
String::toAString(validation.accuracy() * 100.0, 1u) <<
"% succeeded.";
502 return messageObject;
static MessageObject error()
Returns the message for error messages.
Definition: Messenger.h:1074
Messenger object, one object for each message.
Definition: Messenger.h:427
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
unsigned int initialSeed() const
Returns the initial seed value which was used to initialize this random generator.
Definition: RandomGenerator.h:178
static std::string toAString(const char value)
Converts a value to a string with 8bit character.
Creates a new scoped iteration.
Definition: ValidationPrecision.h:37
ScopedIteration(const ScopedIteration &&)=delete
Disabled move constructor.
void setInaccurate()
Sets this iteration to be not precise enough.
Definition: ValidationPrecision.h:249
ValidationPrecision & validationPrecision_
The owner of this scoped object.
Definition: ValidationPrecision.h:90
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:87
~ScopedIteration()
Destructs this scoped object and forwards the information to the owning validation.
Definition: ValidationPrecision.h:244
ScopedIteration()=delete
Disabled default constructor.
This class implements a helper class to validate the accuracy of tests.
Definition: ValidationPrecision.h:28
double threshold() const
Returns the defined threshold.
Definition: ValidationPrecision.h:415
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:311
uint64_t iterations_
The overall number of iterations which have been added.
Definition: ValidationPrecision.h:220
ValidationPrecision(const double threshold, const unsigned int minimumIterations=1u)
Creates a new precision-based validation object with specified threshold.
Definition: ValidationPrecision.h:266
RandomGenerator * randomGenerator_
Optional random generator object which will be used during validation.
Definition: ValidationPrecision.h:226
uint64_t accurateIterations_
The number of iterations which were precise enough, with range [0, iterations_].
Definition: ValidationPrecision.h:223
std::string randomGeneratorOutput() const
Returns a string containing the random generator's initial seed, if any.
Definition: ValidationPrecision.h:425
bool needMoreIterations() const
Returns whether the number of iterations is not yet sufficient to determine a success or failure.
Definition: ValidationPrecision.h:357
bool succeeded_
True, if the validation has succeeded; False, if the validation has failed.
Definition: ValidationPrecision.h:214
double accuracy() const
Returns the accuracy of all iterations.
Definition: ValidationPrecision.h:398
void setSucceededFalse()
Sets the succeeded state to false.
Definition: ValidationPrecision.h:435
void addIteration(const bool accurate)
Explicitly adds a new iteration which is either accurate or not.
Definition: ValidationPrecision.h:301
~ValidationPrecision()
Destructs this validation object.
Definition: ValidationPrecision.h:294
ValidationPrecision(const ValidationPrecision &)=delete
Disabled copy constructor.
uint64_t necessaryIterations() const
Returns the necessary iterations to allow determining success or failure based on the specified succe...
Definition: ValidationPrecision.h:350
bool succeeded() const
Returns if this validation has succeeded.
Definition: ValidationPrecision.h:364
double threshold_
The necessary percent of accurate iterations necessary for a successful verification,...
Definition: ValidationPrecision.h:211
uint64_t iterations() const
Returns the number of iterations in which the precision has been determined.
Definition: ValidationPrecision.h:345
bool succeededChecked_
True, if the success state of this validation has been checked.
Definition: ValidationPrecision.h:230
uint64_t necessaryIterations_
The number of iterations needed to determine success or failure.
Definition: ValidationPrecision.h:217
bool hasSetFailed() const
Returns whether this validation object has been set to failed explicitly.
Definition: ValidationPrecision.h:420
void setFailed()
Explicitly sets the validation to be failed.
Definition: ValidationPrecision.h:325
std::ostream & operator<<(std::ostream &stream, const Validation &validation)
Definition: Validation.h:824
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15