STIR  6.2.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members

A base class for making test classesWith a derived class, an application could look like. 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::BlocksTests, stir::BSpline::BSplines_Tests, stir::BSpline::BSplinesRegularGrid1D_Tests, stir::BSpline::BSplinesRegularGrid_Tests, stir::ByteOrderTests, stir::convert_array_Tests, stir::coordinateTests, stir::DataSymmetriesForBins_PET_CartesianGridTests, stir::DateTimeTest, stir::DetectionPosition_Tests, stir::DetectionPosMapTests, stir::DynamicDiscretisedDensityTests, stir::erfTests, stir::ExportArrayTests, stir::FilenameTests, stir::find_fwhm_in_imageTests, stir::FourierTests, stir::GATEConsistencyTests, stir::GeneralisedPoissonNoiseGeneratorTests, stir::GeometryBlocksOnCylindricalTests, stir::ImagingModalityTests, stir::IndexRange_Tests, stir::integrate_discrete_functionTests, stir::InterpolationTests, stir::IOTests< A >, stir::IOTests_ITKMulticomponent, stir::IR_filterTests, stir::KeyParserTests, stir::linear_regressionTests, stir::LmToProjDataWithMCTests, stir::MatrixTests, stir::ML_normTests, stir::modellingTests, stir::MultipleProjDataTests, stir::NestedIteratorTests, stir::ObjectiveFunctionTests< ObjectiveFunctionT, TargetT >, stir::OutputFileFormatTests, stir::overlap_interpolateTests, stir::ParametricDiscretisedDensityTests, stir::ProjDataInfoTests, stir::ProjDataInMemoryTests, stir::ProjDataInMemoryTests, stir::ProjDataTests, stir::ProjMatrixByBinUsingInterpolationTests, stir::QuaternionTests, stir::RadionuclideTest, stir::ReconstructionTests< TargetT >, stir::RigidObject3DTransformationTests, stir::ROITests, stir::ScannerTests, stir::ScatterSimulationTests, stir::SeparableGaussianArrayFilterTests, stir::SeparableMetzArrayFilterTests, stir::stir_mathTests, stir::TestBSplineTransformation, stir::TestDataProcessorProjectors, stir::TestGPUProjectors, stir::TestProjDataInfoSubsets, stir::TOF_Tests, stir::VectorWithOffsetTests, stir::VoxelsOnCartesianGridTests, stir::warp_imageTests, and stir::zoom_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. More...
 
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. More...
 
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. More...
 
template<class T1 , class T2 >
bool check_if_less (T1 a, T2 b, const std::string &str="")
 check if a<b
 
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 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()
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
 

Protected Member Functions

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!=
 

Protected Attributes

double tolerance
 tolerance for comparisons with real values
 
bool everything_ok
 variable storing current status
 

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.

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

◆ 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.

◆ check()

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

◆ check_if_equal()

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;

References stir::ProjDataInMemory::begin(), check_if_equal_generic(), check_if_zero(), check_if_zero_generic(), stir::ProjDataInMemory::end(), everything_ok, stir::ProjData::get_proj_data_info_sptr(), and tolerance.

◆ check_if_zero()

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

check if

fabs(a)<=tolerance

References everything_ok, and tolerance.

Referenced by check_if_equal().


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