STORMM Source Documentation
Loading...
Searching...
No Matches
stormm::testing::Approx Class Reference

Class for handling comparisons of floating-point results versus expected values in unit tests. The general form is to take a vector of real numbers and apply the comparison across all entries. More...

#include <approx.h>

Public Member Functions

template<typename T>
 Approx (const std::vector< T > &values_in, ComparisonType style_in=ComparisonType::ABSOLUTE, double tol_in=1.0e-6)
 Constructors for real number comparisons based on a vector of multiple input values. Other floating point and integer vectors can be converted to double-precision vectors.
 
 ~Approx ()=default
 Default destructor.
 
int size () const
 Get the size of the collection of numbers in a real number comparison.
 
double getValue () const
 Get the expectation value, sans any tolerance.
 
std::vector< double > getValues () const
 Get all values of an approximate comparison, sans any tolerance.
 
ComparisonType getStyle () const
 Get the style used in this approximate comparison.
 
bool test (const double test_value) const
 Test whether a real-valued scalar is the same as the value held for comparison.
 
template<typename T>
bool test (const std::vector< T > &test_values) const
 Test whether a vector of real-valued scalars is the same as as vector held for comparison.
 
 Approx (double value_in, ComparisonType style_in=ComparisonType::ABSOLUTE, double tol_in=1.0e-6)
 Constructor for real number comparisons based on a single input value.
 
 Approx (double value_in, double tol_in, ComparisonType style_in=ComparisonType::ABSOLUTE)
 
double getMargin () const
 Get the margin or tolerance associated with this approximate comparison.
 
double getTolerance () const
 
double getTol () const
 
void setValue (double value_in)
 Set the values that form the basis of the approximate comparison.
 
void setValues (const std::vector< double > &values_in)
 
void setValue (double value_in, size_t index)
 
void setMargin (double dtol_in)
 Set the tolerance of the existing object. This will not emit a new object.
 
void setTolerance (double dtol_in)
 
void setTol (double dtol_in)
 
Approx margin (double dtol_in) const
 Set the tolerance. This is written in such a way as to mimic the Catch2 unit testing framework in some circumstances. It will not change the original object's tolerance, rather it will emit an object with the same comparison values and the desired tolerance.
 
Approx tolerance (double dtol_in) const
 
Approx tol (double dtol_in) const
 

Detailed Description

Class for handling comparisons of floating-point results versus expected values in unit tests. The general form is to take a vector of real numbers and apply the comparison across all entries.

Constructor & Destructor Documentation

◆ Approx() [1/2]

template<typename T>
stormm::testing::Approx::Approx ( const std::vector< T > & values_in,
ComparisonType style_in = ComparisonType::ABSOLUTE,
double tol_in = 1.0e-6 )

Constructors for real number comparisons based on a vector of multiple input values. Other floating point and integer vectors can be converted to double-precision vectors.

Parameters
values_inThe value for comparison
style_inType of comparison, relative or absolute
tol_inTolerance for deviations that will still yield a correct comparison

◆ Approx() [2/2]

stormm::testing::Approx::Approx ( double value_in,
ComparisonType style_in = ComparisonType::ABSOLUTE,
double tol_in = 1.0e-6 )

Constructor for real number comparisons based on a single input value.

Overloaded:

  • Take the comparison style ahead of the tolerance (convenient use of default tolerance)
  • Take the tolerance ahead of the comparison style (tolerance must be specified)
Parameters
value_inThe value for comparison
style_inThe type of comparison, relative or absolute
tol_inTolerance for deviations that will still yield a correct comparison

Member Function Documentation

◆ margin()

Approx stormm::testing::Approx::margin ( double dtol_in) const

Set the tolerance. This is written in such a way as to mimic the Catch2 unit testing framework in some circumstances. It will not change the original object's tolerance, rather it will emit an object with the same comparison values and the desired tolerance.

Overloaded:

  • Three different names that individual developers may find most intuitive
Parameters
dtol_inThe tolerance to use

◆ setMargin()

void stormm::testing::Approx::setMargin ( double dtol_in)

Set the tolerance of the existing object. This will not emit a new object.

Overloaded:

  • Three different names that individual developers may find most intuitive
Parameters
dtol_inThe tolerance to use

◆ setValue()

void stormm::testing::Approx::setValue ( double value_in)

Set the values that form the basis of the approximate comparison.

Overloaded:

  • Set the approximation to use a single value
  • Set the target value of a particular index
  • Set the approximation to use multiple values
Parameters
value_inThe single value to set (this will change the length of the comparison vector to one)
values_inThe vector of values to set
indexIndex of the value to change (this will be checked against the length of comparison values in the existing object)

◆ test() [1/2]

bool stormm::testing::Approx::test ( const double test_value) const

Test whether a real-valued scalar is the same as the value held for comparison.

Parameters
test_valueThe scalar value to test

◆ test() [2/2]

template<typename T>
bool stormm::testing::Approx::test ( const std::vector< T > & test_values) const

Test whether a vector of real-valued scalars is the same as as vector held for comparison.

Parameters
test_valuesThe vector of values to test

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