// TupleManager_t.cpp #include "TupleManager.h" #include #include #include using std::string; using std::cout; using std::cerr; using std::endl; //********************************************************************** int main( ) { string component = "TupleManager"; 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 << "Create tuple a." << endl; Tuple& a = TupleManager::tuple("a"); a.columnDirect("x",1.0); a.capture("x",1.0); a.storeCapturedData(); a.clearData(); a.capture("x",2.0); a.storeCapturedData(); a.clearData(); a.capture("x",2.0); a.storeCapturedData(); a.clearData(); a.capture("x",3.0); a.storeCapturedData(); a.clearData(); //******************************************************************** cout << ok_prefix << "Create tuple b." << endl; string bstr = "b"; Tuple& b = TupleManager::tuple(bstr); b.columnDirect("x",1.0); b.columnDirect("y",1.0); for ( int i=0; i<=10; ++i ) { double x = double(i); b.capture("x",x); b.capture("y",x*x); b.storeCapturedData(); b.clearData(); } // finish a a.capture("x",3.0); a.storeCapturedData(); a.clearData(); a.capture("x",3.0); a.storeCapturedData(); a.clearData(); cout << "a has 6 entries." << endl; cout << "b has 11 entries." << endl; #ifndef NO_HEPTUPLE assert( a.nrows() == 6 ); assert( b.nrows() == 11 ); #endif //******************************************************************** cout << ok_prefix << "Check titles." << endl; cout << "Titles: " << a.title() << " " << b.title() << endl; assert( a.title() == "a" ); assert( b.title() == "b" ); //******************************************************************** cout << ok_prefix << "Reopen a histogram." << endl; Tuple& aa = TupleManager::tuple("a"); assert( &a == &aa ); //******************************************************************** cout << ok_prefix << "Check existence." << endl; assert( TupleManager::is_tuple("a") ); assert( ! TupleManager::is_tuple("c") ); //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }