Ocean
Loading...
Searching...
No Matches
Ocean::Test::ValidationPrecision Class Reference

This class implements a helper class to validate the precision of algorithms or objects across multiple iterations. More...

#include <ValidationPrecision.h>

Inheritance diagram for Ocean::Test::ValidationPrecision:

Data Structures

class  ScopedIteration
 Creates a new scoped iteration representing one iteration in a precision test. More...
 

Public Member Functions

 ValidationPrecision (const double threshold, const unsigned int minimumIterations=1u)
 Creates a new precision-based validation object with specified threshold.
 
 ValidationPrecision (const double threshold, RandomGenerator &randomGenerator, const unsigned int minimumIterations=1u)
 Creates a new validation object associated with a random generator, by default the verified has succeeded.
 
void addIteration (const bool accurate)
 Explicitly adds a new iteration which is either accurate or not.
 
void addIterations (const size_t accurateIterations, const size_t iterations)
 Explicitly adds new iterations for which the amount of accurate iterations is known.
 
uint64_t iterations () const
 Returns the number of iterations in which the precision has been determined.
 
uint64_t necessaryIterations () const
 Returns the necessary iterations to allow determining success or failure based on the specified success threshold.
 
bool needMoreIterations () const
 Returns whether the number of iterations is not yet sufficient to determine a success or failure.
 
bool succeeded () const override
 Returns if this validation has succeeded.
 
double accuracy () const
 Returns the accuracy of all iterations.
 
double threshold () const
 Returns the defined threshold.
 
bool hasSetFailed () const
 Returns whether this validation object has been set to failed explicitly.
 
- Public Member Functions inherited from Ocean::Test::Validation
 Validation ()=default
 Default constructor, by default the validation has succeeded.
 
 Validation (RandomGenerator &randomGenerator)
 Creates a new validation object associated with a random generator, by default the validation has succeeded.
 
virtual ~Validation ()
 Destructs this validation object.
 
void expectTrue (const bool value)
 Informs this validation object that a value is expected to be True.
 
void expectTrue (const bool value, const char *file, const int line)
 Informs this validation object that a value is expected to be True.
 
void expectFalse (const bool value)
 Informs this validation object that a value is expected to be False.
 
void expectFalse (const bool value, const char *file, const int line)
 Informs this validation object that a value is expected to be False.
 
template<typename T >
void expectEqual (const T &value0, const T &value1)
 Informs this validation object that a value is expected to be equal to another value.
 
template<typename T >
void expectEqual (const T &value0, const T &value1, const char *file, const int line)
 Informs this validation object that a value is expected to be equal to another value.
 
template<typename T >
void expectNotEqual (const T &value0, const T &value1)
 Informs this validation object that a value is expected to be not equal to another value.
 
template<typename T >
void expectNotEqual (const T &value0, const T &value1, const char *file, const int line)
 Informs this validation object that a value is expected to be not equal to another value.
 
template<typename T >
void expectLess (const T &value0, const T &value1)
 Informs this validation object that a value is expected to be less than another value.
 
template<typename T >
void expectLess (const T &value0, const T &value1, const char *file, const int line)
 Informs this validation object that a value is expected to be less than another value.
 
template<typename T >
void expectLessEqual (const T &value0, const T &value1)
 Informs this validation object that a value is expected to be less than or equal to another value.
 
template<typename T >
void expectLessEqual (const T &value0, const T &value1, const char *file, const int line)
 Informs this validation object that a value is expected to be less than or equal to another value.
 
template<typename T >
void expectGreater (const T &value0, const T &value1)
 Informs this validation object that a value is expected to be greater than another value.
 
template<typename T >
void expectGreater (const T &value0, const T &value1, const char *file, const int line)
 Informs this validation object that a value is expected to be greater than another value.
 
template<typename T >
void expectGreaterEqual (const T &value0, const T &value1)
 Informs this validation object that a value is expected to be greater than or equal to another value.
 
template<typename T >
void expectGreaterEqual (const T &value0, const T &value1, const char *file, const int line)
 Informs this validation object that a value is expected to be greater than or equal to another value.
 
template<typename T >
void expectInsideRange (const T &lower, const T &value, const T &upper)
 Informs this validation object that a value is expected to be inside a range.
 
template<typename T >
void expectInsideRange (const T &lower, const T &value, const T &upper, const char *file, const int line)
 Informs this validation object that a value is expected to be inside a range.
 
void setFailed ()
 Explicitly sets the validation to be failed.
 
void setFailed (const char *file, const int line)
 Explicitly sets the validation to be failed.
 
bool succeededSoFar () const
 Returns whether this validation has succeeded so far.
 
std::string randomGeneratorOutput () const
 Returns a string containing the random generator's initial seed, if any.
 

Protected Attributes

double threshold_ = 1.0
 The necessary percent of accurate iterations necessary for a successful verification, with range (0, 1].
 
uint64_t necessaryIterations_ = 0ull
 The number of iterations needed to determine success or failure.
 
uint64_t iterations_ = 0ull
 The overall number of iterations which have been added.
 
uint64_t accurateIterations_ = 0ull
 The number of iterations which were precise enough, with range [0, iterations_].
 
- Protected Attributes inherited from Ocean::Test::Validation
bool succeeded_ = true
 True, if the validation has succeeded; False, if the validation has failed.
 
RandomGeneratorrandomGenerator_ = nullptr
 Optional random generator object which will be used during validation.
 
bool succeededChecked_ = false
 True, if the success state of this validation has been checked.
 

Additional Inherited Members

- Protected Member Functions inherited from Ocean::Test::Validation
 Validation (const Validation &)=delete
 Disabled copy constructor.
 
void setSucceededFalse ()
 Sets the succeeded state to false.
 

Detailed Description

This class implements a helper class to validate the precision of algorithms or objects across multiple iterations.

The main purpose is to allow a configurable percentage of iterations to be imprecise while still considering the overall test as successful. This class inherits from Validation and extends it with precision-based validation capabilities. As this class inherits from Validation, the entire validation can also be invalidated using base class methods (e.g., OCEAN_EXPECT_TRUE, OCEAN_SET_FAILED) for errors unrelated to precision.

See also
Validation, ScopedIteration.

Constructor & Destructor Documentation

◆ ValidationPrecision() [1/2]

Ocean::Test::ValidationPrecision::ValidationPrecision ( const double  threshold,
const unsigned int  minimumIterations = 1u 
)
inlineexplicit

Creates a new precision-based validation object with specified threshold.

Parameters
thresholdThe necessary percent of accurate iterations necessary for a successful verification, with range (0, 1]
minimumIterationsThe minimum number of iterations necessary for a successful verification, with range [1, infinity)

◆ ValidationPrecision() [2/2]

Ocean::Test::ValidationPrecision::ValidationPrecision ( const double  threshold,
RandomGenerator randomGenerator,
const unsigned int  minimumIterations = 1u 
)
inline

Creates a new validation object associated with a random generator, by default the verified has succeeded.

Parameters
thresholdThe necessary percent of accurate iterations necessary for a successful verification, with range (0, 1]
randomGeneratorThe random generator which will be used during verification

Member Function Documentation

◆ accuracy()

double Ocean::Test::ValidationPrecision::accuracy ( ) const
inline

Returns the accuracy of all iterations.

Beware: Ensure that at least one iteration has been added.

Returns
The validation's accuracy, in percent, with range [0, 1]

◆ addIteration()

void Ocean::Test::ValidationPrecision::addIteration ( const bool  accurate)
inline

Explicitly adds a new iteration which is either accurate or not.

Parameters
accurateTrue, if the iteration was precise enough; False, if the iteration was not precise enough
See also
ScopedIteration.

◆ addIterations()

void Ocean::Test::ValidationPrecision::addIterations ( const size_t  accurateIterations,
const size_t  iterations 
)
inline

Explicitly adds new iterations for which the amount of accurate iterations is known.

Parameters
accurateIterationsThe number of accurate iterations, with range [0, iterations]
iterationsThe number of new iterations, with range [1, infinity)
See also
ScopedIteration.

◆ hasSetFailed()

bool Ocean::Test::ValidationPrecision::hasSetFailed ( ) const
inline

Returns whether this validation object has been set to failed explicitly.

This function is intended for internal use only, use succeeded() instead.

Returns
True, if so
See also
succeeded().

◆ iterations()

uint64_t Ocean::Test::ValidationPrecision::iterations ( ) const
inline

Returns the number of iterations in which the precision has been determined.

Returns
The number of iterations, with range [0, infinity)

◆ necessaryIterations()

uint64_t Ocean::Test::ValidationPrecision::necessaryIterations ( ) const
inline

Returns the necessary iterations to allow determining success or failure based on the specified success threshold.

Returns
The number of necessary iterations, with range [1, infinity)

◆ needMoreIterations()

bool Ocean::Test::ValidationPrecision::needMoreIterations ( ) const
inline

Returns whether the number of iterations is not yet sufficient to determine a success or failure.

Returns
True, if more iterations are required

◆ succeeded()

bool Ocean::Test::ValidationPrecision::succeeded ( ) const
inlineoverridevirtual

Returns if this validation has succeeded.

Returns
True, if so; False, if the validation has failed

Reimplemented from Ocean::Test::Validation.

◆ threshold()

double Ocean::Test::ValidationPrecision::threshold ( ) const
inline

Returns the defined threshold.

Returns
The validation object's precision threshold, with range [0, 1]

Field Documentation

◆ accurateIterations_

uint64_t Ocean::Test::ValidationPrecision::accurateIterations_ = 0ull
protected

The number of iterations which were precise enough, with range [0, iterations_].

◆ iterations_

uint64_t Ocean::Test::ValidationPrecision::iterations_ = 0ull
protected

The overall number of iterations which have been added.

◆ necessaryIterations_

uint64_t Ocean::Test::ValidationPrecision::necessaryIterations_ = 0ull
protected

The number of iterations needed to determine success or failure.

◆ threshold_

double Ocean::Test::ValidationPrecision::threshold_ = 1.0
protected

The necessary percent of accurate iterations necessary for a successful verification, with range (0, 1].


The documentation for this class was generated from the following file: