gslmm::test_suite Class Reference
[Test suite handling]

#include <gslmm/test/test_suite.hh>

Collaboration diagram for gslmm::test_suite:

Collaboration graph
[legend]
List of all members.

Detailed Description

Utility class to use in test suits.

The idea is that one creates an object of this class, and then do operations in the program. Then, one passes the result of the operation, as well as the expected result of the operation, to the appropiate member function of this class. The object then keeps a score of how many operations gave the expected result.

Turning on the verbosity will print out descriptions of the tests evaluated, along with information on whether the test passed or failed.

Various tests are defined. They are explained in the member function documentation.

A simple example could be

      #include <gslmm/test/test_suite.hh>
      #include <gslmm/math/type_trait.hh>

      int main(int argc, char** argv) 
      { 
      gslmm::test_suite ts;

      for (int i = 1; i < argc; i++) {
        if (!argv[i][0] || argv[i][0] != '-' || !argv[i][1]) continue;
          switch (argv[i][1]) {
          case 'h':  
            std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
            return 0;
          case 'v': ts.verbose(); break;
          }
        }

        double x = M_PI;
        y = 22.0 / 7.0;

        //___________________________________________________________________
        // test the basic function 
        for (int i = 0; i < 10; i++) {
          double tol = pow(10, -i);
          int    res = gslmm::compare(x, y, tol);
          ts.test(res, -(i >= 4 ? 1 : 0), 
                  "gslmm::compare(%.5f,%.5f,%g)", x, y, tol);
        }
        
        return ts.summary() ? 0 : 1;
      }
The above will print
      PASS: gslmm::compare(3.14159,3.14286,1)
      PASS: gslmm::compare(3.14159,3.14286,0.1)
      PASS: gslmm::compare(3.14159,3.14286,0.01)
      PASS: gslmm::compare(3.14159,3.14286,0.001)
      PASS: gslmm::compare(3.14159,3.14286,0.0001)
      PASS: gslmm::compare(3.14159,3.14286,1e-05)
      PASS: gslmm::compare(3.14159,3.14286,1e-06)
      PASS: gslmm::compare(3.14159,3.14286,1e-07)
      PASS: gslmm::compare(3.14159,3.14286,1e-08)
      PASS: gslmm::compare(3.14159,3.14286,1e-09)
      10 tests, 10 passed, 0 failed.
      All tests passed successfully
      
if the verbose output was turned on.
Examples:

annealing/annealing-test.cc, blas/blas-test.cc, chebyshev/chebyshev-test.cc, combination/combination-test.cc, compleks/complex-test.cc, constant/constant-test.cc, differentiation/differentiation-test.cc, eigen/eigen-test.cc, error/error-test.cc, fit/fit-test.cc, fourier/fourier-test.cc, hankel/hankel-test.cc, histogram/histogram-test.cc, ieee/ieee-test.cc, integration/integration-test.cc, interpolation/interpolation-test.cc, linear/linear-test.cc, math/math-test.cc, minimization/minimization-test.cc, montecarlo/montecarlo-test.cc, ntuple/ntuple-test.cc, ordinary/ordinary-test.cc, permutation/permutation-test.cc, polynomial/polynomial-test.cc, random/distribution-test.cc, random/generator-test.cc, random/quasi_generator-test.cc, root/root-test.cc, series/series-test.cc, sort/sort-test.cc, special/special-test.cc, statistic/statistic-test.cc, vectormatrix/matrix-test.cc, and vectormatrix/vector-test.cc.


Public Member Functions

 test_suite (const std::string &n, int &argc, char **argv)
virtual ~test_suite ()
bool is_verbose () const
void banner () const
Tests
bool check (bool status, const char *description,...)
bool status (int status, const char *description,...)
bool relative (double result, double expected, double error, const char *description,...)
template<typename Type>
bool absolute (const Type &result, const Type &expected, const Type &error, const char *description,...)
bool factor (double result, double expected, double error, const char *description,...)
template<typename Type>
bool range (const Type &result, const Type &min, const Type &max, const char *description,...)
template<typename Type, typename Type1>
bool test (const Type &result, const Type1 &expected, const char *description,...)
Status of test suite
bool summary ()
int tests () const
int passed () const
int failed () const
void message (const char *format,...)

Static Public Member Functions

static test_suiteinstance ()

Protected Member Functions

bool store (bool status)
template<typename Type, typename Type1>
void print (bool status, const Type &result, const Type1 &expected)

Protected Attributes

optionmm::command_line _cl
optionmm::bool_option _verbose
int _tests
int _passed
int _failed
char _buf [1024]

Static Protected Attributes

static test_suite_instance = 0


Constructor & Destructor Documentation

gslmm::test_suite::test_suite const std::string &  n,
int &  argc,
char **  argv
[inline]
 

Constructor.

virtual gslmm::test_suite::~test_suite  )  [inline, virtual]
 

Destructor.


Member Function Documentation

template<typename T>
bool gslmm::test_suite::absolute const Type &  result,
const Type &  expected,
const Type &  error,
const char *  description,
  ...
[inline]
 

Absolute error test.

The test is passed if $ |result - expected| \leq error $

Parameters:
result The result of the computations.
expected The expected result.
error The absolute tolerance.
description What you expect.
Returns:
true if test succeded, false otherwise.
Examples:
chebyshev/chebyshev-test.cc, and histogram/histogram-test.cc.

void gslmm::test_suite::banner  )  const [inline]
 

Show a banner.

bool gslmm::test_suite::check bool  status,
const char *  description,
  ...
[inline]
 

Test a truth value.

The test is passed if status evaluates to true.

Parameters:
status The truth value.
description What you expect.
Returns:
true if test succeded, false otherwise.
Examples:
error/error-test.cc, histogram/histogram-test.cc, ntuple/ntuple-test.cc, polynomial/polynomial-test.cc, vectormatrix/matrix-test.cc, and vectormatrix/vector-test.cc.

bool gslmm::test_suite::factor double  result,
double  expected,
double  error,
const char *  description,
  ...
[inline]
 

Factor error test.

The test is passed if $ f \leq error \wedge f \leq 1 / error$, where $ f = result / expected $

Parameters:
result The result of the computations.
expected The expected result.
error The factor tolerance.
description What you expect.
Returns:
true if test succeded, false otherwise.
Examples:
chebyshev/chebyshev-test.cc, and random/generator-test.cc.

int gslmm::test_suite::failed  )  const [inline]
 

Get the number of failed tests.

Returns:
the number of failed tests done so far.
Examples:
compleks/complex-test.cc.

static test_suite& gslmm::test_suite::instance  )  [inline, static]
 

Examples:
error/error-test.cc.

bool gslmm::test_suite::is_verbose  )  const [inline]
 

Whether we're verbose.

void gslmm::test_suite::message const char *  format,
  ...
[inline]
 

Print a message.

Examples:
linear/linear-test.cc.

int gslmm::test_suite::passed  )  const [inline]
 

Get the number of passed tests.

Returns:
the number of passed tests done so far.

template<typename Type, typename Type1>
void gslmm::test_suite::print bool  status,
const Type &  result,
const Type1 &  expected
[inline, protected]
 

Utility function to print result for double tests.

Parameters:
status Status of test.
result The result.
expected The exprected result.

template<typename Type>
bool gslmm::test_suite::range const Type &  result,
const Type &  min,
const Type &  max,
const char *  description,
  ...
[inline]
 

Range error test.

Test is passed if $ min < result < max$

Parameters:
result The result of the computations
min The lower limit
max The upper limit.
description What you expect.
Returns:
true if test succeded, false otherwise.
Examples:
random/generator-test.cc.

bool gslmm::test_suite::relative double  result,
double  expected,
double  error,
const char *  description,
  ...
[inline]
 

Relative error test.

The test is passed if $ |result - expected|/|expected| \leq error $

Parameters:
result The result of the computations.
expected The expected result.
error The relatvie tolerance.
description What you expect.
Returns:
true if test succeded, false otherwise.
Examples:
annealing/annealing-test.cc, compleks/complex-test.cc, math/math-test.cc, polynomial/polynomial-test.cc, statistic/statistic-test.cc, and vectormatrix/matrix-test.cc.

bool gslmm::test_suite::status int  status,
const char *  description,
  ...
[inline]
 

Test a return status.

The test is passed if status is 0.

Parameters:
status The result of the computations.
description What you expect.
Returns:
true if test succeded, false otherwise.
Examples:
linear/linear-test.cc, random/distribution-test.cc, random/generator-test.cc, random/quasi_generator-test.cc, and vectormatrix/matrix-test.cc.

bool gslmm::test_suite::store bool  status  )  [inline, protected]
 

Utility function to increment counters etc.

Parameters:
status The status of a test.

bool gslmm::test_suite::summary  )  [inline]
 

Write a summary of the tests.

Returns:
true if all tests succeded, false otherwise.
Examples:
chebyshev/chebyshev-test.cc, combination/combination-test.cc, compleks/complex-test.cc, constant/constant-test.cc, differentiation/differentiation-test.cc, eigen/eigen-test.cc, error/error-test.cc, fit/fit-test.cc, fourier/fourier-test.cc, hankel/hankel-test.cc, histogram/histogram-test.cc, integration/integration-test.cc, interpolation/interpolation-test.cc, linear/linear-test.cc, math/math-test.cc, minimization/minimization-test.cc, montecarlo/montecarlo-test.cc, ntuple/ntuple-test.cc, ordinary/ordinary-test.cc, permutation/permutation-test.cc, polynomial/polynomial-test.cc, random/distribution-test.cc, random/generator-test.cc, random/quasi_generator-test.cc, root/root-test.cc, series/series-test.cc, sort/sort-test.cc, special/special-test.cc, and vectormatrix/matrix-test.cc.

template<typename Type, typename Type1>
bool gslmm::test_suite::test const Type &  result,
const Type1 &  expected,
const char *  description,
  ...
[inline]
 

Compare arbitriary types.

Type must define the == operator, and the put-to operator for streams (operator<<(ostream&,const Type&)).

Parameters:
result The result of the computations.
expected The expected result.
description What you expect.
Returns:
true if test succeded, false otherwise.
Examples:
combination/combination-test.cc, compleks/complex-test.cc, histogram/histogram-test.cc, ieee/ieee-test.cc, math/math-test.cc, permutation/permutation-test.cc, polynomial/polynomial-test.cc, random/generator-test.cc, statistic/statistic-test.cc, vectormatrix/matrix-test.cc, and vectormatrix/vector-test.cc.

int gslmm::test_suite::tests  )  const [inline]
 

Get the number of tests.

Returns:
the number of tests done so far.


Member Data Documentation

char gslmm::test_suite::_buf[1024] [protected]
 

Buffer for output messages.

optionmm::command_line gslmm::test_suite::_cl [protected]
 

int gslmm::test_suite::_failed [protected]
 

The number of failed tests so far.

test_suite * gslmm::test_suite::_instance = 0 [static, protected]
 

int gslmm::test_suite::_passed [protected]
 

The number of passed tests so far.

int gslmm::test_suite::_tests [protected]
 

The total number of tests so far.

optionmm::bool_option gslmm::test_suite::_verbose [protected]
 

The verbosity level.


The documentation for this class was generated from the following file:
Top of page Last update Tue May 9 10:11:37 2006
Christian Holm
Created by DoxyGen 1.4.6