// RootFinder_t.cpp #include "RootFinder.h" #include #include #include using std::string; using std::cout; using std::cerr; using std::endl; // Test interface -- this is not a true root finder. class RootFinderTest : public RootFinder { public: RootFinderTest() { }; ~RootFinderTest() { }; StatusDouble evaluate(double x) const { return StatusDouble(1,x); }; StatusDouble solve(double x1, double x2) const { return StatusDouble(2,x1*x2); }; }; //********************************************************************** int main( ) { string component = "RootFinder"; string ok_prefix = component + " (I): "; string error_prefix = component + " test (E): "; cout << ok_prefix << "---------- Testing component " + component + ". ----------" << endl; // Make sure assert is enabled. bool assert_flag = false; assert ( ( assert_flag = true, assert_flag ) ); if ( ! assert_flag ) { cerr << "Assert is disabled" << endl; return 1; } //******************************************************************** cout << ok_prefix << "Test interface." << endl; const RootFinderTest rfind; StatusDouble eval = rfind.evaluate(3.2); StatusDouble soln = rfind.solve(2.34,5.67); assert( eval.status() == 1 ); assert( eval.value() == 3.2 ); assert( soln.status() == 2 ); assert( soln.value() == 2.34*5.67 ); //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }