All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
TestManagerClass< T > Class Template Reference

Test manager class. More...

Classes

struct  FailureInfo_t
 Data structure to document failure of a single action. More...
 

Public Types

typedef T Data_t
 
typedef TestManagerClass< Data_tThis_t
 
typedef std::vector< Data_tVector_t
 
typedef lar::sparse_vector
< Data_t
SparseVector_t
 
typedef actions::BaseAction
< Data_t
Action_t
 

Public Member Functions

 TestManagerClass (std::ostream &output_stream=std::cout)
 Constructor, specify an output stream. More...
 
size_t current_vector_size () const
 Returns the current size of the STL vector. More...
 
bool validate () const
 Checks if the sparse vector is valid. More...
 
bool match () const
 
unsigned int check ()
 
void run (const Action_t &action)
 
unsigned int perform (const Action_t &action, bool autoCorrect=true)
 Perform the specified action and evaluate the result. More...
 
int quiet (int nq=0)
 
unsigned int operator() (const Action_t &action)
 
void recover ()
 Set the sparse vector as a copy of the vector (lossy!) More...
 
void mirror ()
 Set the vector as a copy of the sparse vector. More...
 
int summary () const
 Print a summary of the failures. More...
 

Public Attributes

Vector_t v {}
 vector to operate on More...
 
SparseVector_t sv {}
 sparse vector to operate on More...
 
unsigned int nAction {0}
 number of actions taken so far More...
 
unsigned int nErrors {0}
 number of errors accumulated More...
 
std::vector< FailureInfo_tfailures
 documentation of the failures More...
 
int quietness {0}
 verbosity level (larger is less verbose) More...
 
std::ostream & out
 output stream More...
 

Detailed Description

template<typename T>
class TestManagerClass< T >

Test manager class.

Definition at line 81 of file sparse_vector_test.cc.

Member Typedef Documentation

template<typename T>
typedef actions::BaseAction<Data_t> TestManagerClass< T >::Action_t

Definition at line 87 of file sparse_vector_test.cc.

template<typename T>
typedef T TestManagerClass< T >::Data_t

Definition at line 83 of file sparse_vector_test.cc.

template<typename T>
typedef lar::sparse_vector<Data_t> TestManagerClass< T >::SparseVector_t

Definition at line 86 of file sparse_vector_test.cc.

template<typename T>
typedef TestManagerClass<Data_t> TestManagerClass< T >::This_t

Definition at line 84 of file sparse_vector_test.cc.

template<typename T>
typedef std::vector<Data_t> TestManagerClass< T >::Vector_t

Definition at line 85 of file sparse_vector_test.cc.

Constructor & Destructor Documentation

template<typename T>
TestManagerClass< T >::TestManagerClass ( std::ostream &  output_stream = std::cout)
inline

Constructor, specify an output stream.

Definition at line 114 of file sparse_vector_test.cc.

114  : out(output_stream)
115  {}
std::ostream & out
output stream

Member Function Documentation

template<typename T>
unsigned int TestManagerClass< T >::check ( )
inline

Definition at line 164 of file sparse_vector_test.cc.

165  {
166  unsigned int local_errors = 0;
167  if (!validate()) ++local_errors;
168  if (!match()) {
169  out << "*** Mismatch: " << std::string(58, '*') << std::endl;
170  out << "vector: " << VectorToString(v) << std::endl;
171  out << "sparse vector: " << VectorToString(sv) << std::endl;
172  out << std::string(72, '*') << std::endl;
173  ++local_errors;
174  }
175  return local_errors;
176  } // check()
std::string VectorToString(const CONT &sv)
Converts a container into a string.
std::ostream & out
output stream
bool validate() const
Checks if the sparse vector is valid.
Vector_t v
vector to operate on
SparseVector_t sv
sparse vector to operate on
template<typename T>
size_t TestManagerClass< T >::current_vector_size ( ) const
inline

Returns the current size of the STL vector.

Definition at line 119 of file sparse_vector_test.cc.

119 { return v.size(); }
Vector_t v
vector to operate on
template<typename T>
bool TestManagerClass< T >::match ( ) const
inline

Definition at line 162 of file sparse_vector_test.cc.

162 { return std::equal(v.begin(), v.end(), sv.begin()); }
Vector_t v
vector to operate on
SparseVector_t sv
sparse vector to operate on
bool equal(double a, double b)
Comparison tolerance, in centimeters.
iterator begin()
Standard iterators interface.
template<typename T>
void TestManagerClass< T >::mirror ( )
inline

Set the vector as a copy of the sparse vector.

Definition at line 231 of file sparse_vector_test.cc.

231 { v.assign(sv.cbegin(), sv.cend()); }
const_iterator cend() const
Vector_t v
vector to operate on
SparseVector_t sv
sparse vector to operate on
const_iterator cbegin() const
template<typename T>
unsigned int TestManagerClass< T >::operator() ( const Action_t action)
inline

Definition at line 224 of file sparse_vector_test.cc.

224 { return perform(action); }
unsigned int perform(const Action_t &action, bool autoCorrect=true)
Perform the specified action and evaluate the result.
template<typename T>
unsigned int TestManagerClass< T >::perform ( const Action_t action,
bool  autoCorrect = true 
)
inline

Perform the specified action and evaluate the result.

Parameters
actionthe action to be performed
autoCorrectif on failure the sparse vector is copied from vector
Returns
number of detected errors

Definition at line 192 of file sparse_vector_test.cc.

193  {
194  out << "[" << ++nAction << "] ";
195  action.describe(*this);
196  out << std::endl;
197  run(action);
198  if (quietness <= 0) {
199  out << " => ";
200  PrintVectorRanges(sv) << std::endl;
201  }
202  unsigned int errors = check();
203  if (action.expected_errors != 0) {
204  out << " (" << action.expected_errors << " error(s) expected)"
205  << std::endl;
206  }
207  if ((int)errors != action.expected_errors) {
208  int actual_errors = abs(errors - action.expected_errors);
209  nErrors += actual_errors;
210  failures.emplace_back(*this, action, actual_errors);
211  if (autoCorrect) {
212  recover();
213  if (!match())
214  out << " *** recovery from error failed ***" << std::endl;
215  } // if autoCorrect
216  } // if errors
217  return errors;
218  } // perform()
std::ostream & out
output stream
unsigned int nAction
number of actions taken so far
unsigned int check()
void recover()
Set the sparse vector as a copy of the vector (lossy!)
std::ostream & PrintVectorRanges(const lar::sparse_vector< T > &sv, std::ostream &out=std::cout)
Prints a sparse vector highlighting the ranges.
T abs(T value)
SparseVector_t sv
sparse vector to operate on
int quietness
verbosity level (larger is less verbose)
unsigned int nErrors
number of errors accumulated
std::vector< FailureInfo_t > failures
documentation of the failures
void run(const Action_t &action)
template<typename T>
int TestManagerClass< T >::quiet ( int  nq = 0)
inline

Definition at line 221 of file sparse_vector_test.cc.

221 { int q = quietness; quietness = nq; return q; }
int quietness
verbosity level (larger is less verbose)
template<typename T>
void TestManagerClass< T >::recover ( )
inline

Set the sparse vector as a copy of the vector (lossy!)

Definition at line 228 of file sparse_vector_test.cc.

228 { sv.assign(v); sv.optimize(); }
Vector_t v
vector to operate on
SparseVector_t sv
sparse vector to operate on
bool optimize()
Performs internal optimization, returns whether the object was changed.
void assign(ITER first, ITER last)
Copies data from a sequence between two iterators.
template<typename T>
void TestManagerClass< T >::run ( const Action_t action)
inline

Definition at line 179 of file sparse_vector_test.cc.

180  {
181  action(v);
182  action(sv);
183  } // run()
Vector_t v
vector to operate on
SparseVector_t sv
sparse vector to operate on
template<typename T>
int TestManagerClass< T >::summary ( ) const
inline

Print a summary of the failures.

Definition at line 234 of file sparse_vector_test.cc.

235  {
236  out << nAction << " tests performed";
237  if (nErrors == 0) {
238  out << " successfully." << std::endl;
239  }
240  else {
241  out << ", " << nErrors << " unexpected errors occurred in "
242  << failures.size() << " of them:" << std::endl;
243  for (const FailureInfo_t& info: failures) {
244  out << " [" << info.nAction << "] " << info.description
245  << " => " << info.nErrors << " errors" << std::endl;
246  } // for
247  } // if errors
248  return nErrors;
249  } // summary()
std::ostream & out
output stream
unsigned int nAction
number of actions taken so far
unsigned int nErrors
number of errors accumulated
std::vector< FailureInfo_t > failures
documentation of the failures
template<typename T>
bool TestManagerClass< T >::validate ( ) const
inline

Checks if the sparse vector is valid.

Definition at line 123 of file sparse_vector_test.cc.

124  {
125  const auto ranges = sv.get_ranges();
126  // a sparse vector with no non-null elements can't be detected invalid
127  if (ranges.empty()) {
128  // std::cout << "[vector is void]" << std::endl;
129  return true;
130  }
131  int i = 0;
132  auto iNext = ranges.cbegin(), rend = ranges.cend();
133  while (iNext != rend) {
134  auto iRange = iNext++;
135  if (iRange->empty()) {
136  out << "[range " << i << " is empty]" << std::endl;
137  return false;
138  }
139  if (iNext != rend) {
140  if (!(*iRange < *iNext)) {
141  out << "[range " << i << " comes after range " << (i+1) << "]"
142  << std::endl;
143  return false;
144  }
145  if (!iRange->separate(*iNext)) {
146  out << "[range " << i << " is overlapping or adjacent to "
147  << (i+1) << "]" << std::endl;
148  return false;
149  }
150  }
151  ++i;
152  } // while
153  if (sv.size() < ranges.back().end_index()) {
154  out << "[size is " << sv.size() << ", it should be at least "
155  << ranges.back().end_index() << "]" << std::endl;
156  return false;
157  }
158  return true;
159  } // validate()
std::ostream & out
output stream
size_type size() const
Returns the size of the vector.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
SparseVector_t sv
sparse vector to operate on

Member Data Documentation

template<typename T>
std::vector<FailureInfo_t> TestManagerClass< T >::failures

documentation of the failures

Definition at line 107 of file sparse_vector_test.cc.

template<typename T>
unsigned int TestManagerClass< T >::nAction {0}

number of actions taken so far

Definition at line 105 of file sparse_vector_test.cc.

template<typename T>
unsigned int TestManagerClass< T >::nErrors {0}

number of errors accumulated

Definition at line 106 of file sparse_vector_test.cc.

template<typename T>
std::ostream& TestManagerClass< T >::out

output stream

Definition at line 111 of file sparse_vector_test.cc.

template<typename T>
int TestManagerClass< T >::quietness {0}

verbosity level (larger is less verbose)

Definition at line 109 of file sparse_vector_test.cc.

template<typename T>
SparseVector_t TestManagerClass< T >::sv {}

sparse vector to operate on

Definition at line 104 of file sparse_vector_test.cc.

template<typename T>
Vector_t TestManagerClass< T >::v {}

vector to operate on

Definition at line 103 of file sparse_vector_test.cc.


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