10 #ifndef OSISOLVERINTERFACETEST_HPP_
11 #define OSISOLVERINTERFACETEST_HPP_
39 const std::string &mpsDir);
46 const std::string &mpsDir,
47 const std::string &netlibDir);
51 const std::string &mpsDir);
55 const std::string &mpsDir);
59 const std::string &mpsDir);
65 namespace OsiUnitTest {
98 const std::string &message);
101 const std::string &message);
110 const std::string &testname,
const std::string &testcond);
114 const std::string &testname,
const std::string &testcond);
130 double tol,
const double *v1,
const double *v2,
int size);
157 std::map< std::string, std::string > &parms,
158 const std::map< std::string, int > &ignorekeywords = std::map< std::string, int >());
190 const char *file,
int line,
bool exp =
false)
208 void add(std::string comp, std::string tst,
const char *cond,
212 push_back(
TestOutcome(comp, tst, cond, sev, file, line, exp));
230 int &total,
int &expected)
const;
234 #define OSIUNITTEST_QUOTEME_(x) #x
235 #define OSIUNITTEST_QUOTEME(x) OSIUNITTEST_QUOTEME_(x)
238 template <
typename Component >
240 bool condition,
const char *condition_str,
const char *filename,
241 int line,
const Component &component,
const std::string &testname,
248 std::ostringstream successmsg;
249 successmsg << __FILE__ <<
":" << __LINE__ <<
": " << testname
250 <<
" (condition \'" << condition_str <<
"\') passed.\n";
256 severity, filename, line, expected);
265 std::cout << std::endl
266 <<
"press any key to continue..." << std::endl;
276 #define OSIUNITTEST_ADD_OUTCOME(component, testname, testcondition, severity, expected) \
277 OsiUnitTest::outcomes.add(component, testname, testcondition, severity, \
278 __FILE__, __LINE__, expected)
289 #define OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition, failurecode, component, \
290 testname, severity, expected) \
292 if (!OsiUnitTestAssertSeverityExpected(condition, #condition, \
293 __FILE__, __LINE__, component, testname, severity, expected)) { \
301 #define OSIUNITTEST_ASSERT_ERROR(condition, failurecode, component, testname) \
302 OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition, failurecode, component, testname, \
303 OsiUnitTest::TestOutcome::ERROR, false)
308 #define OSIUNITTEST_ASSERT_WARNING(condition, failurecode, component, testname) \
309 OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition, failurecode, component, testname, \
310 OsiUnitTest::TestOutcome::WARNING, false)
322 #define OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, \
323 severity, expected) \
327 OSIUNITTEST_ADD_OUTCOME(component, testname, #trycode " did not throw exception", \
328 OsiUnitTest::TestOutcome::PASSED, false); \
329 if (OsiUnitTest::verbosity >= 2) { \
330 std::string successmsg(__FILE__ ":" OSIUNITTEST_QUOTEME(__LINE__) ": "); \
331 successmsg = successmsg + testname; \
332 successmsg = successmsg + " (code \'" #trycode "\') did not throw exception"; \
333 successmsg = successmsg + ".\n"; \
334 OsiUnitTest::testingMessage(successmsg.c_str()); \
336 } catch (CoinError & e) { \
337 std::stringstream errmsg; \
338 errmsg << #trycode " threw CoinError: " << e.message(); \
339 if (e.className().length() > 0) \
340 errmsg << " in " << e.className(); \
341 if (e.methodName().length() > 0) \
342 errmsg << " in " << e.methodName(); \
343 if (e.lineNumber() >= 0) \
344 errmsg << " at " << e.fileName() << ":" << e.lineNumber(); \
345 OSIUNITTEST_ADD_OUTCOME(component, testname, errmsg.str().c_str(), \
346 severity, expected); \
347 OsiUnitTest::failureMessage(component, testname, errmsg.str().c_str()); \
348 switch (OsiUnitTest::haltonerror) { \
350 if (severity >= OsiUnitTest::TestOutcome::ERROR) \
355 std::cout << std::endl \
356 << "press any key to continue..." << std::endl; \
364 std::string errmsg; \
366 errmsg = errmsg + " threw unknown exception"; \
367 OSIUNITTEST_ADD_OUTCOME(component, testname, errmsg.c_str(), severity, false); \
368 OsiUnitTest::failureMessage(component, testname, errmsg.c_str()); \
376 #define OSIUNITTEST_CATCH_ERROR(trycode, catchcode, component, testname) \
377 OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, OsiUnitTest::TestOutcome::ERROR, false)
382 #define OSIUNITTEST_CATCH_WARNING(trycode, catchcode, component, testname) \
383 OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, OsiUnitTest::TestOutcome::WARNING, false)
bool compareProblems(OsiSolverInterface *osi1, OsiSolverInterface *osi2)
Compare two problems for equality.
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.
void OsiCutsUnitTest()
A function that tests the methods in the OsiCuts class.
void OsiRowCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiRowCut class.
void OsiColCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiColCut class.
std::string filename
Name of code file where test executed.
SeverityLevel severity
Test result.
unsigned int verbosity
Verbosity level of unit tests.
bool isEquivalent(const CoinPackedVectorBase &pv, int n, const double *fv)
Compare a packed vector with an expanded vector.
Utility class to maintain a list of test outcomes.
TestOutcome(const std::string &comp, const std::string &tst, const char *cond, SeverityLevel sev, const char *file, int line, bool exp=false)
Standard constructor.
int linenumber
Line number in code file where test executed.
bool expected
Set to true if problem is expected.
void OsiRowCutDebuggerUnitTest(const OsiSolverInterface *siP, const std::string &mpsDir)
A function that tests the methods in the OsiRowCutDebugger class.
Abstract Base Class for describing an interface to a solver.
Abstract base class for various sparse vectors.
void getCountBySeverity(TestOutcome::SeverityLevel sev, int &total, int &expected) const
Count total and expected outcomes at given severity level.
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.
std::string testcond
Condition being tested.
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)
unsigned int haltonerror
Behaviour on failing a test.
TestOutcomes outcomes
Test outcomes.
A single test outcome record.
void print() const
Print the test outcome.
void testingMessage(const char *const msg)
Print a message.
std::string testname
Name of test.
std::string component
Name of component under test.
SeverityLevel
Test result.
void OsiSolverInterfaceCommonUnitTest(const OsiSolverInterface *emptySi, const std::string &mpsDir, const std::string &netlibDir)
A function that tests the methods in the OsiSolverInterface class.
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...
static std::string SeverityLevelName[LAST]
Print strings for SeverityLevel.
void failureMessage(const std::string &solverName, const std::string &message)
Print an error message.
bool equivalentVectors(const OsiSolverInterface *si1, const OsiSolverInterface *si2, double tol, const double *v1, const double *v2, int size)
Utility method to check equality.