Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestingObject< ResultsType > Class Template Reference

Project-specific testing object. More...

#include <RocstarTest.H>

Inheritance diagram for TestingObject< ResultsType >:
Collaboration diagram for TestingObject< ResultsType >:

Public Member Functions

 TestingObject ()
 Default constructor. More...
 
virtual void Epilogue ()
 Tears down the testing fixtures if needed. More...
 
virtual void Prologue ()
 Sets up the data fixtures for the tests. More...
 
double F1 (double x)
 Simple test function fixture returns $2x$. More...
 
double F2 (double x)
 Simple test function fixture returns $3x^2$. More...
 
virtual void Test__ExampleFunction (ResultsType &result)
 Test for Rocstar::ExampleFunction. More...
 
virtual void Test__TrapezoidQuadrature (ResultsType &result)
 Test for Rocstar::TrapezoidQuadrature. More...
 
virtual void Test__MidPointQuadrature (ResultsType &result)
 Test for Rocstar::MidPointQuadrature. More...
 
virtual void Process (ResultsType &result)
 Runs all tests implemented by the Rocstar::TestingObject. More...
 
virtual void RunTest (const std::string &name, ResultsType &result)
 Runs a test specified by name. More...
 
virtual void ProcessTests (std::list< std::string > &test_names, ResultsType &result)
 Runs a list of tests specified by name. More...
 

Protected Attributes

std::string ExampleTestFixture
 A sample string test fixture. More...
 
std::vector< int > N
 A set of values for testing quadrature methods. More...
 

Private Types

typedef
IRAD::Util::TestingObject
< ResultsType > 
TestingObjectBaseType
 

Detailed Description

template<typename ResultsType>
class Rocstar::TestingObject< ResultsType >

Project-specific testing object.

The project-specific testing object encapsulates all tests for the project. This is the interface to all testing available for the given project. It implements the interface given by IRAD::Util::TestingObject.

Every project should define a "TestingObject" which implements (or interfaces) all of the tests for the project. If necessary (e.g. for parallel tests through batch systems), this is the object responsible for spawning off children processes to conduct parallel tests and for gathering the results of those tests.

Definition at line 71 of file RocstarTest.H.

Member Typedef Documentation

typedef IRAD::Util::TestingObject<ResultsType> TestingObjectBaseType
private

Definition at line 73 of file RocstarTest.H.

Constructor & Destructor Documentation

TestingObject ( )
inline

Default constructor.

Definition at line 91 of file RocstarTest.H.

IRAD::Util::TestingObject< ResultsType > TestingObjectBaseType
Definition: RocstarTest.H:73

Member Function Documentation

virtual void Epilogue ( )
inlinevirtual

Tears down the testing fixtures if needed.

Definition at line 96 of file RocstarTest.H.

Referenced by TestingObject< ResultsType >::Process(), TestingObject< ResultsType >::ProcessTests(), and TestingObject< ResultsType >::RunTest().

96 {};

Here is the caller graph for this function:

double F1 ( double  x)
inline

Simple test function fixture returns $2x$.

F1 is a 1st order function in x that has unity integral over [0,1].

Definition at line 114 of file RocstarTest.H.

114 { return (2.0*x); };
void int int REAL * x
Definition: read.cpp:74
double F2 ( double  x)
inline

Simple test function fixture returns $3x^2$.

F2 is quadratic function in x and integrates to unity over [0,1].

Definition at line 120 of file RocstarTest.H.

120 { return (3.0*x*x); };
void int int REAL * x
Definition: read.cpp:74
virtual void Process ( ResultsType &  result)
inlinevirtual

Runs all tests implemented by the Rocstar::TestingObject.

Parameters
resultRocstar::TestResults object to store test results.

Definition at line 255 of file RocstarTest.H.

References TestingObject< ResultsType >::Epilogue(), TestingObject< ResultsType >::Prologue(), TestingObject< ResultsType >::Test__ExampleFunction(), TestingObject< ResultsType >::Test__MidPointQuadrature(), and TestingObject< ResultsType >::Test__TrapezoidQuadrature().

Referenced by Rocstar::Test().

255  {
256  Prologue();
257  Test__ExampleFunction(result);
259  Test__MidPointQuadrature(result);
260  Epilogue();
261  }
virtual void Test__MidPointQuadrature(ResultsType &result)
Test for Rocstar::MidPointQuadrature.
Definition: RocstarTest.H:207
virtual void Epilogue()
Tears down the testing fixtures if needed.
Definition: RocstarTest.H:96
virtual void Test__ExampleFunction(ResultsType &result)
Test for Rocstar::ExampleFunction.
Definition: RocstarTest.H:130
virtual void Prologue()
Sets up the data fixtures for the tests.
Definition: RocstarTest.H:105
virtual void Test__TrapezoidQuadrature(ResultsType &result)
Test for Rocstar::TrapezoidQuadrature.
Definition: RocstarTest.H:155

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void ProcessTests ( std::list< std::string > &  test_names,
ResultsType &  result 
)
inlinevirtual

Runs a list of tests specified by name.

Parameters
test_nameslist of string test names
resultRocstar::TestResults object to store test results.

Definition at line 287 of file RocstarTest.H.

References TestingObject< ResultsType >::Epilogue(), TestingObject< ResultsType >::Prologue(), and TestingObject< ResultsType >::RunTest().

287  {
288  Prologue();
289  std::list<std::string>::iterator tni = test_names.begin();
290  while(tni != test_names.end())
291  RunTest(*tni++,result);
292  Epilogue();
293  }
virtual void RunTest(const std::string &name, ResultsType &result)
Runs a test specified by name.
Definition: RocstarTest.H:269
virtual void Epilogue()
Tears down the testing fixtures if needed.
Definition: RocstarTest.H:96
virtual void Prologue()
Sets up the data fixtures for the tests.
Definition: RocstarTest.H:105

Here is the call graph for this function:

virtual void Prologue ( )
inlinevirtual

Sets up the data fixtures for the tests.

This function gives the object a chance to allocate and set up any "fixtures" before the tests are run.

Definition at line 105 of file RocstarTest.H.

References TestingObject< ResultsType >::ExampleTestFixture, i, and TestingObject< ResultsType >::N.

Referenced by TestingObject< ResultsType >::Process(), TestingObject< ResultsType >::ProcessTests(), and TestingObject< ResultsType >::RunTest().

105  {
106  ExampleTestFixture.assign("ExampleTestData");
107  for(int i = 10;i < 10000000;i*=10) N.push_back(i);
108  }
std::vector< int > N
A set of values for testing quadrature methods.
Definition: RocstarTest.H:86
blockLoc i
Definition: read.cpp:79
std::string ExampleTestFixture
A sample string test fixture.
Definition: RocstarTest.H:82

Here is the caller graph for this function:

virtual void RunTest ( const std::string &  name,
ResultsType &  result 
)
inlinevirtual

Runs a test specified by name.

Parameters
nameString name of the test to run.
resultRocstar::TestResults object to store test results.

Definition at line 269 of file RocstarTest.H.

References TestingObject< ResultsType >::Epilogue(), TestingObject< ResultsType >::Prologue(), TestingObject< ResultsType >::Test__ExampleFunction(), TestingObject< ResultsType >::Test__MidPointQuadrature(), and TestingObject< ResultsType >::Test__TrapezoidQuadrature().

Referenced by TestingObject< ResultsType >::ProcessTests(), and Rocstar::Test().

270  {
271  Prologue();
272  if(name == "ExampleFunction")
273  Test__ExampleFunction(result);
274  else if(name == "TrapezoidQuadrature")
276  else if(name == "MidPointQuadrature")
277  Test__MidPointQuadrature(result);
278  Epilogue();
279  }
virtual void Test__MidPointQuadrature(ResultsType &result)
Test for Rocstar::MidPointQuadrature.
Definition: RocstarTest.H:207
virtual void Epilogue()
Tears down the testing fixtures if needed.
Definition: RocstarTest.H:96
virtual void Test__ExampleFunction(ResultsType &result)
Test for Rocstar::ExampleFunction.
Definition: RocstarTest.H:130
virtual void Prologue()
Sets up the data fixtures for the tests.
Definition: RocstarTest.H:105
virtual void Test__TrapezoidQuadrature(ResultsType &result)
Test for Rocstar::TrapezoidQuadrature.
Definition: RocstarTest.H:155

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Test__ExampleFunction ( ResultsType &  result)
inlinevirtual

Test for Rocstar::ExampleFunction.

Parameters
resultRocstar::TestResults object to store test results.

This function implements a simple test of the function Rocstar::ExampleFunction - which is designed to simply return a copy of the input string.

Definition at line 130 of file RocstarTest.H.

References GridConversion::ExampleFunction(), and TestingObject< ResultsType >::ExampleTestFixture.

Referenced by TestingObject< ResultsType >::Process(), and TestingObject< ResultsType >::RunTest().

130  {
131  // This is an actual test of the function called
132  // ExampleFunction. The name Test__XXXXX will
133  // eventually help automated utilities with
134  // running tests by name.
135  std::string ExampleResult(ExampleFunction(ExampleTestFixture));
136  result.UpdateResult("ExampleFunction:Works",
137  ExampleResult == ExampleTestFixture);
138  result.UpdateResult("ExampleFunction:Fails",
139  ExampleResult != ExampleTestFixture);
140  }
std::string ExampleFunction(const std::string &instring)
Example function for GridConversion (this is a brief description).
std::string ExampleTestFixture
A sample string test fixture.
Definition: RocstarTest.H:82

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Test__MidPointQuadrature ( ResultsType &  result)
inlinevirtual

Test for Rocstar::MidPointQuadrature.

Parameters
resultRocstar::TestResults object to store test results.

This function implements a simple test of the function Rocstar::MidPointQuadrature - which is designed to integrate a function, f, over an interval $[x_0,x_n]$.

The test first makes sure that the method integrates a linear function exactly, and then that the error term has the proper dependence on the spacings.

Definition at line 207 of file RocstarTest.H.

References NTS::abs(), Rocstar::TestFixture::F1(), Rocstar::TestFixture::F2(), i, cimg_library::log(), GridConversion::MidPointQuadrature(), n, and TestingObject< ResultsType >::N.

Referenced by TestingObject< ResultsType >::Process(), and TestingObject< ResultsType >::RunTest().

207  {
208  std::ostringstream Ostr;
209  std::vector<double> Ibar;
210  std::vector<double> E;
211  size_t n = 2*N.size();
212  bool runs = true;
213  bool order2 = true;
214  for(std::vector<int>::iterator i = N.begin();i != N.end();i++){
215  double Ii = 0.0;
216  try {
218  } catch (...) {
219  runs = false;
220  }
221  Ibar.push_back(Ii);
222  E.push_back(std::fabs(Ii-1.0));
223  }
224  order2 = (E[0] < 1e-14);
225  for(std::vector<int>::iterator i = N.begin();i != N.end();i++){
226  double Ii = 0.0;
227  try {
229  } catch (...) {
230  runs = false;
231  }
232  Ibar.push_back(Ii);
233  E.push_back(std::fabs(Ii-1.0));
234  }
235  result.UpdateResult("MidPointQuadrature:Runs",runs);
236  result.UpdateResult("MidPointQuadrature:Accurate",E[n-1] < 1e-12);
237  for(int i = N.size();i < n - 1;i++){
238  double e = E[i+1]/E[i];
239  double n1 = static_cast<double>(N[i-N.size()])/static_cast<double>(N[(i-N.size())+1]);
240  double p = std::log(e)/std::log(n1);
241  p -= 2;
242  p = std::abs(p);
243  if(p > 1e-2){
244  order2 = false;
245  }
246  }
247  result.UpdateResult("MidPointQuadrature:Order2",order2);
248  }
std::vector< int > N
A set of values for testing quadrature methods.
Definition: RocstarTest.H:86
double F1(double x)
Simple test function fixture returns .
Definition: RocstarTest.H:34
double F2(double x)
Simple test function fixture returns .
Definition: RocstarTest.H:40
CImg< _cimg_Tfloat > log(const CImg< T > &instance)
Definition: CImg.h:6021
blockLoc i
Definition: read.cpp:79
double MidPointQuadrature(double(*f)(double), double x0, double xn, int n)
Integrates f with composite midpoint rule.
const NT & n
NT abs(const NT &x)
Definition: number_utils.h:130

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Test__TrapezoidQuadrature ( ResultsType &  result)
inlinevirtual

Test for Rocstar::TrapezoidQuadrature.

Parameters
resultRocstar::TestResults object to store test results.

This function implements a simple test of the function Rocstar::TrapezoidQuadrature - which is designed to integrate a function, f, over an n-way partitioned interval $[x_0,x_n]$ .

The test first makes sure that the method integrates a linear function exactly, and then that the error term has the proper dependence on the spacings.

Definition at line 155 of file RocstarTest.H.

References NTS::abs(), Rocstar::TestFixture::F1(), Rocstar::TestFixture::F2(), i, cimg_library::log(), n, TestingObject< ResultsType >::N, and GridConversion::TrapezoidQuadrature().

Referenced by TestingObject< ResultsType >::Process(), and TestingObject< ResultsType >::RunTest().

155  {
156  std::ostringstream Ostr;
157  std::vector<double> E;
158  size_t n = 2*N.size();
159  bool runs = true;
160  for(std::vector<int>::iterator i = N.begin();i != N.end();i++){
161  double Ii = 0.0;
162  try {
164  } catch (...) {
165  runs = false;
166  }
167  E.push_back(std::fabs(Ii-1.0));
168  }
169  bool order2 = (E[0] < 1e-14);
170  for(std::vector<int>::iterator i = N.begin();i != N.end();i++){
171  double Ii = 0.0;
172  try {
174  } catch (...) {
175  runs = false;
176  }
177  E.push_back(std::fabs(Ii-1.0));
178  }
179  result.UpdateResult("TrapezoidQuadrature:Runs",runs);
180  result.UpdateResult("TrapezoidQuadrature:Accurate",E[n-1] < 1e-12);
181  for(int i = N.size();i < n - 1;i++){
182  double e = E[i+1]/E[i];
183  double n1 = static_cast<double>(N[i-N.size()])/static_cast<double>(N[(i-N.size())+1]);
184  double p = std::log(e)/std::log(n1);
185  p -= 2;
186  p = std::abs(p);
187  if(p > 2e-2){
188  order2 = false;
189  }
190  }
191  result.UpdateResult("TrapezoidQuadrature:Order2",order2);
192  }
double TrapezoidQuadrature(double(*f)(double), double x0, double xn, int n)
Integrates f with composite trapezoid rule.
std::vector< int > N
A set of values for testing quadrature methods.
Definition: RocstarTest.H:86
double F1(double x)
Simple test function fixture returns .
Definition: RocstarTest.H:34
double F2(double x)
Simple test function fixture returns .
Definition: RocstarTest.H:40
CImg< _cimg_Tfloat > log(const CImg< T > &instance)
Definition: CImg.h:6021
blockLoc i
Definition: read.cpp:79
const NT & n
NT abs(const NT &x)
Definition: number_utils.h:130

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

std::string ExampleTestFixture
protected

A sample string test fixture.

Definition at line 82 of file RocstarTest.H.

Referenced by TestingObject< ResultsType >::Prologue(), and TestingObject< ResultsType >::Test__ExampleFunction().

std::vector<int> N
protected

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