Changeset 4054
- Timestamp:
- May 31, 2005, 11:52:55 AM (21 years ago)
- Location:
- trunk/psLib/test/dataIO
- Files:
-
- 2 edited
-
tst_psLookupTable_01.c (modified) (14 diffs)
-
verified/tst_psLookupTable_01.stderr (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataIO/tst_psLookupTable_01.c
r3682 r4054 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-0 4-07 20:27:42$14 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-05-31 21:52:49 $ 16 16 * 17 17 * Copyright 2004-5 Maui High Performance Computing Center, University of Hawaii … … 24 24 25 25 static psS32 testLookupTableAlloc(void); 26 static psS32 testVectorsReadFromFile(void); 27 static psS32 testLookupTableImport(void); 26 28 static psS32 testLookupTableRead(void); 27 29 static psS32 testLookupTableInterpolate(void); … … 32 34 const psF64 tableU8_validTo = 3; 33 35 const psS32 tableU8_size = 4; 36 const char tableU8_format[] = "\%d \%d \%d \%ld \%d \%d \%d \%ld \%f \%lf"; 37 const char tableU8_filename[] = "verified/tableU8.dat"; 38 const psS32 tableU8_indexCol = 0; 34 39 const psS32 tableU8_index[] = 35 40 { … … 71 76 { 72 77 -1.5,-1.0,-0.25,1.75 73 };74 75 const psF64 tableS32_validFrom = -1;76 const psF64 tableS32_validTo = 33;77 const psS32 tableS32_size = 4;78 const psS32 tableS32_index[] =79 {80 -1,11,22,3381 78 }; 82 79 83 80 const psF64 tableF32_validFrom = -10.05; 84 81 const psF64 tableF32_validTo = 3500.67; 85 const psF64 tableF32_size = 4; 82 const psS32 tableF32_size = 4; 83 const psS32 tableF32_cols = 9; 84 const char tableF32_filename[] = "verified/tableF32.dat"; 85 const char tableF32_format[] = "\%f \%d \%d \%ld \%d \%d \%d \%ld \%d \%lf"; 86 const char tableF32_indexCol = 0; 87 const psElemType tableF32_colType[] = 88 { 89 PS_TYPE_F32, PS_TYPE_S32, PS_TYPE_S32, PS_TYPE_S64, 90 PS_TYPE_S32, PS_TYPE_S32, PS_TYPE_S32, PS_TYPE_S64, 91 PS_TYPE_F64 92 }; 86 93 const psF32 tableF32_index[] = 87 94 { 88 95 -10.05,1.009,23.45,3500.67 89 96 }; 97 const psS32 tableF32_col1[] = 98 { 99 2, 4, 6, 8 100 }; 101 const psS32 tableF32_col2[] = 102 { 103 4, 8, 12, 16 104 }; 105 const psS64 tableF32_col3[] = 106 { 107 8, 16, 24, 32 108 }; 109 const psS32 tableF32_col4[] = 110 { 111 0, -1, -2, -3 112 }; 113 const psS32 tableF32_col5[] = 114 { 115 -2, -4, -6, -8 116 }; 117 const psS32 tableF32_col6[] = 118 { 119 -4, -8, -12, -16 120 }; 121 const psS64 tableF32_col7[] = 122 { 123 -8, -16, -24, -32 124 }; 125 const psF64 tableF32_col8[] = 126 { 127 -1.5, -1.0, -0.25, 1.75 128 }; 129 90 130 91 131 const psF64 table10_validFrom = 1; 92 132 const psF64 table10_validTo = 10; 93 133 const psS32 table10_size = 10; 94 const psU8 table10_index[] = 134 const char table10_format[] = "\%d \%d \%d \%ld \%d \%d \%d \%ld \%f \%lf"; 135 const char table10_filename[] = "verified/table10.dat"; 136 const psS32 table10_indexCol = 0; 137 const psS32 table10_index[] = 95 138 { 96 139 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 97 140 }; 98 const ps U16table10_val1[] =141 const psS32 table10_val1[] = 99 142 { 100 143 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 101 144 }; 102 const ps U32 table10_val2[] =145 const psS32 table10_val2[] = 103 146 { 104 147 8, 12, 16, 20, 24, 28, 32, 36, 40, 44 105 148 }; 106 const ps U64 table10_val3[] =149 const psS64 table10_val3[] = 107 150 { 108 151 16, 24, 32, 64, 128, 256, 512, 1024, 2048, 4096 109 152 }; 110 const psS 8table10_val4[] =153 const psS32 table10_val4[] = 111 154 { 112 155 -1, -2, -3, -4, -5, -6, -7, -8, -9, -10 113 156 }; 114 const psS 16table10_val5[] =157 const psS32 table10_val5[] = 115 158 { 116 159 -4, -6, -8, -10, -12, -14, -16, -18, -20, -22 … … 134 177 const psF64 interpolVal1[] = 135 178 { 136 12.5, 25, 160, -5.25, -12.5, -25, -160, 0.9375, 11.4825179 5.25, 12.5, 25, 160, -5.25, -12.5, -25, -160, 0.9375, 11.4825 137 180 }; 138 181 const psF64 interpolVal2[] = 139 182 { 140 12, 24, 128, -5, -12, -24, -128, 0.75, 10.65183 5, 12, 24, 128, -5, -12, -24, -128, 0.75, 10.65 141 184 }; 142 185 const psF64 interpolVal3[] = … … 146 189 147 190 testDescription tests[] = { 148 {testLookupTableAlloc,999,"psLookupTableAlloc",0,false}, 191 {testLookupTableAlloc,817,"psLookupTableAlloc",0,false}, 192 {testVectorsReadFromFile,999,"psVectorsReadFromFile",0,false}, 193 {testLookupTableImport,999,"psLookupTableImport",0,false}, 149 194 {testLookupTableRead,998,"psLookupTableRead",0,false}, 150 195 {testLookupTableInterpolate,997,"psLookupTableInterpolate",0,false}, … … 168 213 169 214 // Allocate lookup table with valid parameters 170 table1 = psLookupTableAlloc("tableF32.dat", tableF32_validFrom, tableF32_validTo);215 table1 = psLookupTableAlloc("tableF32.dat","\%f \%lf \%d \%ld",10); 171 216 if(table1 == NULL) { 172 217 psError(PS_ERR_UNKNOWN,true,"Null lookup table generated from valid parameters"); 173 218 return 1; 174 219 } 175 if(strcmp(table1->file Name,"tableF32.dat") != 0) {220 if(strcmp(table1->filename,"tableF32.dat") != 0) { 176 221 psError(PS_ERR_UNKNOWN,true,"File name not properly stored in psLookupTable structure."); 177 222 return 2; 178 223 } 179 180 if( (fabs(table1->validFrom - tableF32_validFrom) > FLT_EPSILON) || 181 (fabs(table1->validTo-tableF32_validTo) > FLT_EPSILON) ) { 182 psError(PS_ERR_UNKNOWN,true,"Members validTo or validFrom not set properly"); 224 if(strcmp(table1->format,"\%f \%lf \%d \%ld") != 0) { 225 psError(PS_ERR_UNKNOWN,true,"Format string not properly storeed in psLookupTable structure."); 226 return 3; 227 } 228 if(table1->indexCol != 10) { 229 psError(PS_ERR_UNKNOWN,true,"Member indexCol not set properly"); 183 230 return 3; 184 231 } … … 187 234 // Allocate lookup table with invalid filename 188 235 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid file name"); 189 table1 = psLookupTableAlloc(NULL, 0,3);236 table1 = psLookupTableAlloc(NULL,"\%d",3); 190 237 if(table1 != NULL) { 191 238 psError(PS_ERR_UNKNOWN,true,"Null file name accepted by psLookupTableAlloc"); … … 193 240 } 194 241 242 // Allocate lookup table with invalid format 243 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid format string"); 244 table1 = psLookupTableAlloc("tableF32.dat",NULL,3); 245 if(table1 != NULL) { 246 psError(PS_ERR_UNKNOWN,true,"Null format string accepted by psLookupTableAlloc"); 247 return 5; 248 } 249 195 250 return 0; 196 251 } 197 252 253 psS32 testVectorsReadFromFile(void) 254 { 255 psArray* out = NULL; 256 psVector* tempVector = NULL; 257 258 // Read file and place into an array of vectors 259 out = psVectorsReadFromFile("verified/tableF32.dat","\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 260 if(out == NULL) { 261 psError(PS_ERR_UNKNOWN,true,"Unable to read file into array of vectors"); 262 return 1; 263 } 264 // Verify the number of vectors in array is as expected 265 if(out->n != tableF32_cols) { 266 psError(PS_ERR_UNKNOWN,true,"Expected number of columns = %d not equal to actual = %d", 267 tableF32_cols, out->n); 268 return 2; 269 } 270 // Verify the number of entries in vectors is as expected 271 for(int i = 0; i < out->n; i++ ) { 272 tempVector = out->data[i]; 273 if(tempVector->n != tableF32_size) { 274 psError(PS_ERR_UNKNOWN,true,"Col #%d Expected number of entries = %d not equal to actual = %d", 275 i,tableF32_size,tempVector->n); 276 return 3; 277 } 278 } 279 // Verify the vector types are as expected 280 for(int i = 0; i < out->n; i++) { 281 tempVector = out->data[i]; 282 if(tempVector->type.type != tableF32_colType[i]) { 283 psError(PS_ERR_UNKNOWN,true,"Col #%d Expected type = %d not equal to actual = %d", 284 i,tableF32_colType[i],tempVector->type.type); 285 return 4; 286 } 287 } 288 // Verify the values in the vectors are as expected 289 tempVector = out->data[0]; 290 for(int i = 0; i < tempVector->n; i++) { 291 if(tempVector->data.F32[i] != tableF32_index[i]) { 292 psError(PS_ERR_UNKNOWN,true,"Col #0 Vector element[%d] expected = %f not equal to actual = %f", 293 i, tableF32_index[i],tempVector->data.F32[i]); 294 return 5 + i; 295 } 296 } 297 // Verify the values in the vectors are as expected 298 tempVector = out->data[1]; 299 for(int i = 0; i < tempVector->n; i++) { 300 if(tempVector->data.S32[i] != tableF32_col1[i]) { 301 psError(PS_ERR_UNKNOWN,true,"Col #1 Vector element[%d] expected = %d not equal to actual = %d", 302 i, tableF32_col1[i],tempVector->data.S32[i]); 303 return 10 + i; 304 } 305 } 306 // Verify the values in the vectors are as expected 307 tempVector = out->data[2]; 308 for(int i = 0; i < tempVector->n; i++) { 309 if(tempVector->data.S32[i] != tableF32_col2[i]) { 310 psError(PS_ERR_UNKNOWN,true,"Col #2 Vector element[%d] expected = %d not equal to actual = %d", 311 i, tableF32_col2[i],tempVector->data.S32[i]); 312 return 15 + i; 313 } 314 } 315 // Verify the values in the vectors are as expected 316 tempVector = out->data[3]; 317 for(int i = 0; i < tempVector->n; i++) { 318 if(tempVector->data.S64[i] != tableF32_col3[i]) { 319 psError(PS_ERR_UNKNOWN,true,"Col #3 Vector element[%d] expected = %ld not equal to actual = %ld", 320 i, tableF32_col3[i],tempVector->data.S64[i]); 321 return 20 + i; 322 } 323 } 324 // Verify the values in the vectors are as expected 325 tempVector = out->data[4]; 326 for(int i = 0; i < tempVector->n; i++) { 327 if(tempVector->data.S32[i] != tableF32_col4[i]) { 328 psError(PS_ERR_UNKNOWN,true,"Col #4 Vector element[%d] expected = %d not equal to actual = %d", 329 i, tableF32_col4[i],tempVector->data.S32[i]); 330 return 25 + i; 331 } 332 } 333 // Verify the values in the vectors are as expected 334 tempVector = out->data[5]; 335 for(int i = 0; i < tempVector->n; i++) { 336 if(tempVector->data.S32[i] != tableF32_col5[i]) { 337 psError(PS_ERR_UNKNOWN,true,"Col #5 Vector element[%d] expected = %d not equal to actual = %d", 338 i, tableF32_col5[i],tempVector->data.S32[i]); 339 return 30 + i; 340 } 341 } 342 // Verify the values in the vectors are as expected 343 tempVector = out->data[6]; 344 for(int i = 0; i < tempVector->n; i++) { 345 if(tempVector->data.S32[i] != tableF32_col6[i]) { 346 psError(PS_ERR_UNKNOWN,true,"Col #6 Vector element[%d] expected = %d not equal to actual = %d", 347 i, tableF32_col6[i],tempVector->data.S32[i]); 348 return 35 + i; 349 } 350 } 351 // Verify the values in the vectors are as expected 352 tempVector = out->data[7]; 353 for(int i = 0; i < tempVector->n; i++) { 354 if(tempVector->data.S64[i] != tableF32_col7[i]) { 355 psError(PS_ERR_UNKNOWN,true,"Col #7 Vector element[%d] expected = %ld not equal to actual = %ld", 356 i, tableF32_col7[i],tempVector->data.S64[i]); 357 return 40 + i; 358 } 359 } 360 // Verify the values in the vectors are as expected 361 tempVector = out->data[8]; 362 for(int i = 0; i < tempVector->n; i++) { 363 if(tempVector->data.F64[i] != tableF32_col8[i]) { 364 psError(PS_ERR_UNKNOWN,true,"Col #8 Vector element[%d] expected = %lf not equal to actual = %lf", 365 i, tableF32_col8[i],tempVector->data.F64[i]); 366 return 45 + i; 367 } 368 } 369 psFree(out); 370 371 // Attempt to read vectors from valid file with invalid format 372 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL format"); 373 out = psVectorsReadFromFile("verified/tableF32.dat",NULL); 374 if(out != NULL) { 375 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with NULL format string"); 376 return 50; 377 } 378 379 // Attempt to read vectors from invalid file with valid format 380 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL filename"); 381 out = psVectorsReadFromFile(NULL,"%f %f"); 382 if(out != NULL) { 383 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with NULL file name"); 384 return 51; 385 } 386 387 // Attempt to read vectors from valid file with invalid format specifiers 388 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid format specifier"); 389 out = psVectorsReadFromFile("verified/tableF32.data","\%f \%c \%d"); 390 if(out != NULL) { 391 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid format specifier"); 392 return 52; 393 } 394 395 // Attempt to read vectors from non-existant file 396 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for non-existant file"); 397 out = psVectorsReadFromFile("verified/nonexistant.dat","\%f \%d \%d"); 398 if(out != NULL) { 399 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with non-existant file"); 400 return 53; 401 } 402 403 // Attempt to read vectors from file with errors in the numbers 404 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for error is file"); 405 out = psVectorsReadFromFile("verified/tableF32_err.dat","\%f \%d \%d \%ld \%d \%d \%d \%ld \%d \%lf"); 406 if(out != NULL) { 407 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with file with errors"); 408 return 54; 409 } 410 411 return 0; 412 } 413 414 psS32 testLookupTableImport(void) 415 { 416 psLookupTable* outTable = NULL; 417 psLookupTable* inTable = NULL; 418 psArray* vectors = NULL; 419 420 // Attempt to import table with NULL table 421 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL table argument"); 422 outTable = psLookupTableImport(NULL,vectors,1); 423 if(outTable != NULL) { 424 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with NULL input table"); 425 return 1; 426 } 427 428 // Allocate valid table, format string and index column 429 inTable = psLookupTableAlloc(table10_filename,table10_format,table10_indexCol); 430 431 // Attempt to import table with NULL vector argument 432 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL vectors"); 433 outTable = psLookupTableImport(inTable,vectors,table10_indexCol); 434 if(outTable != NULL) { 435 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with NULL input vectors"); 436 return 2; 437 } 438 439 // Allocate valid array 440 vectors = psArrayAlloc(10); 441 442 // Attempt to import table with invalid index column 443 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid index column"); 444 outTable = psLookupTableImport(inTable,vectors,-1); 445 if(outTable != NULL) { 446 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid index column specified"); 447 return 3; 448 } 449 psFree(vectors); 450 451 // Attempt to import file with file with unsorted index vector 452 // Read vectors from file 453 vectors = psVectorsReadFromFile(table10_filename,table10_format); 454 outTable = psLookupTableImport(inTable,vectors,table10_indexCol); 455 if(outTable != inTable) { 456 psError(PS_ERR_UNKNOWN,true,"Did not set proper return value"); 457 return 4; 458 } 459 // Verify the index column vector 460 psVector* indexVector = outTable->index; 461 for(int i = 0; i < indexVector->n; i++) { 462 if(indexVector->data.S32[i] != table10_index[i]) { 463 psError(PS_ERR_UNKNOWN,true,"Index value[%d] = %d is not as expected %d", 464 i,indexVector->data.S32[i],table10_index[i]); 465 return i*4; 466 } 467 } 468 // Verify the value array vectors 469 psVector* valueVector = outTable->values->data[1]; 470 for(int i = 0; i < valueVector->n; i++) { 471 if(valueVector->data.S32[i] != table10_val1[i]) { 472 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %d is not as expected %d", 473 i,valueVector->data.S32[i],table10_val1[i]); 474 return i*5; 475 } 476 } 477 valueVector = outTable->values->data[2]; 478 for(int i = 0; i < valueVector->n; i++) { 479 if(valueVector->data.S32[i] != table10_val2[i]) { 480 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %d is not as expected %d", 481 i,valueVector->data.S32[i],table10_val2[i]); 482 return i*6; 483 } 484 } 485 valueVector = outTable->values->data[3]; 486 for(int i = 0; i < valueVector->n; i++) { 487 if(valueVector->data.S64[i] != table10_val3[i]) { 488 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %ld is not as expected %ld", 489 i,valueVector->data.S64[i],table10_val3[i]); 490 return i*7; 491 } 492 } 493 valueVector = outTable->values->data[4]; 494 for(int i = 0; i < valueVector->n; i++) { 495 if(valueVector->data.S32[i] != table10_val4[i]) { 496 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %d is not as expected %d", 497 i,valueVector->data.S32[i],table10_val4[i]); 498 return i*8; 499 } 500 } 501 valueVector = outTable->values->data[5]; 502 for(int i = 0; i < valueVector->n; i++) { 503 if(valueVector->data.S32[i] != table10_val5[i]) { 504 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %d is not as expected %d", 505 i,valueVector->data.S32[i],table10_val5[i]); 506 return i*9; 507 } 508 } 509 valueVector = outTable->values->data[6]; 510 for(int i = 0; i < valueVector->n; i++) { 511 if(valueVector->data.S32[i] != table10_val6[i]) { 512 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %d is not as expected %d", 513 i,valueVector->data.S32[i],table10_val6[i]); 514 return i*10; 515 } 516 } 517 valueVector = outTable->values->data[7]; 518 for(int i = 0; i < valueVector->n; i++) { 519 if(valueVector->data.S64[i] != table10_val7[i]) { 520 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %ld is not as expected %ld", 521 i,valueVector->data.S64[i],table10_val7[i]); 522 return i*11; 523 } 524 } 525 valueVector = outTable->values->data[8]; 526 for(int i = 0; i < valueVector->n; i++) { 527 if(valueVector->data.F32[i] != table10_val8[i]) { 528 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %f is not as expected %f", 529 i,valueVector->data.F32[i],table10_val8[i]); 530 return i*12; 531 } 532 } 533 valueVector = outTable->values->data[9]; 534 for(int i = 0; i < valueVector->n; i++) { 535 if(valueVector->data.F64[i] != table10_val9[i]) { 536 psError(PS_ERR_UNKNOWN,true,"Value [%d] = %lf is not as expected %lf", 537 i,valueVector->data.F64[i],table10_val9[i]); 538 return i*13; 539 } 540 } 541 // Verify the table members are set properly 542 if(outTable->indexCol != table10_indexCol) { 543 psError(PS_ERR_UNKNOWN,true,"Member indexCol = %d not as expected %d", 544 outTable->indexCol,table10_indexCol); 545 return 100; 546 } 547 if(outTable->validFrom != table10_validFrom) { 548 psError(PS_ERR_UNKNOWN,true,"Member validFrom = %d not as expected %d", 549 outTable->validFrom, table10_validFrom); 550 return 101; 551 } 552 if(outTable->validTo != table10_validTo) { 553 psError(PS_ERR_UNKNOWN,true,"Member validTo = %d not as expected %d", 554 outTable->validTo, table10_validTo); 555 return 102; 556 } 557 if(strcmp(outTable->filename,table10_filename) != 0) { 558 psError(PS_ERR_UNKNOWN,true,"Member filename = %d not as expected %s", 559 outTable->filename,table10_filename); 560 return 103; 561 } 562 if(strcmp(outTable->format,table10_format) != 0) { 563 psError(PS_ERR_UNKNOWN,true,"Member format = %d not as expected %s", 564 outTable->format,table10_format); 565 return 104; 566 } 567 psFree(vectors); 568 psFree(inTable); 569 570 // Attempt to import file with file with sorted index vector 571 // Read vectors from file 572 // Allocate valid table, format string and index column 573 inTable = psLookupTableAlloc(tableU8_filename,tableU8_format,tableU8_indexCol); 574 vectors = psVectorsReadFromFile(tableU8_filename,tableU8_format); 575 outTable = psLookupTableImport(inTable,vectors,tableU8_indexCol); 576 if(outTable != inTable) { 577 psError(PS_ERR_UNKNOWN,true,"Did not set proper return value"); 578 return 4; 579 } 580 // Verify the index column vector 581 indexVector = outTable->index; 582 for(int i = 0; i < indexVector->n; i++) { 583 if(indexVector->data.S32[i] != tableU8_index[i]) { 584 psError(PS_ERR_UNKNOWN,true,"Index value[%d] = %d is not as expected %d", 585 i,indexVector->data.S32[i],tableU8_index[i]); 586 } 587 } 588 // Verify the table members are set properly 589 if(outTable->indexCol != tableU8_indexCol) { 590 psError(PS_ERR_UNKNOWN,true,"Member indexCol = %d not as expected %d", 591 outTable->indexCol,tableU8_indexCol); 592 return 100; 593 } 594 if(outTable->validFrom != tableU8_validFrom) { 595 psError(PS_ERR_UNKNOWN,true,"Member validFrom = %d not as expected %d", 596 outTable->validFrom, tableU8_validFrom); 597 return 101; 598 } 599 if(outTable->validTo != tableU8_validTo) { 600 psError(PS_ERR_UNKNOWN,true,"Member validTo = %d not as expected %d", 601 outTable->validTo, tableU8_validTo); 602 return 102; 603 } 604 if(strcmp(outTable->filename,tableU8_filename) != 0) { 605 psError(PS_ERR_UNKNOWN,true,"Member filename = %d not as expected %s", 606 outTable->filename,tableU8_filename); 607 return 103; 608 } 609 if(strcmp(outTable->format,tableU8_format) != 0) { 610 psError(PS_ERR_UNKNOWN,true,"Member format = %d not as expected %s", 611 outTable->format,tableU8_format); 612 return 104; 613 } 614 psFree(inTable); 615 psFree(vectors); 616 617 return 0; 618 } 619 198 620 psS32 testLookupTableRead(void) 199 621 { 200 psLookupTable* table1 = NULL; 201 202 // Allocate table using table with psU8 index and valid types and index-values 203 table1 = psLookupTableAlloc("tableU8.dat", 0, 100.5); 204 if(table1 == NULL) { 205 psError(PS_ERR_UNKNOWN,true,"Unable to allocate table with tableU8.dat"); 622 psLookupTable* table1 = NULL; 623 psS32 numRows = 0; 624 625 // Attempt to read table with NULL input table specified 626 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL table"); 627 numRows = psLookupTableRead(table1); 628 if(numRows != 0) { 629 psError(PS_ERR_UNKNOWN,true,"Did not return zero for NULL input table"); 206 630 return 1; 207 631 } 208 // Read table with index U8 209 table1 = psLookupTableRead(table1); 210 if(table1 == NULL) { 211 psError(PS_ERR_UNKNOWN,true,"Unable to read table from file tableU8.dat"); 632 633 // Set up valid table to read 634 table1 = psLookupTableAlloc(tableF32_filename,tableF32_format,tableF32_indexCol); 635 // Read table 636 numRows = psLookupTableRead(table1); 637 // Verify return value equals number of lines read 638 if(numRows != tableF32_size) { 639 psError(PS_ERR_UNKNOWN,true,"Return value %d not as expected %d", 640 numRows,tableF32_size); 641 return 1; 642 } 643 // Verify the members and values in table 644 if(fabs(table1->validFrom - tableF32_validFrom) > errorTol_psF64) { 645 psError(PS_ERR_UNKNOWN,true,"Member validFrom = %f not as expected %f", 646 table1->validFrom,tableF32_validFrom); 212 647 return 2; 213 648 } 214 // Verify the validFrom and validTo are updated properly 215 if( (fabs(table1->validFrom - tableU8_validFrom) > FLT_EPSILON) || 216 (fabs(table1->validTo - tableU8_validTo) > FLT_EPSILON) ) { 217 psError(PS_ERR_UNKNOWN,true,"ValidFrom or validTo not set properly"); 649 if(fabs(table1->validTo - tableF32_validTo) > errorTol_psF64) { 650 psError(PS_ERR_UNKNOWN,true,"Member validTo = %f not as expected %f", 651 table1->validTo,tableF32_validTo); 218 652 return 3; 219 653 } 220 // Verify index and all values in table read properly 221 for(psS32 i=0; i < tableU8_size; i++) { 222 if(table1->index->data.U8[i] != tableU8_index[i]) { 223 psError(PS_ERR_UNKNOWN,true,"Index values do not match: index[%d]=%d expected %d",i, 224 table1->index->data.U8[i], tableU8_index[i]); 225 return 3*i; 226 } 227 if(((psVector*)table1->values->data[0])->data.U16[i] != tableU8_val1[i]) { 228 psError(PS_ERR_UNKNOWN,true,"Value in column 1 do not match: value[%d]=%d expected %d",i, 229 ((psVector*)table1->values->data[0])->data.U16[i], tableU8_val1[i]); 230 return 3*i+1; 231 } 232 if(((psVector*)table1->values->data[1])->data.U32[i] != tableU8_val2[i]) { 233 psError(PS_ERR_UNKNOWN,true,"Value in column 2 do not match: value[%d]=%d expected %d",i, 234 ((psVector*)table1->values->data[1])->data.U32[i], tableU8_val2[i]); 235 return 3*i+2; 236 } 237 if(((psVector*)table1->values->data[2])->data.U64[i] != tableU8_val3[i]) { 238 psError(PS_ERR_UNKNOWN,true,"Value in column 3 do not match: value[%d]=%lld expected %lld",i, 239 ((psVector*)table1->values->data[2])->data.U64[i], tableU8_val3[i]); 240 return 3*i+3; 241 } 242 if(((psVector*)table1->values->data[3])->data.S8[i] != tableU8_val4[i]) { 243 psError(PS_ERR_UNKNOWN,true,"Value in column 4 do not match: value[%d]=%d expected %d",i, 244 ((psVector*)table1->values->data[3])->data.S8[i], tableU8_val4[i]); 245 return 3*i+4; 246 } 247 if(((psVector*)table1->values->data[4])->data.S16[i] != tableU8_val5[i]) { 248 psError(PS_ERR_UNKNOWN,true,"Value in column 5 do not match: value[%d]=%d expected %d",i, 249 ((psVector*)table1->values->data[4])->data.S16[i], tableU8_val5[i]); 250 return 3*i+5; 251 } 252 if(((psVector*)table1->values->data[5])->data.S32[i] != tableU8_val6[i]) { 253 psError(PS_ERR_UNKNOWN,true,"Value in column 6 do not match: value[%d]=%d expected %d",i, 254 ((psVector*)table1->values->data[5])->data.S32[i], tableU8_val6[i]); 255 return 3*i+6; 256 } 257 if(((psVector*)table1->values->data[6])->data.S64[i] != tableU8_val7[i]) { 258 psError(PS_ERR_UNKNOWN,true,"Value in column 7 do not match: value[%d]=%lld expected %lld",i, 259 ((psVector*)table1->values->data[6])->data.S64[i], tableU8_val7[i]); 260 return 3*i+7; 261 } 262 if(fabs(((psVector*)table1->values->data[7])->data.F32[i] - tableU8_val8[i]) > FLT_EPSILON ) { 263 psError(PS_ERR_UNKNOWN,true,"Value in column 8 do not match: value[%d]=%g expected %g",i, 264 ((psVector*)table1->values->data[7])->data.F32[i], tableU8_val8[i]); 265 return 3*i+8; 266 } 267 if(fabs(((psVector*)table1->values->data[8])->data.F64[i] - tableU8_val9[i]) > FLT_EPSILON ) { 268 psError(PS_ERR_UNKNOWN,true,"Value in column 9 do not match: value[%d]=%g expected %g",i, 269 ((psVector*)table1->values->data[8])->data.F32[i], tableU8_val9[i]); 270 return 3*i+9; 654 if(strcmp(table1->filename,tableF32_filename) != 0) { 655 psError(PS_ERR_UNKNOWN,true,"Member filename %s not as expected %s", 656 table1->filename,tableF32_filename); 657 return 4; 658 } 659 if(strcmp(table1->format,tableF32_format) != 0) { 660 psError(PS_ERR_UNKNOWN,true,"Member format %s not as expected %s", 661 table1->format,tableF32_format); 662 return 5; 663 } 664 if(table1->indexCol != tableF32_indexCol) { 665 psError(PS_ERR_UNKNOWN,true,"Member indexCol %d not as expected %d", 666 table1->indexCol,tableF32_indexCol); 667 return 6; 668 } 669 for(psS32 i = 0; i < table1->index->n; i++) { 670 if(fabs(table1->index->data.F32[i]-tableF32_index[i]) > errorTol_psF64) { 671 psError(PS_ERR_UNKNOWN,true,"Index column[%d] = %f not as expected %f", 672 i,table1->index->data.F32[i],tableF32_index[i]); 673 return i*7; 674 } 675 } 676 psVector* tempVector = table1->values->data[1]; 677 for(psS32 i = 0; i < tempVector->n; i++) { 678 if(tempVector->data.S32[i] != tableF32_col1[i]) { 679 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 680 i,tempVector->data.S32[i],tableF32_col1[i]); 681 return i*8; 682 } 683 } 684 tempVector = table1->values->data[2]; 685 for(psS32 i = 0; i < tempVector->n; i++) { 686 if(tempVector->data.S32[i] != tableF32_col2[i]) { 687 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 688 i,tempVector->data.S32[i],tableF32_col2[i]); 689 return i*9; 690 } 691 } 692 tempVector = table1->values->data[3]; 693 for(psS32 i = 0; i < tempVector->n; i++) { 694 if(tempVector->data.S64[i] != tableF32_col3[i]) { 695 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %ld not as expected %ld", 696 i,tempVector->data.S64[i],tableF32_col3[i]); 697 return i*10; 698 } 699 } 700 tempVector = table1->values->data[4]; 701 for(psS32 i = 0; i < tempVector->n; i++) { 702 if(tempVector->data.S32[i] != tableF32_col4[i]) { 703 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 704 i,tempVector->data.S32[i],tableF32_col4[i]); 705 return i*11; 706 } 707 } 708 tempVector = table1->values->data[5]; 709 for(psS32 i = 0; i < tempVector->n; i++) { 710 if(tempVector->data.S32[i] != tableF32_col5[i]) { 711 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 712 i,tempVector->data.S32[i],tableF32_col5[i]); 713 return i*12; 714 } 715 } 716 tempVector = table1->values->data[6]; 717 for(psS32 i = 0; i < tempVector->n; i++) { 718 if(tempVector->data.S32[i] != tableF32_col6[i]) { 719 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 720 i,tempVector->data.S32[i],tableF32_col6[i]); 721 return i*13; 722 } 723 } 724 tempVector = table1->values->data[7]; 725 for(psS32 i = 0; i < tempVector->n; i++) { 726 if(tempVector->data.S64[i] != tableF32_col7[i]) { 727 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %ld not as expected %ld", 728 i,tempVector->data.S64[i],tableF32_col7[i]); 729 return i*14; 271 730 } 272 731 } 273 732 psFree(table1); 274 733 275 // Allocate table using table with psS32 index and valid types and index-values 276 table1 = psLookupTableAlloc("tableS32.dat", -110, 1000.5); 277 if(table1 == NULL) { 278 psError(PS_ERR_UNKNOWN,true,"Unable to allocate table with tableS32.dat"); 279 return 1; 280 } 281 table1 = psLookupTableRead(table1); 282 if(table1 == NULL) { 283 psError(PS_ERR_UNKNOWN,true,"Unable to read table from file tableS32.dat"); 284 return 2; 285 } 286 if( (fabs(table1->validFrom - tableS32_validFrom) > FLT_EPSILON) || 287 (fabs(table1->validTo - tableS32_validTo) > FLT_EPSILON) ) { 288 psError(PS_ERR_UNKNOWN,true,"ValidFrom or validTo not set properly"); 289 return 3; 290 } 291 for(psS32 i=0; i < tableS32_size; i++) { 292 if(table1->index->data.S32[i] != tableS32_index[i]) { 293 psError(PS_ERR_UNKNOWN,true,"Index values do not match: index[%d]=%d expected %d",i, 294 table1->index->data.S32[i], tableS32_index[i]); 295 return 4*i; 296 } 734 // Set up invalid table to read 735 table1 = psLookupTableAlloc(tableF32_filename,tableF32_format,tableF32_indexCol); 736 table1->indexCol = -1; 737 // Read invalid table 738 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid table indexCol"); 739 numRows = psLookupTableRead(table1); 740 // Verify the num of rows read is zero 741 if(numRows != 0) { 742 psError(PS_ERR_UNKNOWN,true,"Did not return 0 for line read for invalid table"); 743 return 15; 297 744 } 298 745 psFree(table1); 299 300 // Allocate table using table with psF32 index and valid types and index-values301 table1 = psLookupTableAlloc("tableF32.dat", -1100, 5500.5);302 if(table1 == NULL) {303 psError(PS_ERR_UNKNOWN,true,"Unable to allocate table with tableF32.dat");304 return 1;305 }306 table1 = psLookupTableRead(table1);307 if(table1 == NULL) {308 psError(PS_ERR_UNKNOWN,true,"Unable to read table from file tableF32.dat");309 return 2;310 }311 if( (fabs(table1->validFrom - tableF32_validFrom) > errorTol_psF64) ||312 (fabs(table1->validTo - tableF32_validTo) > errorTol_psF64) ) {313 psError(PS_ERR_UNKNOWN,true,"ValidFrom or validTo not set properly");314 return 3;315 }316 for(psS32 i=0; i < tableS32_size; i++) {317 if(fabsf(table1->index->data.F32[i] - tableF32_index[i]) > FLT_EPSILON ) {318 psError(PS_ERR_UNKNOWN,true,"Index values do not match: index[%d]=%d expected %d",i,319 table1->index->data.F32[i], tableF32_index[i]);320 return 4*i;321 }322 }323 psFree(table1);324 325 // Allocate table using psU8 index but with unsorted rows and verify the list is326 // sorted properly after being read327 table1 = psLookupTableAlloc("table10.dat",1,2);328 if(table1 == NULL) {329 psError(PS_ERR_UNKNOWN,true,"Unable to allocate table with table10.dat");330 return 1;331 }332 table1 = psLookupTableRead(table1);333 if(table1 == NULL) {334 psError(PS_ERR_UNKNOWN,true,"Unable to read table with table10.dat");335 return 2;336 }337 // Verify the validFrom and validTo are updated properly338 if( (fabs(table1->validFrom - table10_validFrom) > FLT_EPSILON) ||339 (fabs(table1->validTo - table10_validTo) > FLT_EPSILON) ) {340 psError(PS_ERR_UNKNOWN,true,"ValidFrom or validTo not set properly");341 return 3;342 }343 // Verify index and all values in table read properly344 for(psS32 i=0; i < table10_size; i++) {345 if(table1->index->data.U8[i] != table10_index[i]) {346 psError(PS_ERR_UNKNOWN,true,"Index values do not match: index[%d]=%d expected %d",i,347 table1->index->data.U8[i], table10_index[i]);348 return 3*i;349 }350 if(((psVector*)table1->values->data[0])->data.U16[i] != table10_val1[i]) {351 psError(PS_ERR_UNKNOWN,true,"Value in column 1 do not match: value[%d]=%d expected %d",i,352 ((psVector*)table1->values->data[0])->data.U16[i], table10_val1[i]);353 return 3*i+1;354 }355 if(((psVector*)table1->values->data[1])->data.U32[i] != table10_val2[i]) {356 psError(PS_ERR_UNKNOWN,true,"Value in column 2 do not match: value[%d]=%d expected %d",i,357 ((psVector*)table1->values->data[1])->data.U32[i], table10_val2[i]);358 return 3*i+2;359 }360 if(((psVector*)table1->values->data[2])->data.U64[i] != table10_val3[i]) {361 psError(PS_ERR_UNKNOWN,true,"Value in column 3 do not match: value[%d]=%lld expected %lld",i,362 ((psVector*)table1->values->data[2])->data.U64[i], table10_val3[i]);363 return 3*i+3;364 }365 if(((psVector*)table1->values->data[3])->data.S8[i] != table10_val4[i]) {366 psError(PS_ERR_UNKNOWN,true,"Value in column 4 do not match: value[%d]=%d expected %d",i,367 ((psVector*)table1->values->data[3])->data.S8[i], table10_val4[i]);368 return 3*i+4;369 }370 if(((psVector*)table1->values->data[4])->data.S16[i] != table10_val5[i]) {371 psError(PS_ERR_UNKNOWN,true,"Value in column 5 do not match: value[%d]=%d expected %d",i,372 ((psVector*)table1->values->data[4])->data.S16[i], table10_val5[i]);373 return 3*i+5;374 }375 if(((psVector*)table1->values->data[5])->data.S32[i] != table10_val6[i]) {376 psError(PS_ERR_UNKNOWN,true,"Value in column 6 do not match: value[%d]=%d expected %d",i,377 ((psVector*)table1->values->data[5])->data.S32[i], table10_val6[i]);378 return 3*i+6;379 }380 if(((psVector*)table1->values->data[6])->data.S64[i] != table10_val7[i]) {381 psError(PS_ERR_UNKNOWN,true,"Value in column 7 do not match: value[%d]=%lld expected %lld",i,382 ((psVector*)table1->values->data[6])->data.S64[i], table10_val7[i]);383 return 3*i+7;384 }385 if(fabs(((psVector*)table1->values->data[7])->data.F32[i] - table10_val8[i]) > FLT_EPSILON ) {386 psError(PS_ERR_UNKNOWN,true,"Value in column 8 do not match: value[%d]=%g expected %g",i,387 ((psVector*)table1->values->data[7])->data.F32[i], table10_val8[i]);388 return 3*i+8;389 }390 if(fabs(((psVector*)table1->values->data[8])->data.F64[i] - table10_val9[i]) > FLT_EPSILON ) {391 psError(PS_ERR_UNKNOWN,true,"Value in column 9 do not match: value[%d]=%g expected %g",i,392 ((psVector*)table1->values->data[8])->data.F32[i], table10_val9[i]);393 return 3*i+9;394 }395 }396 psFree(table1);397 398 // Allocate table using table with invalid type in type row but valid index-values399 table1 = psLookupTableAlloc("table2.dat",0,99.99);400 if(table1 == NULL) {401 psError(PS_ERR_UNKNOWN,true,"Unable to allocate table with table2.dat");402 return 3;403 }404 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message about invalid type");405 table1 = psLookupTableRead(table1);406 if(table1 == NULL) {407 psError(PS_ERR_UNKNOWN,true,"Unable to read table from file table2.dat");408 return 4;409 }410 psFree(table1);411 412 // Allocate table using table with invalid value413 table1 = psLookupTableAlloc("table3.dat",0,75.0);414 if(table1 == NULL) {415 psError(PS_ERR_UNKNOWN,true,"Unable to allocate table with table3.dat");416 return 5;417 }418 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message about invalid value");419 table1 = psLookupTableRead(table1);420 if(table1 == NULL) {421 psError(PS_ERR_UNKNOWN,true,"Unable to read table from file table3.dat");422 return 6;423 }424 psFree(table1);425 426 // Attempt to read for non-existant file427 table1 = psLookupTableAlloc("nonexistantFile.dat",0,100);428 if(table1 == NULL) {429 psError(PS_ERR_UNKNOWN,true,"Unable to allocate table with non-existant file");430 return 3;431 }432 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg about opening file");433 table1 = psLookupTableRead(table1);434 if(table1 == NULL) {435 psError(PS_ERR_UNKNOWN,true,"Returned NULL when table should have been returned");436 return 4;437 }438 439 // Attempt to read table with NULL specified file440 psFree((char*)table1->fileName);441 table1->fileName = NULL;442 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg about NULL file name");443 if(psLookupTableRead(table1) != NULL) {444 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with table specifying NULL file name");445 return 5;446 }447 psFree(table1);448 449 // Attempt to read table with NULL table450 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg about NULL table");451 if(psLookupTableRead(NULL) != NULL) {452 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with NULL table.");453 return 6;454 }455 746 456 747 return 0; … … 459 750 psS32 testLookupTableInterpolate(void) 460 751 { 461 psLookupStatusType status = 0;462 752 psLookupTable* table1 = NULL; 463 psF64 out1 = 0; 753 psF64 out1 = 0.0; 754 755 // Attempt to perform interpolation with NULL table 756 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid table"); 757 out1 = psLookupTableInterpolate(table1,0,0); 758 if( !isnan(out1) ) { 759 psError(PS_ERR_UNKNOWN,true,"Did not return NaN as expected"); 760 return 1; 761 } 464 762 465 763 // Interpolate values within the list and verify return values 466 table1 = psLookupTableAlloc("table10.dat",0,20); 467 table1 = psLookupTableRead(table1); 468 for(psS32 i = 0; i < table1->numRows-1; i++ ) { 469 out1 = psLookupTableInterpolate(table1, 5.25, i, &status); 764 table1 = psLookupTableAlloc(table10_filename,table10_format,table10_indexCol); 765 psS32 numLines = psLookupTableRead(table1); 766 if(numLines != table10_size) { 767 psError(PS_ERR_UNKNOWN,true,"Line read %d not as expected %d",numLines,table10_size); 768 return 2; 769 } 770 for(psS32 i = 0; i < table1->values->n; i++ ) { 771 out1 = psLookupTableInterpolate(table1, 5.25, i); 470 772 if( fabs(out1-interpolVal1[i]) > errorTol_psF64) { 471 773 psError(PS_ERR_UNKNOWN,true,"Did not return expected value. %lg expected %lg",out1,interpolVal1[i]); … … 473 775 } 474 776 } 475 for(psS32 i = 0; i < table1-> numRows-1; i++ ) {476 out1 = psLookupTableInterpolate(table1, 5.0, i , &status);777 for(psS32 i = 0; i < table1->values->n; i++ ) { 778 out1 = psLookupTableInterpolate(table1, 5.0, i); 477 779 if( fabs(out1-interpolVal2[i]) > errorTol_psF64) { 478 780 psError(PS_ERR_UNKNOWN,true,"Did not return expected value. %lg expected %lg",out1,interpolVal2[i]); … … 482 784 483 785 // Interpolate value just below the lowest index value 484 out1 = psLookupTableInterpolate(table1,0,0 , &status);786 out1 = psLookupTableInterpolate(table1,0,0); 485 787 if ( fabs(out1- NAN) > FLT_EPSILON ) { 486 788 psError(PS_ERR_UNKNOWN,true,"Did not return NAN returned %lf",out1); 487 789 return 5; 488 790 } 489 if ( status != PS_LOOKUP_PAST_TOP) {490 psError(PS_ERR_UNKNOWN,true,"Did not return status PAST TOP");491 return 6;492 }493 791 494 792 // Interpolate value just above the highest index value 495 out1 = psLookupTableInterpolate(table1,11,0 , &status);793 out1 = psLookupTableInterpolate(table1,11,0); 496 794 if ( fabs(out1-NAN) > FLT_EPSILON ) { 497 795 psError(PS_ERR_UNKNOWN,true,"Did not return NAN returned %lf",out1); 498 796 return 7; 499 797 } 500 if ( status != PS_LOOKUP_PAST_BOTTOM) {501 psError(PS_ERR_UNKNOWN,true,"Did not return status PAST BOTTOM");502 return 8;503 }504 798 505 799 // Interpolate value with a column number greater than the table has 506 800 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error out of range."); 507 out1 = psLookupTableInterpolate(table1, 5, 100 , &status);801 out1 = psLookupTableInterpolate(table1, 5, 100); 508 802 if ( fabs(out1-NAN) > FLT_EPSILON ) { 509 803 psError(PS_ERR_UNKNOWN,true,"Did not return NAN returned %lf",out1); 510 804 return 9; 511 805 } 512 if ( status != PS_LOOKUP_ERROR ) {513 psError(PS_ERR_UNKNOWN,true,"Did not return status LOOKUP ERROR");514 return 10;515 }516 517 // Interpolate with NULL table518 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error NULL table");519 out1 = psLookupTableInterpolate(NULL,5,0,&status);520 if( fabs(out1-NAN) > FLT_EPSILON ) {521 psError(PS_ERR_UNKNOWN,true,"Did not return NAN returned %lf",out1);522 return 11;523 }524 if ( status != PS_LOOKUP_ERROR ) {525 psError(PS_ERR_UNKNOWN,true,"Did not return status LOOKUP ERROR");526 return 12;527 }528 529 // Interpolate with status NULL530 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error NULL status");531 out1 = psLookupTableInterpolate(table1,5,0,NULL);532 if ( fabs(out1-NAN) > FLT_EPSILON ) {533 psError(PS_ERR_UNKNOWN,true,"Did not return NAN returned %lf",out1);534 return 13;535 }536 537 806 psFree(table1); 538 807 … … 544 813 psLookupTable* table1 = NULL; 545 814 psVector* interpValues; 546 psVector* statusVector; 815 816 // Interpolate values with NULL table 817 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL table"); 818 interpValues = psLookupTableInterpolateAll(table1,5); 819 if(interpValues != NULL ) { 820 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL table"); 821 return 5; 822 } 547 823 548 824 // Interpolate values within the list and verify return values 549 table1 = psLookupTableAlloc("table10.dat",0,20); 550 table1 = psLookupTableRead(table1); 551 statusVector = psVectorAlloc(table1->numCols,PS_TYPE_U32); 552 interpValues = psLookupTableInterpolateAll(table1,5.25, statusVector); 825 table1 = psLookupTableAlloc(table10_filename,table10_format,table10_indexCol); 826 psS32 numLines = psLookupTableRead(table1); 827 if(numLines != table10_size) { 828 psError(PS_ERR_UNKNOWN,true,"Num lines read %d not as expected %d",numLines,table10_size); 829 return 6; 830 } 831 interpValues = psLookupTableInterpolateAll(table1,5.25); 553 832 if(interpValues == NULL) { 554 833 psError(PS_ERR_UNKNOWN,true,"Returned vector is NULL."); 555 834 return 1; 556 835 } 557 for(psS32 i = 0; i < table1-> numRows-1; i++ ) {836 for(psS32 i = 0; i < table1->values->n; i++ ) { 558 837 if( fabs(interpValues->data.F64[i]-interpolVal1[i]) > errorTol_psF64) { 559 838 psError(PS_ERR_UNKNOWN,true,"Did not return expected value. %lg expected %lg", … … 562 841 } 563 842 } 564 for(psS32 j = 0; j < table1->numCols; j++) {565 if(statusVector->data.U32[j] != PS_LOOKUP_SUCCESS) {566 psError(PS_ERR_UNKNOWN,true,"Return status not success for col=%d status=%d",567 j,statusVector->data.U32[j]);568 return 3*j;569 }570 }571 psFree(statusVector);572 843 psFree(interpValues); 573 844 574 845 // Interpolate values with index outside table 575 statusVector = psVectorAlloc(table1->numCols,PS_TYPE_U32); 576 interpValues = psLookupTableInterpolateAll(table1,0,statusVector); 577 if(interpValues == NULL) { 846 interpValues = psLookupTableInterpolateAll(table1,0); 847 if(interpValues != NULL) { 578 848 psError(PS_ERR_UNKNOWN,true,"Did return NULL"); 579 849 return 4; 580 850 } 581 582 for(psS32 i = 0; i < table1->numRows-1; i++ ) {583 if( fabs(interpValues->data.F64[i]-interpolVal3[i]) > errorTol_psF64) {584 psError(PS_ERR_UNKNOWN,true,"Did not return expected value. %lg expected %lg",585 interpValues->data.F64[i],interpolVal3[i]);586 return 2*i;587 }588 }589 590 for(psS32 j = 0; j < table1->numCols; j++) {591 if(statusVector->data.S32[j] != PS_LOOKUP_PAST_TOP) {592 psError(PS_ERR_UNKNOWN,true,"Return status did not indicate passed top for col=%d status=%d",593 j,statusVector->data.U32[j]);594 return 3*j;595 }596 }597 psFree(interpValues);598 psFree(statusVector);599 600 // Interpolate values with NULL table601 statusVector = psVectorAlloc(table1->numCols,PS_TYPE_S32);602 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL table");603 interpValues = psLookupTableInterpolateAll(NULL,5,statusVector);604 if(interpValues != NULL ) {605 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL table");606 return 5;607 }608 psFree(statusVector);609 610 // Interpolate values with NULL status vector611 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL status vector");612 interpValues = psLookupTableInterpolateAll(table1,5,NULL);613 if(interpValues != NULL ) {614 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL status vector");615 return 6;616 }617 851 psFree(table1); 618 852 -
trunk/psLib/test/dataIO/verified/tst_psLookupTable_01.stderr
r3269 r4054 9 9 <DATE><TIME>|<HOST>|E|psLookupTableAlloc (FILE:LINENO) 10 10 Unallowable operation: fileName is NULL. 11 <DATE><TIME>|<HOST>|I|testLookupTableAlloc 12 Following should generate error message for invalid format string 13 <DATE><TIME>|<HOST>|E|psLookupTableAlloc (FILE:LINENO) 14 Unallowable operation: format is NULL. 11 15 12 16 ---> TESTPOINT PASSED (psLookupTable{psLookupTableAlloc} | tst_psLookupTable_01.c) 17 18 /***************************** TESTPOINT ******************************************\ 19 * TestFile: tst_psLookupTable_01.c * 20 * TestPoint: psLookupTable{psVectorsReadFromFile} * 21 * TestType: Positive * 22 \**********************************************************************************/ 23 24 <DATE><TIME>|<HOST>|I|testVectorsReadFromFile 25 Following should generate error message for NULL format 26 <DATE><TIME>|<HOST>|E|psVectorsReadFromFile (FILE:LINENO) 27 Unallowable operation: format is NULL. 28 <DATE><TIME>|<HOST>|I|testVectorsReadFromFile 29 Following should generate error message for NULL filename 30 <DATE><TIME>|<HOST>|E|psVectorsReadFromFile (FILE:LINENO) 31 Unallowable operation: filename is NULL. 32 <DATE><TIME>|<HOST>|I|testVectorsReadFromFile 33 Following should generate error message for invalid format specifier 34 <DATE><TIME>|<HOST>|E|psVectorsReadFromFile (FILE:LINENO) 35 Invalid format specifier 36 <DATE><TIME>|<HOST>|E|psVectorsReadFromFile (FILE:LINENO) 37 Format string was not parsed sucessfully 38 <DATE><TIME>|<HOST>|I|testVectorsReadFromFile 39 Following should generate error message for non-existant file 40 <DATE><TIME>|<HOST>|E|psVectorsReadFromFile (FILE:LINENO) 41 Failed to open file verified/nonexistant.dat. 42 <DATE><TIME>|<HOST>|I|testVectorsReadFromFile 43 Following should generate error message for error is file 44 <DATE><TIME>|<HOST>|E|psVectorsReadFromFile (FILE:LINENO) 45 Parsing text file failed. 46 47 ---> TESTPOINT PASSED (psLookupTable{psVectorsReadFromFile} | tst_psLookupTable_01.c) 48 49 /***************************** TESTPOINT ******************************************\ 50 * TestFile: tst_psLookupTable_01.c * 51 * TestPoint: psLookupTable{psLookupTableImport} * 52 * TestType: Positive * 53 \**********************************************************************************/ 54 55 <DATE><TIME>|<HOST>|I|testLookupTableImport 56 Following should generate error message for NULL table argument 57 <DATE><TIME>|<HOST>|E|psLookupTableImport (FILE:LINENO) 58 Unallowable operation: table is NULL. 59 <DATE><TIME>|<HOST>|I|testLookupTableImport 60 Following should generate error message for NULL vectors 61 <DATE><TIME>|<HOST>|E|psLookupTableImport (FILE:LINENO) 62 Unallowable operation: vectors is NULL. 63 <DATE><TIME>|<HOST>|I|testLookupTableImport 64 Following should generate error message for invalid index column 65 <DATE><TIME>|<HOST>|E|psLookupTableImport (FILE:LINENO) 66 Index column cannot be less than zero 67 68 ---> TESTPOINT PASSED (psLookupTable{psLookupTableImport} | tst_psLookupTable_01.c) 13 69 14 70 /***************************** TESTPOINT ******************************************\ … … 19 75 20 76 <DATE><TIME>|<HOST>|I|testLookupTableRead 21 Following should generate an error message about invalid type 22 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 23 Unable to parse type, (null) on line 3. 24 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 25 Lookup table is invalid. 26 <DATE><TIME>|<HOST>|I|testLookupTableRead 27 Following should generate an error message about invalid value 28 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 29 Unable to parse string, 1) on line 5. 30 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 31 Unable to parse string, 4= on line 5. 32 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 33 Unable to parse string, 8; on line 5. 34 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 35 Unable to parse string, 1(6 on line 5. 36 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 37 Unable to parse string, -1_ on line 5. 38 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 39 Unable to parse string, -4$ on line 5. 40 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 41 Unable to parse string, -8@ on line 5. 42 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 43 Unable to parse string, -16{ on line 5. 44 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 45 Unable to parse string, 0.0[ on line 5. 46 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 47 Unable to parse string, -1.0] on line 5. 48 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 49 Lookup table is invalid. 50 <DATE><TIME>|<HOST>|I|testLookupTableRead 51 Following should generate error msg about opening file 52 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 53 Failed to open file nonexistantFile.dat. 54 <DATE><TIME>|<HOST>|I|testLookupTableRead 55 Following should generate error msg about NULL file name 56 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 57 Unallowable operation: table->fileName is NULL. 58 <DATE><TIME>|<HOST>|I|testLookupTableRead 59 Following should generate error msg about NULL table 77 Following should generate an error message for NULL table 60 78 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 61 79 Unallowable operation: table is NULL. 80 <DATE><TIME>|<HOST>|I|testLookupTableRead 81 Following should generate error message invalid table indexCol 82 <DATE><TIME>|<HOST>|E|psLookupTableImport (FILE:LINENO) 83 Index column cannot be less than zero 62 84 63 85 ---> TESTPOINT PASSED (psLookupTable{psLookupTableRead} | tst_psLookupTable_01.c) … … 70 92 71 93 <DATE><TIME>|<HOST>|I|testLookupTableInterpolate 72 Following should generate error out of range. 73 <DATE><TIME>|<HOST>|E|psLookupTableInterpolate (FILE:LINENO) 74 Error: column, 100, is out of range. Must be between 0 and 8. 75 <DATE><TIME>|<HOST>|I|testLookupTableInterpolate 76 Following should generate error NULL table 94 Following should generate error message for invalid table 77 95 <DATE><TIME>|<HOST>|E|psLookupTableInterpolate (FILE:LINENO) 78 96 Unallowable operation: table is NULL. 79 97 <DATE><TIME>|<HOST>|I|testLookupTableInterpolate 80 Following should generate an error NULL status98 Following should generate error out of range. 81 99 <DATE><TIME>|<HOST>|E|psLookupTableInterpolate (FILE:LINENO) 82 Unallowable operation: status is NULL.100 Error: column, 100, is out of range. Must be between 0 and 9. 83 101 84 102 ---> TESTPOINT PASSED (psLookupTable{psLookupTableInterpolate} | tst_psLookupTable_01.c) … … 94 112 <DATE><TIME>|<HOST>|E|psLookupTableInterpolateAll (FILE:LINENO) 95 113 Unallowable operation: table is NULL. 96 <DATE><TIME>|<HOST>|I|testLookupTableInterpolateAll97 Following should generate an error message for NULL status vector98 <DATE><TIME>|<HOST>|E|psLookupTableInterpolateAll (FILE:LINENO)99 Unallowable operation: stats is NULL.100 114 101 115 ---> TESTPOINT PASSED (psLookupTable{psLookupTableInterpolateAll} | tst_psLookupTable_01.c)
Note:
See TracChangeset
for help on using the changeset viewer.
