Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Anaphe::Reporter Class Reference

#include <Reporter.h>

List of all members.

Public Methods

 Reporter (void)
 ~Reporter (void)
bool report (const bool &with_printout) const
 Report with or without verbose printout. Returns true if all tests passed OK. More...

void setTitle (const std::string &)
 Set the title of the set of tests. More...

void clear (void)
 Discard all currently stored tests and start again. More...

void keep (const std::string &, const bool &ex, const bool &ob)
 Store the name of a test, its expected result and the actual result. More...

void keep (const std::string &, const int &ex, const int &ob)
 Store the name of a test, its expected result and the actual result. More...

void keep (const std::string &, const float &ex, const float &ob)
 Store the name of a test, its expected result and the actual result. More...

void keep (const std::string &, const double &ex, const double &ob)
 Store the name of a test, its expected result and the actual result. More...

void keep (const std::string &, const char *ex, const char *ob)
 Store the name of a test, its expected result and the actual result. More...

void keep (const std::string &, const std::string &ex, const std::string &ob)
 Store the name of a test, its expected result and the actual result. More...


Private Types

typedef std::map< int, Test
>::const_iterator 
TestIt

Private Methods

void print (const std::string &, const std::string &, const std::string &, const int &=-1) const
bool veryClose (const float &, const float &) const
 Returns true if two floats are very similar. More...

bool veryClose (const double &, const double &) const
 Returns true if two doubles are very similar. More...

std::string asString (const int &) const
std::string asString (const float &) const
std::string asString (const double &a) const
void reg (const std::string &name, const std::string &ex, const std::string &ob, const bool &res)
void printHeader (void) const

Private Attributes

std::string title
std::map< int, TesttestList
unsigned int widest_title
unsigned int widest_ob
unsigned int widest_ex
int nt

Static Private Attributes

const float F_PREC = 1e-5
const double D_PREC = 1e-9
const std::string H_TITLE = "Test description"
const std::string H_EXP = "Expected"
const std::string H_OBS = "Observed"
const std::string H_FLAG = "Pass?"


Detailed Description

Reporter - simple helper class for testing. Used like this:

                                             
   Reporter r;                                     
   r.setTitle("tests of my mathlib");              
   float pi = 3.14159, e = 2.71828;                
   float tpi = calculatePi(), te = calculateE();   
   r.keep("a test of calcPi",pi,tpi);              
   r.keep("another test",e,te);                    
   ...                                             
   bool printout = false;                          
   bool passed = r.report(printout);               
   if (passed) cout << "all as expected" << endl;  
   

Useful for conducting many tests in the same function.

Author M.Sang (c) CERN, Geneva

Definition at line 40 of file Reporter.h.


Member Typedef Documentation

typedef std::map<int,Test>::const_iterator TestIt [private]
 

Definition at line 104 of file Reporter.h.

Referenced by report.


Constructor & Destructor Documentation

Reporter void   
 

Definition at line 64 of file Reporter.cpp.

References clear, nt, widest_ex, widest_ob, and widest_title.

~Reporter void   
 

Definition at line 76 of file Reporter.cpp.

References clear.


Member Function Documentation

std::string asString const double &    a const [private]
 

Definition at line 235 of file Reporter.cpp.

std::string asString const float &    const [private]
 

Definition at line 221 of file Reporter.cpp.

std::string asString const int &    const [private]
 

Definition at line 207 of file Reporter.cpp.

Referenced by keep.

void clear void   
 

Definition at line 84 of file Reporter.cpp.

References H_EXP, H_OBS, H_TITLE, nt, testList, widest_ex, widest_ob, and widest_title.

Referenced by Reporter, and ~Reporter.

void keep const std::string &   ,
const std::string &    ex,
const std::string &    ob
 

Definition at line 170 of file Reporter.cpp.

References reg.

void keep const std::string &   ,
const char *    ex,
const char *    ob
 

Definition at line 148 of file Reporter.cpp.

References reg.

void keep const std::string &   ,
const double &    ex,
const double &    ob
 

Definition at line 159 of file Reporter.cpp.

References asString, reg, and veryClose.

void keep const std::string &   ,
const float &    ex,
const float &    ob
 

Definition at line 137 of file Reporter.cpp.

References asString, reg, and veryClose.

void keep const std::string &   ,
const int &    ex,
const int &    ob
 

Definition at line 126 of file Reporter.cpp.

References asString, and reg.

void keep const std::string &   ,
const bool &    ex,
const bool &    ob
 

Definition at line 179 of file Reporter.cpp.

References asString, and reg.

void print const std::string &   ,
const std::string &   ,
const std::string &   ,
const int &    = -1
const [private]
 

Definition at line 249 of file Reporter.cpp.

References H_FLAG, widest_ex, widest_ob, and widest_title.

Referenced by printHeader, and report.

void printHeader void    const [private]
 

Definition at line 263 of file Reporter.cpp.

References print, title, widest_ex, widest_ob, and widest_title.

Referenced by report.

void reg const std::string &    name,
const std::string &    ex,
const std::string &    ob,
const bool &    res
[private]
 

Definition at line 279 of file Reporter.cpp.

References nt, testList, widest_ex, widest_ob, and widest_title.

Referenced by keep.

bool report const bool &    with_printout const
 

Definition at line 190 of file Reporter.cpp.

References print, printHeader, TestIt, and testList.

void setTitle const std::string &   
 

Definition at line 96 of file Reporter.cpp.

References title.

bool veryClose const double &   ,
const double &   
const [private]
 

Definition at line 115 of file Reporter.cpp.

References D_PREC.

bool veryClose const float &   ,
const float &   
const [private]
 

Definition at line 104 of file Reporter.cpp.

References F_PREC.

Referenced by keep.


Member Data Documentation

const double D_PREC = 1e-9 [static, private]
 

Definition at line 30 of file Reporter.cpp.

Referenced by veryClose.

const float F_PREC = 1e-5 [static, private]
 

Definition at line 29 of file Reporter.cpp.

Referenced by veryClose.

const std::string H_EXP = "Expected" [static, private]
 

Definition at line 32 of file Reporter.cpp.

Referenced by clear.

const std::string H_FLAG = "Pass?" [static, private]
 

Definition at line 34 of file Reporter.cpp.

Referenced by print.

const std::string H_OBS = "Observed" [static, private]
 

Definition at line 33 of file Reporter.cpp.

Referenced by clear.

const std::string H_TITLE = "Test description" [static, private]
 

Definition at line 31 of file Reporter.cpp.

Referenced by clear.

int nt [private]
 

Definition at line 108 of file Reporter.h.

Referenced by clear, reg, and Reporter.

std::map<int,Test> testList [private]
 

Definition at line 103 of file Reporter.h.

Referenced by clear, reg, and report.

std::string title [private]
 

Definition at line 102 of file Reporter.h.

Referenced by printHeader, and setTitle.

unsigned int widest_ex [private]
 

Definition at line 107 of file Reporter.h.

Referenced by clear, print, printHeader, reg, and Reporter.

unsigned int widest_ob [private]
 

Definition at line 106 of file Reporter.h.

Referenced by clear, print, printHeader, reg, and Reporter.

unsigned int widest_title [private]
 

Definition at line 105 of file Reporter.h.

Referenced by clear, print, printHeader, reg, and Reporter.


The documentation for this class was generated from the following files:
Generated on Tue May 20 14:50:28 2003 for HepUtilities by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002