# /home/coin/svn-release/Alps-1.5.2/Osi/src/OsiCommonTest/OsiUnitTests.hpp File Reference

`#include <cstdio>`
`#include <cstdlib>`
`#include <iostream>`
`#include <string>`
`#include <sstream>`
`#include <vector>`
`#include <list>`
`#include <map>`
Include dependency graph for OsiUnitTests.hpp:

Go to the source code of this file.

## Classes
class | OsiUnitTest::TestOutcome
| A single test outcome record. More...
class | OsiUnitTest::TestOutcomes
| Utility class to maintain a list of test outcomes. More...
## Namespaces
namespace | OsiUnitTest

| A namespace so we can define a few `global' variables to use during tests.
## Defines
#define | OSIUNITTEST_QUOTEME_(x) #x
| Convert parameter to a string (stringification).
#define | OSIUNITTEST_QUOTEME(x) OSIUNITTEST_QUOTEME_(x)
| Convert to string with one level of expansion of the parameter.
#define | OSIUNITTEST_ADD_OUTCOME(component, testname, testcondition, severity, expected)
| Add a test outcome to the list held in OsiUnitTest::outcomes.
#define | OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition, failurecode, component, testname, severity, expected)
| Test for a condition and record the result.
#define | OSIUNITTEST_ASSERT_ERROR(condition, failurecode, component, testname)
| Perform a test with severity OsiUnitTest::TestOutcome::ERROR, failure not expected.
#define | OSIUNITTEST_ASSERT_WARNING(condition, failurecode, component, testname)
| Perform a test with severity OsiUnitTest::TestOutcome::WARNING, failure not expected.
#define | OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, severity, expected)
| Perform a test surrounded by a try/catch block.
#define | OSIUNITTEST_CATCH_ERROR(trycode, catchcode, component, testname) OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, OsiUnitTest::TestOutcome::ERROR, false)
| Perform a try/catch test with severity OsiUnitTest::TestOutcome::ERROR, failure not expected.
#define | OSIUNITTEST_CATCH_WARNING(trycode, catchcode, component, testname) OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, OsiUnitTest::TestOutcome::WARNING, false)
| Perform a try/catch test with severity OsiUnitTest::TestOutcome::WARNING, failure not expected.
## Functions
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 properly with all the specified solvers.
void | OsiSolverInterfaceCommonUnitTest (const OsiSolverInterface *emptySi, const std::string &mpsDir, const std::string &netlibDir)
| A function that tests the methods in the OsiSolverInterface class.
void | OsiColCutUnitTest (const OsiSolverInterface *baseSiP, const std::string &mpsDir)
| A function that tests the methods in the OsiColCut class.
void | OsiRowCutUnitTest (const OsiSolverInterface *baseSiP, const std::string &mpsDir)
| A function that tests the methods in the OsiRowCut class.
void | OsiRowCutDebuggerUnitTest (const OsiSolverInterface *siP, const std::string &mpsDir)
| A function that tests the methods in the OsiRowCutDebugger class.
void | OsiCutsUnitTest ()
| A function that tests the methods in the OsiCuts class.
void | OsiUnitTest::failureMessage (const std::string &solverName, const std::string &message)
| Print an error message.
void | OsiUnitTest::failureMessage (const OsiSolverInterface &si, const std::string &message)
void | OsiUnitTest::failureMessage (const std::string &solverName, const std::string &testname, const std::string &testcond)
| Print an error message, specifying the test name and condition.
void | OsiUnitTest::failureMessage (const OsiSolverInterface &si, const std::string &testname, const std::string &testcond)
void | OsiUnitTest::testingMessage (const char *const msg)
| Print a message.
bool | OsiUnitTest::equivalentVectors (const OsiSolverInterface *si1, const OsiSolverInterface *si2, double tol, const double *v1, const double *v2, int size)
| Utility method to check equality.
bool | OsiUnitTest::compareProblems (OsiSolverInterface *osi1, OsiSolverInterface *osi2)
| Compare two problems for equality.
bool | OsiUnitTest::isEquivalent (const CoinPackedVectorBase &pv, int n, const double *fv)
| Compare a packed vector with an expanded vector.
bool | OsiUnitTest::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.
template<typename Component >
bool | OsiUnitTest::OsiUnitTestAssertSeverityExpected (bool condition, const char *condition_str, const char *filename, int line, const Component &component, const std::string &testname, TestOutcome::SeverityLevel severity, bool expected)
## Variables
unsigned int | OsiUnitTest::verbosity
| Verbosity level of unit tests.
unsigned int | OsiUnitTest::haltonerror
| Behaviour on failing a test.
TestOutcomes | OsiUnitTest::outcomes
| Test outcomes.

## Detailed Description

Utility methods for OSI unit tests.

Definition in file OsiUnitTests.hpp.

## Define Documentation

#define OSIUNITTEST_QUOTEME_ | ( | x |  | ) | #x

Convert parameter to a string (stringification).

Definition at line 231 of file OsiUnitTests.hpp.

#define OSIUNITTEST_QUOTEME | ( | x |  | ) | OSIUNITTEST_QUOTEME_(x)

Convert to string with one level of expansion of the parameter.

Definition at line 233 of file OsiUnitTests.hpp.

#define OSIUNITTEST_ADD_OUTCOME | ( | component,
|  | testname,
|  | testcondition,
|  | severity,
|  | expected |  | ) |

Value:

    OsiUnitTest::outcomes.add(component,testname,testcondition,severity,\
        __FILE__,__LINE__,expected)

Add a test outcome to the list held in OsiUnitTest::outcomes.

Definition at line 268 of file OsiUnitTests.hpp.

#define OSIUNITTEST_ASSERT_SEVERITY_EXPECTED | ( | condition,
|  | failurecode,
|  | component,
|  | testname,
|  | severity,
|  | expected |  | ) |

Value:

    { \
      if (!OsiUnitTestAssertSeverityExpected(condition, #condition, \
          __FILE__, __LINE__, component, testname, severity, expected)) { \
        failurecode; \
      } \
    }

Test for a condition and record the result.

Test `condition` and record the result in OsiUnitTest::outcomes. If it succeeds, record the result as OsiUnitTest::TestOutcome::PASSED and print a message for OsiUnitTest::verbosity >= 2. If it fails, record the test as failed with `severity` and `expected` and react as specified by OsiUnitTest::haltonerror.

`failurecode` is executed when failure is not fatal.

Definition at line 282 of file OsiUnitTests.hpp.

#define OSIUNITTEST_ASSERT_ERROR | ( | condition,
|  | failurecode,
|  | component,
|  | testname |  | ) |

Value:

    OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition,failurecode,component,testname,\
                                           OsiUnitTest::TestOutcome::ERROR,false)

Perform a test with severity OsiUnitTest::TestOutcome::ERROR, failure not expected.

Definition at line 293 of file OsiUnitTests.hpp.

#define OSIUNITTEST_ASSERT_WARNING | ( | condition,
|  | failurecode,
|  | component,
|  | testname |  | ) |

Value:

    OSIUNITTEST_ASSERT_SEVERITY_EXPECTED(condition,failurecode,component,testname,\
                                           OsiUnitTest::TestOutcome::WARNING,false)

Perform a test with severity OsiUnitTest::TestOutcome::WARNING, failure not expected.

Definition at line 300 of file OsiUnitTests.hpp.

#define OSIUNITTEST_CATCH_SEVERITY_EXPECTED | ( | trycode,
|  | catchcode,
|  | component,
|  | testname,
|  | severity,
|  | expected |  | ) |

Perform a test surrounded by a try/catch block.

`trycode` is executed in a try/catch block; if there's no throw the test is deemed to have succeeded and is recorded in OsiUnitTest::outcomes with status OsiUnitTest::TestOutcome::PASSED. If the `trycode` throws a CoinError, the failure is recorded with status `severity` and `expected` and the value of OsiUnitTest::haltonerror is consulted. If the failure is not fatal, `catchcode` is executed. If any other error is thrown, the failure is recorded as for a CoinError and `catchcode` is executed (haltonerror is not consulted).

Definition at line 315 of file OsiUnitTests.hpp.

#define OSIUNITTEST_CATCH_ERROR | ( | trycode,
|  | catchcode,
|  | component,
|  | testname |  | ) | OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, OsiUnitTest::TestOutcome::ERROR, false)

Perform a try/catch test with severity OsiUnitTest::TestOutcome::ERROR, failure not expected.

Definition at line 363 of file OsiUnitTests.hpp.

#define OSIUNITTEST_CATCH_WARNING | ( | trycode,
|  | catchcode,
|  | component,
|  | testname |  | ) | OSIUNITTEST_CATCH_SEVERITY_EXPECTED(trycode, catchcode, component, testname, OsiUnitTest::TestOutcome::WARNING, false)

Perform a try/catch test with severity OsiUnitTest::TestOutcome::WARNING, failure not expected.

Definition at line 369 of file OsiUnitTests.hpp.

## Function Documentation

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 properly with all the specified solvers.

The routine creates a vector of NetLib problems (problem name, objective, various other characteristics), and a vector of solvers to be tested.

Each solver is run on each problem. The run is deemed successful if the solver reports the correct problem size after loading and returns the correct objective value after optimization.

If multiple solvers are available, the results are compared pairwise against the results reported by adjacent solvers in the solver vector. Due to limitations of the volume solver, it must be the last solver in vecEmptySiP.

void OsiSolverInterfaceCommonUnitTest | ( | const OsiSolverInterface * | emptySi,
|  | const std::string & | mpsDir,
|  | const std::string & | netlibDir |
| ) |  |  |

A function that tests the methods in the OsiSolverInterface class.

Some time ago, if this method is compiled with optimization, the compilation took 10-15 minutes and the machine pages (has 256M core memory!)...

void OsiColCutUnitTest | ( | const OsiSolverInterface * | baseSiP,
|  | const std::string & | mpsDir |
| ) |  |  |

A function that tests the methods in the OsiColCut class.

void OsiRowCutUnitTest | ( | const OsiSolverInterface * | baseSiP,
|  | const std::string & | mpsDir |
| ) |  |  |

A function that tests the methods in the OsiRowCut class.

void OsiRowCutDebuggerUnitTest | ( | const OsiSolverInterface * | siP,
|  | const std::string & | mpsDir |
| ) |  |  |

A function that tests the methods in the OsiRowCutDebugger class.

void OsiCutsUnitTest | ( |  | ) |

A function that tests the methods in the OsiCuts class.