23 #define fei_file "test_Utils.cpp"
37 std::vector<int> intarray;
38 intarray.push_back(1);
39 intarray.push_back(2);
40 intarray.push_back(5);
41 intarray.push_back(6);
42 intarray.push_back(9);
47 FEI_COUT <<
"testing correctness of fei::binarySearch(int,int*,int,int)...";
51 if (offset != -1 || insertPoint != 0) {
52 throw std::runtime_error(
"fei::binarySearch test failed 1.");
58 throw std::runtime_error(
"fei::binarySearch test failed 2.");
63 if (offset != -1 || insertPoint != 2) {
64 throw std::runtime_error(
"fei::binarySearch test failed 3.");
69 if (offset != -1 || insertPoint != 2) {
70 throw std::runtime_error(
"fei::binarySearch test failed 4.");
76 throw std::runtime_error(
"fei::binarySearch test failed 5.");
81 if (offset != -1 || insertPoint != 4) {
82 throw std::runtime_error(
"fei::binarySearch test failed 6.");
87 if (offset != -1 || insertPoint != 5) {
88 throw std::runtime_error(
"fei::binarySearch test failed 7.");
113 FEI_COUT <<
"testing snl_fei::leading_substring_length...";
115 static char string1[] =
"test ";
121 static char string2[] =
"second test";
126 static char string3[] =
"third test";
139 FEI_COUT <<
"testing snl_fei::getDoubleParamValue...";
141 static char string1[] =
"DOUBLE1 1.0";
142 static char string2[] =
"DOUBLE2 1.0e+0";
143 static char string3[] =
"DOUBLE3 1.0E+0";
144 static char string4[] =
"DOUBLE4 1";
146 std::vector<char*> params;
147 params.push_back(string1);
148 params.push_back(string2);
149 params.push_back(string3);
150 params.push_back(string4);
155 params.size(), ¶ms[0],d1));
157 params.size(), ¶ms[0],d2));
159 params.size(), ¶ms[0],d3));
161 params.size(), ¶ms[0],d4));
163 if (std::abs(d1 - 1.0) > 1.e-49 || std::abs(d2 - 1.0) > 1.e-49 ||
164 std::abs(d3 - 1.0) > 1.e-49 || std::abs(d4 - 1.0) > 1.e-49) {
175 FEI_COUT <<
"testing fei::Param and fei::ParameterSet...";
177 fei::Param param1(
"string-param",
"garbage value");
195 paramset.
add(param2);
196 paramset.
add(param3);
198 if (paramset.
size() != 3) {
203 iter = paramset.
begin(),
204 iter_end = paramset.
end();
207 for(; iter != iter_end; ++iter) {
214 if (paramset.
get(
"int-param") == NULL) {
228 std::string dummychars;
234 if (
"garbage value" != dummychars) {
246 std::vector<std::string> stdstrings;
249 tempstr =
"string-param garbage value";
250 stdstrings.push_back(tempstr);
252 tempstr =
"int-param 58";
253 stdstrings.push_back(tempstr);
255 tempstr =
"real-param 45.e-2";
256 stdstrings.push_back(tempstr);
262 if (
"garbage value" != dummychars) {
273 if (std::abs(ddummy - 45.e-2) > 1.e-49) {
284 throw std::runtime_error(
"testing...");
289 FEI_COUT <<
"testing std::runtime_error...";
291 bool exc_thrown_and_caught =
false;
296 catch(std::runtime_error& exc) {
297 std::string str(exc.what());
298 if (str ==
"testing...") {
299 exc_thrown_and_caught =
true;
303 if (!exc_thrown_and_caught) {
339 FEI_COUT <<
"testing fei::SharedPtr...";
355 FEI_COUT <<
"testing snl_fei::copy2DToColumnContig...";
363 int len1 = numrows1*numcols1;
364 int len2 = numrows2*numcols2;
366 double** table2d_1 =
new double*[numrows1];
367 for(i=0; i<numrows1; ++i) {
368 table2d_1[i] =
new double[numcols1];
369 for(j=0; j<numcols1; ++j) {
370 table2d_1[i][j] = j*numrows1+i;
374 double** table2d_2 =
new double*[numcols2];
375 for(j=0; j<numcols2; ++j) {
376 table2d_2[j] =
new double[numrows2];
377 for(i=0; i<numrows2; ++i) {
378 table2d_2[j][i] = j*numrows2+i;
382 double* cc1 =
new double[len1];
383 double* cc2 =
new double[len2];
391 for(i=0; i<len1; ++i) {
392 if (std::abs(cc1[i] - cc2[i]) > 1.e-49) {
393 throw std::runtime_error(
"column-contig arrays not equal.");
397 for(j=0; j<numrows1; ++j)
delete [] table2d_1[j];
404 FEI_COUT <<
"testing snl_fei::copy2DBlockDiagToColumnContig...";
408 int* blockSizes =
new int[numBlocks];
409 for(i=0; i<numBlocks; ++i) {
413 table2d_1 =
new double*[numrows1];
414 for(i=0; i<numrows1; ++i) {
415 table2d_1[i] =
new double[4];
417 table2d_1[i][j] = 1.0*i*4+j;
422 cc1 =
new double[len1];
427 for(i=0; i<len1; ++i) {
428 if (std::abs(1.0*i - cc1[i]) > 1.e-49) {
429 throw std::runtime_error(
"copy2DBlockDiagToColumnContig row test failed.");
433 for(j=0; j<numrows1; ++j)
delete [] table2d_1[j];
435 for(j=0; j<numcols2; ++j)
delete [] table2d_2[j];
439 delete [] blockSizes;
void test_Utils_binarySearch()
ParamType getType() const
const Param * get(const char *name) const
bool test_Utils_dummy_destroyed
void test_Utils_function_that_throws()
void copy2DToColumnContig(int numrows, int numcols, const double *const *values2d, int format, double *colcontigvalues)
unsigned leading_substring_length(const char *string)
#define FEI_BLOCK_DIAGONAL_ROW
int test_Utils_test_SharedPtr()
int getDoubleParamValue(const char *key, int numParams, const char *const *params, double ¶mValue)
int getStringParamValue(const char *name, std::string ¶mValue) const
int binarySearch(const T &item, const T *list, int len)
void add(const Param ¶m, bool maintain_unique_keys=true)
int getDoubleParamValue(const char *name, double ¶mValue) const
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet ¶mset)
void copy2DBlockDiagToColumnContig(int numBlocks, const int *blockSizes, const double *const *values2d, int format, double *colcontigvalues)
test_Utils(MPI_Comm comm)
const_iterator end() const
const_iterator begin() const
int getIntParamValue(const char *name, int ¶mValue) const