File: unitTest.cpp

package info (click to toggle)
coinutils 2.11.4%2Brepack1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,212 kB
  • sloc: cpp: 73,714; sh: 11,224; makefile: 276; ansic: 35
file content (229 lines) | stat: -rw-r--r-- 6,737 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// Copyright (C) 2000, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

// Test individual classes or groups of classes

#ifdef NDEBUG
#undef NDEBUG
#endif

#include <cassert>
#include <iostream>

#include "CoinPragma.hpp"
#include "CoinFinite.hpp"
#include "CoinError.hpp"
#include "CoinHelperFunctions.hpp"
#include "CoinSort.hpp"
#include "CoinShallowPackedVector.hpp"
#include "CoinPackedVector.hpp"
#include "CoinDenseVector.hpp"
#include "CoinIndexedVector.hpp"
#include "CoinPackedMatrix.hpp"
#include "CoinMpsIO.hpp"
#include "CoinLpIO.hpp"
#include "CoinMessageHandler.hpp"
void CoinModelUnitTest(const std::string & mpsDir,
                       const std::string & netlibDir, const std::string & testModel);
// Function Prototypes. Function definitions is in this file.
void testingMessage( const char * const msg );

//----------------------------------------------------------------
// unitTest [-mpsDir=V1] [-netlibDir=V2] [-testModel=V3]
// 
// where (unix defaults):
//   -mpsDir: directory containing mps test files
//       Default value V1="../../Data/Sample"    
//   -netlibDir: directory containing netlib files
//       Default value V2="../../Data/Netlib"
//   -testModel: name of model in netlibdir for testing CoinModel
//       Default value V3="25fv47.mps"
//
// All parameters are optional.
//----------------------------------------------------------------

int main (int argc, const char *argv[])
{
  /*
    Set default location for Data directory, assuming traditional
    package layout.
  */
  const char dirsep =  CoinFindDirSeparator();
  std::string dataDir ;
  if (dirsep == '/')
    dataDir = "../../Data" ;
  else
    dataDir = "..\\..\\Data" ;
# ifdef COIN_MSVS
    // Visual Studio builds are deeper.
    dataDir = "..\\..\\"+dataDir ;
# endif
  // define valid parameter keywords
  std::set<std::string> definedKeyWords;
  // Really should be sampleDir, but let's not rock the boat.
  definedKeyWords.insert("-mpsDir");
  // Directory for netlib problems.
  definedKeyWords.insert("-netlibDir");
  // Allow for large named model for CoinModel
  definedKeyWords.insert("-testModel");
  /*
    Set parameter defaults.
  */
  std::string mpsDir = dataDir + dirsep + "Sample" + dirsep ;
  std::string netlibDir = dataDir + dirsep + "Netlib" + dirsep ;
  std::string testModel = "p0033.mps" ;
  /*
    Process command line parameters. Assume params of the
    form 'keyword' or 'keyword=value'.
  */
  std::map<std::string,std::string> parms;
  for (int i = 1 ;  i < argc ; i++) {
    std::string parm(argv[i]);
    std::string key,value;
    std::string::size_type eqPos = parm.find('=');
    if (eqPos == std::string::npos) {
      key = parm ;
      value = "" ;
    }
    else {
      key = parm.substr(0,eqPos) ;
      value = parm.substr(eqPos+1) ;
    }
  /*
    Check for valid keyword. Print help and exit on failure.
  */
    if (definedKeyWords.find(key) == definedKeyWords.end()) {
      std::cerr
	  << "Undefined parameter \"" << key << "\".\n"
	  << "Correct usage: \n"
	  << "  unitTest [-mpsDir=V1] [-netlibDir=V2] [-testModel=V3]\n"
	  << "where:\n"
	  << "  -mpsDir: directory containing mps test files\n"
	  << "        Default value V1=\"" << mpsDir << "\"\n"
	  << "  -netlibDir: directory containing netlib files\n"
	  << "        Default value V2=\"" << netlibDir << "\"\n"
	  << "  -testModel: name of model testing CoinModel\n"
	  << "        Default value V3=\"" << testModel << "\"\n";
      return 1 ;
    }
    parms[key] = value ;
  }
  // Deal with any values given on the command line 
  if (parms.find("-mpsDir") != parms.end())
    mpsDir = parms["-mpsDir"] + dirsep;
  if (parms.find("-netlibDir") != parms.end())
    netlibDir = parms["-netlibDir"] + dirsep;
  if (parms.find("-testModel") != parms.end())
    testModel = parms["-testModel"] ;

  bool allOK = true ;

  // *FIXME* : these tests should be written... 
  //  testingMessage( "Testing CoinHelperFunctions\n" );
  //  CoinHelperFunctionsUnitTest();
  //  testingMessage( "Testing CoinSort\n" );
  //  tripleCompareUnitTest();

/*
  Check that finite and isnan are working.
*/
  double finiteVal = 1.0 ;
  double zero = 0.0 ;
  double checkVal ;

  testingMessage( "Testing CoinFinite ... " ) ;
# ifdef COIN_C_FINITE
  checkVal = finiteVal/zero ;
# else
  checkVal = COIN_DBL_MAX ;
# endif
  testingMessage( " finite value: " ) ;
  if (CoinFinite(finiteVal))
  { testingMessage( "ok" ) ; }
  else
  { allOK = false ;
    testingMessage( "ERROR" ) ; }
  testingMessage( "; infinite value: " ) ;
  if (!CoinFinite(checkVal))
  { testingMessage( "ok.\n" ) ; }
  else
  { allOK = false ;
    testingMessage( "ERROR.\n" ) ; }

# ifdef COIN_C_ISNAN
  testingMessage( "Testing CoinIsnan ... " ) ;
  testingMessage( " finite value: " ) ;
  if (!CoinIsnan(finiteVal))
  { testingMessage( "ok" ) ; }
  else
  { allOK = false ;
    testingMessage( "ERROR" ) ; }
  testingMessage( "; NaN value: " ) ;
  checkVal = checkVal/checkVal ;
  if (CoinIsnan(checkVal))
  { testingMessage( "ok.\n" ) ; }
  else
  { allOK = false ;
    testingMessage( "ERROR.\n" ) ; }
# else
  allOK = false ;
  testingMessage( "ERROR: No functional CoinIsnan.\n" ) ;
# endif


  testingMessage( "Testing CoinModel\n" );
  CoinModelUnitTest(mpsDir,netlibDir,testModel);

  testingMessage( "Testing CoinError\n" );
  CoinErrorUnitTest();

  testingMessage( "Testing CoinShallowPackedVector\n" );
  CoinShallowPackedVectorUnitTest();

  testingMessage( "Testing CoinPackedVector\n" );
  CoinPackedVectorUnitTest();

  testingMessage( "Testing CoinIndexedVector\n" );
  CoinIndexedVectorUnitTest();

  testingMessage( "Testing CoinPackedMatrix\n" );
  CoinPackedMatrixUnitTest();

// At moment CoinDenseVector is not compiling with MS V C++ V6
#if 1
  testingMessage( "Testing CoinDenseVector\n" );
  //CoinDenseVectorUnitTest<int>(0);
  CoinDenseVectorUnitTest<double>(0.0);
  CoinDenseVectorUnitTest<float>(0.0f);
#endif

  testingMessage( "Testing CoinMpsIO\n" );
  CoinMpsIOUnitTest(mpsDir);

  testingMessage( "Testing CoinLpIO\n" );
  CoinLpIOUnitTest(mpsDir);

  testingMessage( "Testing CoinMessageHandler\n" );
  if (!CoinMessageHandlerUnitTest())
  { allOK = false ; }

  if (allOK)
  { testingMessage( "All tests completed successfully.\n" );
    return (0) ; }
  else
  { testingMessage( "\nERROR: " ) ;
    testingMessage(
  	"Errors occurred during testing; please check the output.\n\n");
    return (1) ; }
}

 
// Display message on stdout and stderr
void testingMessage( const char * const msg )
{
  std::cerr <<msg;
  //cout <<endl <<"*****************************************"
  //     <<endl <<msg <<endl;
}