STIR 6.5.0

A base class for making test classes. More...

#include "stir/RunTests.h"

Inherited by stir::IOTests< DiscretisedDensity< 3, float > >, stir::IOTests< DynamicDiscretisedDensity >, stir::IOTests< ParametricVoxelsOnCartesianGrid >, stir::ObjectiveFunctionTests< GeneralisedPrior< DiscretisedDensity< 3, float > >, DiscretisedDensity< 3, float > >, stir::ObjectiveFunctionTests< PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBin< DiscretisedDensity< 3, float > >, DiscretisedDensity< 3, float > >, stir::ObjectiveFunctionTests< PoissonLogLikelihoodWithLinearModelForMeanAndProjData< DiscretisedDensity< 3, float > >, DiscretisedDensity< 3, float > >, stir::ReconstructionTests< target_type >, stir::ArcCorrectionTests, stir::ArrayFilterTests, stir::ArrayTests, stir::BSpline::BSplinesRegularGrid1D_Tests, stir::BSpline::BSplinesRegularGrid_Tests, stir::BSpline::BSplines_Tests, stir::BlocksTests, stir::ByteOrderTests, stir::CUDACXXTests, stir::DataSymmetriesForBins_PET_CartesianGridTests, stir::DateTimeTest, stir::DetectionPosMapTests, stir::DetectionPosition_Tests, , , stir::FilenameTests, stir::FourierTests, , stir::GeneralisedPoissonNoiseGeneratorTests, stir::GeometryBlocksOnCylindricalTests, stir::IOTests< A >, stir::IOTests_ITKMulticomponent, stir::IR_filterTests, stir::ImagingModalityTests, stir::IndexRange_Tests, , stir::KeyParserTests, , stir::ML_normTests, stir::MatrixTests, stir::MultipleProjDataTests, stir::NestedIteratorTests, stir::ObjectiveFunctionTests< ObjectiveFunctionT, TargetT >, stir::OutputFileFormatTests, , , stir::ProjDataInMemoryTests, stir::ProjDataInMemoryTests, stir::ProjDataInfoTests, stir::ProjDataTests, stir::ProjMatrixByBinUsingInterpolationTests, stir::QuaternionTests, stir::ROITests, stir::RadionuclideTest, stir::ReconstructionTests< TargetT >, stir::RigidObject3DTransformationTests, stir::ScannerTests, stir::ScatterSimulationTests, stir::SeparableGaussianArrayFilterTests, stir::SeparableMetzArrayFilterTests, stir::TOF_Tests, stir::TestBSplineTransformation, stir::TestDataProcessorProjectors, stir::TestGPUProjectors, stir::TestProjDataInfoSubsets, stir::TestProjDataInfoSubsetsSPECTUB, stir::VectorWithOffsetTests, stir::VoxelsOnCartesianGridTests, stir::convert_array_Tests, stir::coordinateTests, stir::erfTests, and stir::find_fwhm_in_imageTests.

Public Member Functions

 RunTests (const double tolerance=1E-4)
 Default constructor.
virtual ~RunTests ()
 Destructor, outputs a diagnostic message.
virtual void run_tests ()=0
 Function (to be overloaded) which does the actual tests.
bool is_everything_ok () const
 Returns if all checks were fine upto now.
int main_return_value () const
 Handy return value for a main() function.
void set_tolerance (const double tolerance)
 Set value used in floating point comparisons (see check_* functions).
double get_tolerance () const
 Get value used in floating point comparisons (see check_* functions).
bool check (const bool, const std::string &str="")
 Tests if true, str can be used to tell what you are testing.
Test equality

float/double/complex numbers are compared using tolerance.

See also
check()
bool check_if_equal (const std::string &a, const std::string &b, const std::string &str="")
bool check_if_equal (const double a, const double b, const std::string &str="")
bool check_if_equal (const short a, const short b, const std::string &str="")
bool check_if_equal (const unsigned short a, const unsigned short b, const std::string &str="")
bool check_if_equal (const int a, const int b, const std::string &str="")
bool check_if_equal (const unsigned int a, const unsigned int b, const std::string &str="")
bool check_if_equal (const long a, const long b, const std::string &str="")
bool check_if_equal (const unsigned long a, const unsigned long b, const std::string &str="")
bool check_if_equal (const Bin &a, const Bin &b, const std::string &str="")
template<class T>
bool check_if_equal (const DetectionPosition< T > &a, const DetectionPosition< T > &b, const std::string &str="")
template<class T>
bool check_if_equal (const DetectionPositionPair< T > &a, const DetectionPositionPair< T > &b, const std::string &str="")
template<class T>
bool check_if_equal (const LORInAxialAndNoArcCorrSinogramCoordinates< T > &a, const LORInAxialAndNoArcCorrSinogramCoordinates< T > &b, const std::string &str="")
template<class T>
bool check_if_equal (const std::complex< T > a, const std::complex< T > b, const std::string &str="")
 check equality by calling check_if_equal on real and imaginary parts
template<class T>
bool check_if_equal (const VectorWithOffset< T > &t1, const VectorWithOffset< T > &t2, const std::string &str="")
 check equality by comparing ranges and calling check_if_equal on all elements
template<class T>
bool check_if_equal (const std::vector< T > &t1, const std::vector< T > &t2, const std::string &str="")
 check equality by comparing size and calling check_if_equal on all elements
bool check_if_equal (const ProjDataInMemory &t1, const ProjDataInMemory &t2, const std::string &str="")
template<int n>
bool check_if_equal (const IndexRange< n > &t1, const IndexRange< n > &t2, const std::string &str="")
template<int num_dimensions, class coordT>
bool check_if_equal (const BasicCoordinate< num_dimensions, coordT > &a, const BasicCoordinate< num_dimensions, coordT > &b, const std::string &str="")
 check equality by comparing norm(a-b) with tolerance

Test if a value is zero

float/double/complex numbers are compared using tolerance.

See also
check()
double tolerance
 tolerance for comparisons with real values
bool everything_ok
 variable storing current status
bool check_if_zero (const double a, const std::string &str="")
bool check_if_zero (const short a, const std::string &str="")
bool check_if_zero (const unsigned short a, const std::string &str="")
bool check_if_zero (const int a, const std::string &str="")
bool check_if_zero (const unsigned int a, const std::string &str="")
bool check_if_zero (const long a, const std::string &str="")
bool check_if_zero (const unsigned long a, const std::string &str="")
template<class T>
bool check_if_zero (const VectorWithOffset< T > &t, const std::string &str="")
 use check_if_zero on all elements
template<int num_dimensions, class coordT>
bool check_if_zero (const BasicCoordinate< num_dimensions, coordT > &a, const std::string &str="")
 compare norm with tolerance
template<class T1, class T2>
bool check_if_less (T1 a, T2 b, const std::string &str="")
 check if a<b
template<class T>
bool check_if_equal_generic (const T &a, const T &b, const std::string &str)
 function that is called by some check_if_equal implementations. It just uses operator!=
template<class T>
bool check_if_zero_generic (T a, const std::string &str)
 function that is called by some check_if_zero implementations. It just uses operator!=

Detailed Description

A base class for making test classes.

With a derived class, an application could look like

int main(int argc, char **argv, char **env)
{
SomeTests tests(argc,argv,env);
tests.run_tests();
return tests.main_return_value();
}
Implementation notes

At present, the various check* functions are overloaded on most basic types, and in some STIR specific types such as VectorWithOffset. This creates problems when the arguments are not exactly of one of those types, as then the compilation might break.

A potential solution for this would be to use member templates and the addition of a 'generic' function as a template. However, then that function would take precedence for other cases which are currently resolved by overloading (such as when using stir::Array which is currently handled via stir::VectorWithOffset).

In summary, if you need to check a different type that's not provided for, either use check(), add an appropriate function to your derived class, or if useful for other cases to this class of course.

Constructor & Destructor Documentation

◆ RunTests()

stir::RunTests::RunTests ( const double tolerance = 1E-4)
explicit

Default constructor.

References everything_ok, RunTests(), and tolerance.

Referenced by RunTests().

◆ ~RunTests()

stir::RunTests::~RunTests ( )
virtual

Destructor, outputs a diagnostic message.

References everything_ok.

Member Function Documentation

◆ run_tests()

virtual void stir::RunTests::run_tests ( )
pure virtual

Function (to be overloaded) which does the actual tests.

This function is expected to do a series of calls to check(), check_if_equal() etc.

Implemented in stir::ArcCorrectionTests, stir::ArrayFilterTests, stir::ArrayTests, stir::BlocksTests, stir::BSpline::BSplines_Tests, stir::BSpline::BSplinesRegularGrid1D_Tests, stir::BSpline::BSplinesRegularGrid_Tests, stir::ByteOrderTests, stir::convert_array_Tests, stir::coordinateTests, stir::CUDACXXTests, stir::DataSymmetriesForBins_PET_CartesianGridTests, stir::DateTimeTest, stir::DetectionPosition_Tests, stir::DetectionPosMapTests, stir::erfTests, stir::FilenameTests, stir::find_fwhm_in_imageTests, stir::FourierTests, stir::GeneralisedPoissonNoiseGeneratorTests, stir::GeometryBlocksOnCylindricalTests, stir::ImagingModalityTests, stir::IndexRange_Tests, stir::integrate_discrete_functionTests, stir::IOTests< A >, stir::IOTests< DiscretisedDensity< 3, float > >, stir::IOTests< DynamicDiscretisedDensity >, stir::IOTests< ParametricVoxelsOnCartesianGrid >, stir::IOTests_ITKMulticomponent, stir::IR_filterTests, stir::KeyParserTests, stir::linear_regressionTests, stir::LogCoshPriorTests, stir::MatrixTests, stir::ML_normTests, stir::modellingTests, stir::MultipleProjDataTests, stir::NestedIteratorTests, stir::OutputFileFormatTests, stir::overlap_interpolateTests, stir::PLSPriorTests, stir::PoissonLogLikelihoodWithLinearModelForMeanAndListModeDataWithProjMatrixByBinTests, stir::PoissonLogLikelihoodWithLinearModelForMeanAndProjDataTests, stir::ProjDataInfoCylindricalArcCorrTests, stir::ProjDataInfoCylindricalNoArcCorrTests, stir::ProjDataInMemoryTests, stir::ProjDataInMemoryTests, stir::ProjDataTests, stir::ProjMatrixByBinUsingInterpolationTests, stir::QuadraticPriorTests, stir::QuaternionTests, stir::RadionuclideTest, stir::RelativeDifferencePriorTests< RDP >, stir::RigidObject3DTransformationTests, stir::ROITests, stir::ScannerTests, stir::ScatterSimulationTests, stir::SeparableGaussianArrayFilterTests, stir::SeparableMetzArrayFilterTests, stir::stir_mathTests, stir::TestBSplineTransformation, stir::TestDataProcessorProjectors, stir::TestFBP2D, stir::TestFBP3DRP, stir::TestGPUProjectors, stir::TestOSMAPOSL, stir::TestProjDataInfoSubsets, stir::TestProjDataInfoSubsetsSPECTUB, stir::TOF_Tests, stir::VectorWithOffsetTests, stir::VoxelsOnCartesianGridTests, stir::warp_imageTests, and stir::zoom_imageTests.

References check(), check_if_equal_generic(), get_tolerance(), is_everything_ok(), main_return_value(), set_tolerance(), and tolerance.

◆ is_everything_ok()

◆ main_return_value()

int stir::RunTests::main_return_value ( ) const

Handy return value for a main() function.

Returns EXIT_SUCCESS if is_everything_ok(), EXIT_FAILURE otherwise

References everything_ok.

Referenced by run_tests().

◆ set_tolerance()

◆ get_tolerance()

double stir::RunTests::get_tolerance ( ) const

Get value used in floating point comparisons (see check_* functions).

References tolerance.

Referenced by stir::linear_regressionTests::run_tests(), run_tests(), stir::SeparableMetzArrayFilterTests::run_tests(), and stir::zoom_imageTests::run_tests().

◆ check()

bool stir::RunTests::check ( const bool result,
const std::string & str = "" )

◆ check_if_equal() [1/4]

bool stir::RunTests::check_if_equal ( const double a,
const double b,
const std::string & str = "" )

tolerance is used to account for floating point rounding error. First the absolute difference is checked and afterwards the relative.

const double diff = fabs(b-a);
if (diff <= tolerance)
return true;
const double largest = (std::max(fabs(b), fabs(a)));
if ( diff > tolerance*largest)
return false;
else
return true;
double tolerance
tolerance for comparisons with real values
Definition RunTests.h:279

References everything_ok, and tolerance.

◆ check_if_equal() [2/4]

template<class T>
bool stir::RunTests::check_if_equal ( const VectorWithOffset< T > & t1,
const VectorWithOffset< T > & t2,
const std::string & str = "" )
inline

check equality by comparing ranges and calling check_if_equal on all elements

References everything_ok, stir::VectorWithOffset< T >::get_max_index(), and stir::VectorWithOffset< T >::get_min_index().

◆ check_if_equal() [3/4]

template<class T>
bool stir::RunTests::check_if_equal ( const std::vector< T > & t1,
const std::vector< T > & t2,
const std::string & str = "" )
inline

check equality by comparing size and calling check_if_equal on all elements

References everything_ok.

◆ check_if_equal() [4/4]

template<int num_dimensions, class coordT>
bool stir::RunTests::check_if_equal ( const BasicCoordinate< num_dimensions, coordT > & a,
const BasicCoordinate< num_dimensions, coordT > & b,
const std::string & str = "" )
inline

check equality by comparing norm(a-b) with tolerance

References everything_ok, stir::norm(), and tolerance.

◆ check_if_zero() [1/3]

bool stir::RunTests::check_if_zero ( const double a,
const std::string & str = "" )

◆ check_if_zero() [2/3]

template<class T>
bool stir::RunTests::check_if_zero ( const VectorWithOffset< T > & t,
const std::string & str = "" )
inline

use check_if_zero on all elements

References check_if_zero().

◆ check_if_zero() [3/3]

template<int num_dimensions, class coordT>
bool stir::RunTests::check_if_zero ( const BasicCoordinate< num_dimensions, coordT > & a,
const std::string & str = "" )
inline

compare norm with tolerance

References everything_ok, stir::norm(), and tolerance.

◆ check_if_less()

◆ check_if_equal_generic()

template<class T>
bool stir::RunTests::check_if_equal_generic ( const T & a,
const T & b,
const std::string & str )
inlineprotected

function that is called by some check_if_equal implementations. It just uses operator!=

References everything_ok.

Referenced by run_tests().

◆ check_if_zero_generic()

template<class T>
bool stir::RunTests::check_if_zero_generic ( T a,
const std::string & str )
inlineprotected

function that is called by some check_if_zero implementations. It just uses operator!=

References everything_ok.

Member Data Documentation

◆ tolerance

double stir::RunTests::tolerance
protected

◆ everything_ok


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