10 #ifndef OSISOLVERINTERFACETEST_HPP_
11 #define OSISOLVERINTERFACETEST_HPP_
39 (
const std::vector<OsiSolverInterface*> & vecEmptySiP,
40 const std::string& mpsDir);
48 const std::string& mpsDir,
49 const std::string& netlibDir);
54 const std::string & mpsDir);
59 const std::string & mpsDir);
64 const std::string & mpsDir);
70 namespace OsiUnitTest {
103 const std::string &message) ;
106 const std::string &message) ;
115 const std::string &testname,
const std::string &testcond) ;
119 const std::string &testname,
const std::string &testcond) ;
135 double tol,
const double * v1,
const double * v2,
int size) ;
162 std::map<std::string,std::string>& parms,
163 const std::map<std::string,int>& ignorekeywords = std::map<std::string,int>());
195 const char* file,
int line,
bool exp =
false)
207 void add(std::string comp, std::string tst,
const char* cond,
210 { push_back(
TestOutcome(comp,tst,cond,sev,file,line,exp)); }
227 int& total,
int& expected)
const;
231 #define OSIUNITTEST_QUOTEME_(x) #x
232 #define OSIUNITTEST_QUOTEME(x) OSIUNITTEST_QUOTEME_(x)
235 template <
typename Component>
237 bool condition,
const char * condition_str,
const char *filename,
238 int line,
const Component& component,
const std::string& testname,
245 std::ostringstream successmsg;
246 successmsg << __FILE__ <<
":" << __LINE__ <<
": " << testname
247 <<
" (condition \'" << condition_str <<
"\') passed.\n";
253 severity, filename, line, expected);
259 { std::cout << std::endl <<
"press any key to continue..." << std::endl;
268 #define OSIUNITTEST_ADD_OUTCOME(component,testname,testcondition,severity,expected) \
269 OsiUnitTest::outcomes.add(component,testname,testcondition,severity,\
270 __FILE__,__LINE__,expected)
281 #define OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition,failurecode,component,\
282 testname, severity, expected) \
284 if (!OsiUnitTestAssertSeverityExpected(condition, #condition, \
285 __FILE__, __LINE__, component, testname, severity, expected)) { \
293 #define OSIUNITTEST_ASSERT_ERROR(condition, failurecode, component, testname) \
294 OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition,failurecode,component,testname,\
295 OsiUnitTest::TestOutcome::ERROR,false)
300 #define OSIUNITTEST_ASSERT_WARNING(condition, failurecode, component, testname) \
301 OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition,failurecode,component,testname,\
302 OsiUnitTest::TestOutcome::WARNING,false)
314 #define OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname,\
315 severity, expected) \
319 OSIUNITTEST_ADD_OUTCOME(component,testname,#trycode " did not throw exception",\
320 OsiUnitTest::TestOutcome::PASSED,false); \
321 if (OsiUnitTest::verbosity >= 2) { \
322 std::string successmsg( __FILE__ ":" OSIUNITTEST_QUOTEME(__LINE__) ": "); \
323 successmsg = successmsg + testname; \
324 successmsg = successmsg + " (code \'" #trycode "\') did not throw exception"; \
325 successmsg = successmsg + ".\n" ; \
326 OsiUnitTest::testingMessage(successmsg.c_str()); \
328 } catch (CoinError& e) { \
329 std::stringstream errmsg; \
330 errmsg << #trycode " threw CoinError: " << e.message(); \
331 if (e.className().length() > 0) \
332 errmsg << " in " << e.className(); \
333 if (e.methodName().length() > 0) \
334 errmsg << " in " << e.methodName(); \
335 if (e.lineNumber() >= 0) \
336 errmsg << " at " << e.fileName() << ":" << e.lineNumber(); \
337 OSIUNITTEST_ADD_OUTCOME(component,testname,errmsg.str().c_str(),\
338 severity,expected); \
339 OsiUnitTest::failureMessage(component,testname,errmsg.str().c_str()); \
340 switch(OsiUnitTest::haltonerror) { \
342 { if (severity >= OsiUnitTest::TestOutcome::ERROR) abort(); break; } \
344 { std::cout << std::endl << "press any key to continue..." << std::endl; \
351 std::string errmsg; \
353 errmsg = errmsg + " threw unknown exception"; \
354 OSIUNITTEST_ADD_OUTCOME(component,testname,errmsg.c_str(),severity,false); \
355 OsiUnitTest::failureMessage(component,testname,errmsg.c_str()); \
363 #define OSIUNITTEST_CATCH_ERROR(trycode, catchcode, component, testname) \
364 OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, OsiUnitTest::TestOutcome::ERROR, false)
369 #define OSIUNITTEST_CATCH_WARNING(trycode, catchcode, component, testname) \
370 OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, OsiUnitTest::TestOutcome::WARNING, false)
std::string testname
Name of test.
SeverityLevel severity
Test result.
void testingMessage(const char *const msg)
Print a message.
TestOutcomes outcomes
Test outcomes.
Utility class to maintain a list of test outcomes.
bool isEquivalent(const CoinPackedVectorBase &pv, int n, const double *fv)
Compare a packed vector with an expanded vector.
Abstract base class for various sparse vectors.
bool processParameters(int argc, const char **argv, std::map< std::string, std::string > &parms, const std::map< std::string, int > &ignorekeywords=std::map< std::string, int >())
Process command line parameters.
A single test outcome record.
std::string component
Name of component under test.
SeverityLevel
Test result.
unsigned int haltonerror
Behaviour on failing a test.
void print() const
Print the test outcome.
void OsiSolverInterfaceCommonUnitTest(const OsiSolverInterface *emptySi, const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiSolverInterface class.
TestOutcome(const std::string &comp, const std::string &tst, const char *cond, SeverityLevel sev, const char *file, int line, bool exp=false)
Standard constructor.
void OsiSolverInterfaceMpsUnitTest(const std::vector< OsiSolverInterface * > &vecEmptySiP, const std::string &mpsDir)
A function that tests that a lot of problems given in MPS files (mostly the NETLIB problems) solve pr...
unsigned int verbosity
Verbosity level of unit tests.
void OsiColCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiColCut class.
std::string testcond
Condition being tested.
Abstract Base Class for describing an interface to a solver.
bool equivalentVectors(const OsiSolverInterface *si1, const OsiSolverInterface *si2, double tol, const double *v1, const double *v2, int size)
Utility method to check equality.
static std::string SeverityLevelName[LAST]
Print strings for SeverityLevel.
int linenumber
Line number in code file where test executed.
void OsiRowCutDebuggerUnitTest(const OsiSolverInterface *siP, const std::string &mpsDir)
A function that tests the methods in the OsiRowCutDebugger class.
bool OsiUnitTestAssertSeverityExpected(bool condition, const char *condition_str, const char *filename, int line, const Component &component, const std::string &testname, TestOutcome::SeverityLevel severity, bool expected)
void add(std::string comp, std::string tst, const char *cond, TestOutcome::SeverityLevel sev, const char *file, int line, bool exp=false)
Add an outcome to the list.
void print() const
Print the list of outcomes.
bool compareProblems(OsiSolverInterface *osi1, OsiSolverInterface *osi2)
Compare two problems for equality.
void OsiRowCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiRowCut class.
std::string filename
Name of code file where test executed.
void failureMessage(const std::string &solverName, const std::string &message)
Print an error message.
void OsiCutsUnitTest()
A function that tests the methods in the OsiCuts class.
bool expected
Set to true if problem is expected.
void getCountBySeverity(TestOutcome::SeverityLevel sev, int &total, int &expected) const
Count total and expected outcomes at given severity level.