source: trunk/Clp/test/osiUnitTest.cpp @ 1740

Last change on this file since 1740 was 1740, checked in by stefan, 8 years ago

convert osi unittest to use new TestOutcomes? facility

File size: 4.2 KB
Line 
1// $Id$
2// Copyright (C) 2000, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#include "CoinPragma.hpp"
7#include "OsiConfig.h"
8
9#include <cstdio>
10#include <iostream>
11
12#include "OsiUnitTests.hpp"
13#include "OsiRowCutDebugger.hpp"
14#include "OsiRowCut.hpp"
15#include "OsiColCut.hpp"
16
17#include "CoinError.hpp"
18
19#include "OsiClpSolverInterface.hpp"
20
21using namespace OsiUnitTest;
22
23//----------------------------------------------------------------
24// unitTest [-nobuf] [-mpsDir=V1] [-netlibDir=V2] [-testOsiSolverInterface]
25//      [-cutsOnly]
26//
27// where:
28//   -nobuf: remove buffering on cout (stdout); useful to keep cout and cerr
29//   messages synchronised when redirecting output to a file or pipe.
30//   -mpsDir: directory containing mps test files
31//       Default value V1="../../Data/Sample"   
32//   -netlibDir: directory containing netlib files
33//       Default value V2="../../Data/Netlib"
34//   -testOsiSolverInterface
35//       If specified, then OsiSolveInterface::unitTest
36//       is skipped over and not run.
37//   -cutsOnly
38//   If specified, only OsiCut tests are run.
39//
40// All parameters are optional.
41//----------------------------------------------------------------
42
43int main (int argc, const char *argv[])
44{
45  bool exception = false;
46  outcomes.clear();
47
48/*
49  Start off with various bits of initialisation that don't really belong
50  anywhere else.
51
52  First off, synchronise C++ stream i/o with C stdio. This makes debugging
53  output a bit more comprehensible. It still suffers from interleave of cout
54  (stdout) and cerr (stderr), but -nobuf deals with that.
55*/
56  std::ios::sync_with_stdio() ;
57/*
58  Suppress an popup window that Windows shows in response to a crash. See
59  note at head of file.
60*/
61  WindowsErrorPopupBlocker();
62
63/*
64  Process command line parameters.
65*/
66  std::map<std::string,std::string> parms;
67  if (processParameters(argc,argv,parms) == false)
68  { return (1) ; }
69
70  std::string mpsDir = parms["-mpsDir"] ;
71  std::string netlibDir = parms["-netlibDir"] ;
72
73  try {
74    /*
75      Test Osi{Row,Col}Cut routines.
76    */
77    {
78      OsiClpSolverInterface clpSi;
79      testingMessage( "Testing OsiRowCut with OsiClpSolverInterface\n" );
80      OsiRowCutUnitTest(&clpSi,mpsDir);
81    }
82    {
83      OsiClpSolverInterface clpSi;
84      testingMessage( "Testing OsiColCut with OsiClpSolverInterface\n" );
85      OsiColCutUnitTest(&clpSi,mpsDir);
86    }
87    {
88      OsiClpSolverInterface clpSi;
89      testingMessage( "Testing OsiRowCutDebugger with OsiClpSolverInterface\n" );
90      OsiRowCutDebuggerUnitTest(&clpSi,mpsDir);
91    }
92
93    /*
94      Run the OsiXXX class test. It's up to the OsiClp implementor
95      to decide whether or not to run OsiSolverInterfaceCommonUnitTest. Arguably
96      this should be required.
97    */
98    testingMessage( "Testing OsiClpSolverInterface\n" );
99    OsiClpSolverInterfaceUnitTest(mpsDir,netlibDir);
100
101    /*
102      We have run the specialised unit test. Check now to see if we need to
103      run through the Netlib problems.
104    */
105    if (parms.find("-testOsiSolverInterface") != parms.end())
106    {
107      // Create vector of solver interfaces
108      std::vector<OsiSolverInterface*> vecSi(1, new OsiClpSolverInterface);
109
110      testingMessage( "Testing OsiSolverInterface on Netlib problems.\n" );
111      OsiSolverInterfaceMpsUnitTest(vecSi,netlibDir);
112
113      delete vecSi[0];
114    }
115    else {
116      testingMessage( "***Skipped Testing of OsiClpSolverInterface on Netlib problems***\n" );
117      testingMessage( "***use -testOsiSolverInterface to run them.***\n" );
118    }
119  } catch (CoinError& error) {
120    std::cout.flush();
121    std::cerr << "Caught CoinError exception: ";
122    error.print(true);
123    exception = true;
124  }
125
126  /*
127    We're done. Report on the results.
128  */
129  std::cout.flush();
130  outcomes.print();
131
132  int nerrors;
133  int nerrors_expected;
134  outcomes.getCountBySeverity(TestOutcome::ERROR, nerrors, nerrors_expected);
135
136  if (nerrors > nerrors_expected)
137    std::cerr << "Tests completed with " << nerrors - nerrors_expected << " unexpected errors." << std::endl ;
138  else
139    std::cerr << "All tests completed successfully\n";
140
141  return (nerrors - nerrors_expected) + (exception ? 1 : 0);
142}
Note: See TracBrowser for help on using the repository browser.