Chebyshev
Unit testing for scientific software
Loading...
Searching...
No Matches
chebyshev::prec::prec_context Class Reference

Precision testing context, handling precision test cases. More...

#include <prec.h>

Public Member Functions

void setup (const std::string &moduleName, int argc=0, const char **argv=nullptr)
 Setup the precision testing module.
 
void terminate (bool exit=false)
 Terminate the precision testing module.
 
 prec_context (const std::string &moduleName, int argc, const char **argv)
 Construct a precision testing context.
 
 ~prec_context ()
 Destructor for the context, automatically terminates the module.
 
 prec_context (const prec_context &other)
 Custom copy constructor to avoid copying std::mutex.
 
prec_contextoperator= (const prec_context &other)
 Custom assignment operator to avoid copying std::mutex.
 
template<typename R , typename ... Args, typename Function1 = std::function<R(Args...)>, typename Function2 = Function1>
void estimate (const std::string &name, Function1 funcApprox, Function2 funcExpected, estimate_options< R, Args... > opt)
 Estimate error integrals over a function with respect to an exact function, with the given options.
 
template<typename R , typename ... Args, typename Function1 = std::function<R(Args...)>, typename Function2 = Function1>
void estimate (const std::string &name, Function1 funcApprox, Function2 funcExpected, std::vector< interval > domain, long double tolerance, unsigned int iterations, FailFunction fail, Estimator< R, Args... > estimator, bool quiet=false)
 Estimate error integrals over a function with respect to an exact function.
 
void estimate (const std::string &name, EndoFunction< double > funcApprox, EndoFunction< double > funcExpected, interval domain, long double tolerance=get_nan(), unsigned int iterations=0, FailFunction fail=fail::fail_on_max_err(), Estimator< double, double > estimator=estimator::quadrature1D< double >(), bool quiet=false)
 Estimate error integrals over a real function of real variable, with respect to an exact function.
 
template<typename Type , typename Identity = EndoFunction<Type>>
void identity (const std::string &name, Identity id, const estimate_options< Type, Type > &opt)
 Precision testing of an endofunction which is equivalent to the identity.
 
template<typename Type , typename Involution = EndoFunction<Type>>
void involution (const std::string &name, Involution invol, const estimate_options< Type, Type > &opt)
 Precision testing of an endofunction which is an involution.
 
template<typename Type , typename Involution = EndoFunction<Type>>
void idempotence (const std::string &name, Involution idem, const estimate_options< Type, Type > &opt)
 Precision testing of an endofunction which is idempotent.
 
template<typename InputType , typename OutputType = InputType, typename Homogeneous = std::function<OutputType(InputType)>>
void homogeneous (const std::string &name, Homogeneous hom, const estimate_options< InputType, OutputType > &opt, OutputType zero_element=OutputType(0.0))
 Precision testing of an function which is homogeneous over the domain.
 
template<typename Type = double>
void equals (const std::string &name, const Type &evaluated, const Type &expected, equation_options< Type > opt=equation_options< Type >())
 Test an equivalence up to a tolerance, with the given options (e.g.
 
template<typename Type = double>
void equals (const std::string &name, const Type &evaluated, const Type &expected, long double tolerance, DistanceFunction< Type > distance, bool quiet=false)
 Test an equivalence up to a tolerance, with the given options (e.g.
 
void equals (const std::string &name, long double evaluated, long double expected, long double tolerance=get_nan(), bool quiet=false)
 Test an equivalence up to a tolerance, with the given options (e.g.
 
template<typename Type >
void equals (const std::string &name, std::vector< std::array< Type, 2 > > values, long double tolerance=get_nan(), bool quiet=false)
 Evaluate multiple pairs of values for equivalence up to the given tolerance (e.g.
 
void wait_results ()
 Wait for all concurrent test cases to finish execution.
 
std::vector< estimate_resultget_estimate (const std::string &name)
 Get the results of error estimation by label.
 
estimate_result get_estimate (const std::string &name, unsigned int i)
 Get a single result of error estimation by label and index.
 
std::vector< equation_resultget_equation (const std::string &name)
 Get the results of equation testing by label.
 
equation_result get_equation (const std::string &name, unsigned int i)
 Get a single result of equation testing by label and index.
 

Public Attributes

prec_settings settings
 Settings for the precision testing context.
 
std::shared_ptr< output::output_contextoutput
 Output module settings for the context, dynamically allocated and possibly shared between multiple contexts.
 
std::shared_ptr< random::random_contextrandom
 Random module settings for the context, dynamically allocated and possibly shared between multiple contexts.
 

Detailed Description

Precision testing context, handling precision test cases.

Constructor & Destructor Documentation

◆ prec_context()

chebyshev::prec::prec_context::prec_context ( const std::string &  moduleName,
int  argc,
const char **  argv 
)
inline

Construct a precision testing context.

Parameters
moduleNameName of the module under test
argcNumber of command line arguments
argvList of command line arguments as C strings

Member Function Documentation

◆ equals() [1/4]

template<typename Type = double>
void chebyshev::prec::prec_context::equals ( const std::string &  name,
const Type evaluated,
const Type expected,
equation_options< Type opt = equation_options<Type>() 
)
inline

Test an equivalence up to a tolerance, with the given options (e.g.

for residual testing).

Parameters
nameThe name of the test case
evaluateThe evaluated value
expectedThe expected value
optThe options for the evaluation

◆ equals() [2/4]

template<typename Type = double>
void chebyshev::prec::prec_context::equals ( const std::string &  name,
const Type evaluated,
const Type expected,
long double  tolerance,
DistanceFunction< Type distance,
bool  quiet = false 
)
inline

Test an equivalence up to a tolerance, with the given options (e.g.

for residual testing).

Parameters
nameThe name of the test case
evaluateThe evaluated value
expectedThe expected value
distanceThe distance function to use
toleranceThe tolerance for the evaluation
quietWhether to output the result

◆ equals() [3/4]

void chebyshev::prec::prec_context::equals ( const std::string &  name,
long double  evaluated,
long double  expected,
long double  tolerance = get_nan(),
bool  quiet = false 
)
inline

Test an equivalence up to a tolerance, with the given options (e.g.

for residual testing).

Parameters
nameThe name of the test case
evaluateThe evaluated value
expectedThe expected value
toleranceThe tolerance for the evaluation
quietWhether to output the result

◆ equals() [4/4]

template<typename Type >
void chebyshev::prec::prec_context::equals ( const std::string &  name,
std::vector< std::array< Type, 2 > >  values,
long double  tolerance = get_nan(),
bool  quiet = false 
)
inline

Evaluate multiple pairs of values for equivalence up to the given tolerance (e.g.

for residual testing).

Parameters
nameThe name of the function or test case
valuesA list of values to equate
toleranceThe tolerance for the evaluation
quietWhether to output the result

◆ estimate() [1/3]

void chebyshev::prec::prec_context::estimate ( const std::string &  name,
EndoFunction< double funcApprox,
EndoFunction< double funcExpected,
interval  domain,
long double  tolerance = get_nan(),
unsigned int  iterations = 0,
FailFunction  fail = fail::fail_on_max_err(),
Estimator< double, double estimator = estimator::quadrature1D<double>(),
bool  quiet = false 
)
inline

Estimate error integrals over a real function of real variable, with respect to an exact function.

Parameters
nameThe name of the test case.
funcApproxThe approximation to test.
funcExpectedThe expected result.
intervalsThe (potentially multidimensional) domain of estimation.
iterationsThe number of function evaluations.
failThe fail function to determine whether the test failed (defaults to fail_on_max_err).
estimatorThe precision estimator to use (defaults to the trapezoid<double> estimator).
quietWhether to output the result.

◆ estimate() [2/3]

template<typename R , typename ... Args, typename Function1 = std::function<R(Args...)>, typename Function2 = Function1>
void chebyshev::prec::prec_context::estimate ( const std::string &  name,
Function1  funcApprox,
Function2  funcExpected,
estimate_options< R, Args... >  opt 
)
inline

Estimate error integrals over a function with respect to an exact function, with the given options.

Parameters
nameThe name of the test case
funcApproxThe approximation to test
funcExpectedThe expected result
optThe options for the estimation

◆ estimate() [3/3]

template<typename R , typename ... Args, typename Function1 = std::function<R(Args...)>, typename Function2 = Function1>
void chebyshev::prec::prec_context::estimate ( const std::string &  name,
Function1  funcApprox,
Function2  funcExpected,
std::vector< interval domain,
long double  tolerance,
unsigned int  iterations,
FailFunction  fail,
Estimator< R, Args... >  estimator,
bool  quiet = false 
)
inline

Estimate error integrals over a function with respect to an exact function.

Parameters
nameThe name of the test case.
funcApproxThe approximation to test.
funcExpectedThe expected result.
intervalsThe (potentially multidimensional) domain of estimation.
iterationsThe number of function evaluations.
failThe fail function to determine whether the test failed.
estimatorThe precision estimator to use.
quietWhether to output the result.

◆ get_estimate() [1/2]

std::vector< estimate_result > chebyshev::prec::prec_context::get_estimate ( const std::string &  name)
inline

Get the results of error estimation by label.

Note
This function waits for all previous test cases to end before returning, so it is advised to retrieve test results after all tests have been requested.

◆ get_estimate() [2/2]

estimate_result chebyshev::prec::prec_context::get_estimate ( const std::string &  name,
unsigned int  i 
)
inline

Get a single result of error estimation by label and index.

Note
This function waits for all previous test cases to end before returning, so it is advised to retrieve test results after all tests have been requested.

◆ homogeneous()

template<typename InputType , typename OutputType = InputType, typename Homogeneous = std::function<OutputType(InputType)>>
void chebyshev::prec::prec_context::homogeneous ( const std::string &  name,
Homogeneous  hom,
const estimate_options< InputType, OutputType > &  opt,
OutputType  zero_element = OutputType(0.0) 
)
inline

Precision testing of an function which is homogeneous over the domain.

The function is applied to input values and it is checked against zero. The zero value is constructed as OutputType(0.0), but may be specified as an additional argument.

Parameters
nameThe name of the test case.
homThe homogeneous function to test.
optThe options for estimation.
zero_elementThe zero element of type OutputType (defaults to OutputType(0.0)).

◆ idempotence()

template<typename Type , typename Involution = EndoFunction<Type>>
void chebyshev::prec::prec_context::idempotence ( const std::string &  name,
Involution  idem,
const estimate_options< Type, Type > &  opt 
)
inline

Precision testing of an endofunction which is idempotent.

The function is applied two times to input values and it is checked against itself.

Parameters
nameThe name of the test case.
idemThe idempotent function to test.
optThe options for estimation.

◆ identity()

template<typename Type , typename Identity = EndoFunction<Type>>
void chebyshev::prec::prec_context::identity ( const std::string &  name,
Identity  id,
const estimate_options< Type, Type > &  opt 
)
inline

Precision testing of an endofunction which is equivalent to the identity.

Parameters
nameThe name of the test case.
idThe identity function to test.
optThe options for estimation.

◆ involution()

template<typename Type , typename Involution = EndoFunction<Type>>
void chebyshev::prec::prec_context::involution ( const std::string &  name,
Involution  invol,
const estimate_options< Type, Type > &  opt 
)
inline

Precision testing of an endofunction which is an involution.

The function is applied two times to input values and it is checked against the identity.

Parameters
nameThe name of the test case.
involutionThe involution to test.
optThe options for estimation.

◆ setup()

void chebyshev::prec::prec_context::setup ( const std::string &  moduleName,
int  argc = 0,
const char **  argv = nullptr 
)
inline

Setup the precision testing module.

Parameters
moduleNameName of the module under test
argcNumber of command line arguments
argvList of command line arguments as C strings

◆ terminate()

void chebyshev::prec::prec_context::terminate ( bool  exit = false)
inline

Terminate the precision testing module.

Parameters
exitWhether to exit after finishing execution.

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