Changeset 9714
- Timestamp:
- Oct 21, 2006, 2:49:57 PM (20 years ago)
- Location:
- trunk/psLib
- Files:
-
- 7 added
- 1 deleted
- 3 edited
-
src/types/psLookupTable.c (modified) (23 diffs)
-
src/types/psLookupTable.h (modified) (5 diffs)
-
test/types/table.dat (added)
-
test/types/table2.dat (added)
-
test/types/tableF32.dat (deleted)
-
test/types/tableF32_2.dat (added)
-
test/types/tableF32_err.dat (added)
-
test/types/tableF64_err.dat (added)
-
test/types/tableS32_err.dat (added)
-
test/types/tableS64_err.dat (added)
-
test/types/tap_psLookupTable_all.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psLookupTable.c
r9672 r9714 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1.4 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-10-2 0 02:36:51$9 * @version $Revision: 1.41 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-10-22 00:49:57 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 69 69 static void lookupTableFree(psLookupTable* table); 70 70 71 /* * Determines if a line is blank (whitespace only) or a commentline. It returns true if so. The input string72 *must be null terminated. */71 /* Determines if a line is blank (whitespace only) or a commentline. It returns true if so. 72 The input string must be null terminated. */ 73 73 static bool ignoreLine(char *inString) 74 74 { … … 83 83 84 84 85 /* * Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null86 *terminated copy of the original input string. */85 /* Removes leading and trailing whitespace and # characters from a string. The 86 cleaned string is a new null terminated copy of the original input string. */ 87 87 static char *cleanString(char *inString, 88 88 int sLen) … … 95 95 96 96 // Skip over leading # or whitespace 97 while (isspace(*ptrB) || *ptrB=='#') {98 ptrB++;99 }97 // while (isspace(*ptrB) || *ptrB=='#') { 98 // ptrB++; 99 // } 100 100 101 101 // Skip over trailing whitespace, null terminators, and # characters … … 115 115 116 116 117 /** Returns cleaned token based on delimiter, but not including delimiter. Also changes the pointer location 118 * the beginning of the string. Tokens are newly allocated null terminated strings. */ 117 /* Returns cleaned token based on delimiter, but not including delimiter. Also changes 118 the pointer location the beginning of the string. Tokens are newly allocated null 119 terminated strings. */ 119 120 static char* getToken(char **inString, 120 121 char *delimiter, … … 138 139 // Move to end of token 139 140 (*inString) += sLen; 140 } else if(**inString!='\0' && sLen==0) { 141 *status = PS_PARSE_ERROR_GENERAL; 142 } 143 141 } 142 /* else if(**inString!='\0' && sLen==0) { 143 *status = PS_PARSE_ERROR_GENERAL; 144 } 145 */ 144 146 return cleanToken; 145 147 } 146 148 147 /** Returns single parsed value as a psS32. The input string must be cleaned and null terminated. */ 149 /* Returns single parsed value as a psS32. The input string must be cleaned and 150 null terminated. */ 148 151 static psS32 parseS32(char *inString, 149 152 psParseErrorType *status) … … 164 167 } 165 168 166 /** Returns single parsed value as a psS64. The input string must be cleaned and null terminated. */ 169 /* Returns single parsed value as a psS64. The input string must be cleaned and 170 null terminated. */ 167 171 static psS64 parseS64(char *inString, 168 172 psParseErrorType *status) … … 182 186 } 183 187 184 /** Returns single parsed value as a psF32. The input string must be cleaned and null terminated. */ 188 /* Returns single parsed value as a psF32. The input string must be cleaned and 189 null terminated. */ 185 190 static psF32 parseF32(char *inString, 186 191 psParseErrorType *status) … … 200 205 } 201 206 202 /** Returns single parsed value as a psF64. The input string must be cleaned and null terminated. */ 207 /* Returns single parsed value as a psF64. The input string must be cleaned and 208 null terminated. */ 203 209 static psF64 parseF64(char *inString, 204 210 psParseErrorType *status) … … 218 224 } 219 225 220 /* * Returns single parsed value as a double precision number. The input string must be cleaned and null221 *terminated. */226 /* Returns single parsed value as a double precision number. The input string must be 227 cleaned and null terminated. */ 222 228 static void parseValue(psVector *vec, 223 229 psU64 index, … … 474 480 // Don't increase number of columns 475 481 } else { 476 psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Invalid format specifier"); 482 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 483 "Invalid format specifier"); 477 484 psFree(strValue); 478 485 numCols = 0; … … 500 507 501 508 // Loop through file to get numRows, numCols, and column data types 502 while((fgets(line, MAX_STRING_LENGTH, fp) != NULL) && (parseStatus == PS_PARSE_SUCCESS)) { 509 while((fgets(line, MAX_STRING_LENGTH, fp) != NULL) && 510 (parseStatus == PS_PARSE_SUCCESS)) { 503 511 504 512 // Copy pointer to line for parsing … … 515 523 516 524 // Loop through format and line strings to get values in text table file 517 while((strValue=getToken((char**)&tempFormat," \t",&parseStatus)) && 518 (strNum=getToken((char**)&linePtr," \t",&parseStatus)) ) { 519 525 while((strValue=getToken((char**)&tempFormat," \t",&parseStatus)) 526 && (strNum=getToken((char**)&linePtr," \t",&parseStatus)) ) { 520 527 // Set column vector 521 528 colVector = outputArray->data[arrayIndex]; … … 523 530 // Set column entries based on format string defining the type 524 531 if(strcmp(strValue,"\%d") == 0 ) { 525 colVector = psVectorRecycle(colVector, numRows, colVector->type.type); 532 colVector = psVectorRecycle(colVector, numRows, 533 colVector->type.type); 526 534 parseValue(colVector,numRows-1,strNum,&parseStatus); 527 535 arrayIndex++; 528 536 } else if (strcmp(strValue,"\%ld") == 0) { 529 colVector = psVectorRecycle(colVector, numRows, colVector->type.type); 537 colVector = psVectorRecycle(colVector, numRows, 538 colVector->type.type); 530 539 parseValue(colVector,numRows-1,strNum,&parseStatus); 531 540 arrayIndex++; 532 541 } else if (strcmp(strValue,"\%f") == 0) { 533 colVector = psVectorRecycle(colVector, numRows, colVector->type.type); 542 colVector = psVectorRecycle(colVector, numRows, 543 colVector->type.type); 534 544 parseValue(colVector,numRows-1,strNum,&parseStatus); 535 545 arrayIndex++; 536 546 } else if (strcmp(strValue,"\%lf") == 0) { 537 colVector = psVectorRecycle(colVector, numRows, colVector->type.type); 547 colVector = psVectorRecycle(colVector, numRows, 548 colVector->type.type); 538 549 parseValue(colVector,numRows-1,strNum,&parseStatus); 539 550 arrayIndex++; … … 544 555 psFree(strNum); 545 556 546 // If the file line was not parsed successful report error and return NULL 557 // If the file line was not parsed successful report 558 // error and return NULL 547 559 if(parseStatus != PS_PARSE_SUCCESS) { 548 psError(PS_ERR_UNKNOWN,true,"Parsing text file failed."); 560 psError(PS_ERR_UNKNOWN, true, 561 "Parsing text file failed."); 549 562 fclose(fp); 550 563 psFree(outputArray); … … 556 569 } 557 570 571 //Return NULL for an empty table 572 if (numRows == 0) { 573 psError(PS_ERR_UNKNOWN, true, 574 "Parsing text file failed - input table is empty."); 575 fclose(fp); 576 psFree(outputArray); 577 psFree(line); 578 return NULL; 579 } 580 558 581 // Read on the lines in the file - close file pointer 559 582 fclose(fp); … … 562 585 } else { 563 586 // Format string parse error detected 564 psError(PS_ERR_UNKNOWN,true,"Format string was not parsed sucessfully"); 587 psError(PS_ERR_UNKNOWN, true, 588 "Format string was not parsed sucessfully"); 565 589 psFree(outputArray); 566 590 return NULL; … … 588 612 // Check for invalid index column 589 613 if(indexCol < 0 ) { 590 psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Index column cannot be less than zero"); 614 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 615 "Index column cannot be less than zero"); 591 616 return NULL; 592 617 } 593 618 594 619 if (indexCol >= vectors->n) { 595 psError(PS_ERR_BAD_PARAMETER_VALUE, true,"Index column, %ld, is larger than number of columns, %ld.",596 indexCol, vectors->n);620 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Index column, %ld, is larger" 621 " than number of columns, %ld.", indexCol, vectors->n); 597 622 return NULL; 598 623 } … … 647 672 } else { 648 673 // Index vector is already sorted 649 // Assign array vector specified by indexCol to table index vector and increment memory ref 674 // Assign array vector specified by indexCol to table index vector 675 // and increment memory ref 650 676 table->index = vectors->data[indexCol]; 651 677 table->values = (psArray*)vectors; … … 806 832 807 833 // Verify the index is within the bounds of the table 808 CHECK_LOWER_UPPER_BOUND(table,index,column) 834 CHECK_LOWER_UPPER_BOUND(table,index,column); 809 835 810 836 // Find location in table where specified index is between to entries … … 812 838 while(index > convertVal ) { 813 839 hiIdx++; 814 if(hiIdx >= numRows) { 815 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 816 _("High index too big, %" PRIu64 "."), hiIdx); 817 return NAN; 818 } 840 /* XXX: following is unreachable. 841 if(hiIdx >= numRows) { 842 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 843 _("High index too big, %" PRIu64 "."), hiIdx); 844 return NAN; 845 } 846 */ 819 847 CONVERT_VALUE_TO_F64(indexVec, hiIdx, convertVal) 820 848 } … … 833 861 denom -= convertVal; 834 862 if(fabs(denom) < FLT_EPSILON) { 835 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Divide by zero error during interpolation.")); 863 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 864 _("Divide by zero error during interpolation.")); 836 865 return NAN; 837 866 } else { … … 848 877 } 849 878 850 psVector* psLookupTableInterpolateAll( 851 const psLookupTable *table, 852 double index) 879 psVector* psLookupTableInterpolateAll(const psLookupTable *table, 880 double index) 853 881 { 854 882 long numCols = 0; -
trunk/psLib/src/types/psLookupTable.h
r7545 r9714 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2006- 06-13 23:54:57 $9 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-10-22 00:49:57 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 80 80 */ 81 81 psLookupTable* psLookupTableAlloc( 82 const char *filename, ///< Name of file to read83 const char *format, ///< scanf-like format string84 long indexCol ///< Column of the index vector (starting at zero)82 const char *filename, ///< Name of file to read 83 const char *format, ///< scanf-like format string 84 long indexCol ///< Column of the index vector (starting at zero) 85 85 ); 86 86 … … 92 92 */ 93 93 psArray *psVectorsReadFromFile( 94 const char* filename, ///< File to be read95 const char* format ///< scanf-like format string94 const char* filename, ///< File to be read 95 const char* format ///< scanf-like format string 96 96 ); 97 97 … … 115 115 */ 116 116 long psLookupTableRead( 117 psLookupTable *table ///< Table to read117 psLookupTable *table ///< Table to read 118 118 ); 119 119 … … 140 140 psVector* psLookupTableInterpolateAll( 141 141 const psLookupTable *table, ///< Table with data 142 double index ///< Value to be interpolated142 double index ///< Value to be interpolated 143 143 ); 144 144 -
trunk/psLib/test/types/tap_psLookupTable_all.c
r9672 r9714 24 24 int main(void) 25 25 { 26 plan_tests( 13);26 plan_tests(27); 27 27 28 28 diag("Tests for psLookupTable Functions"); … … 46 46 lt = psLookupTableAlloc(NULL, "\%f \%lf \%d \%ld", 10); 47 47 ok( lt == NULL, 48 "psLookupTableAlloc: return NULL for NULL filename input.");48 "psLookupTableAlloc: return NULL for NULL filename input."); 49 49 } 50 50 //Return NULL for NULL format input 51 51 { 52 lt = psLookupTableAlloc("table F32.dat", NULL, 10);52 lt = psLookupTableAlloc("table.dat", NULL, 10); 53 53 ok( lt == NULL, 54 "psLookupTableAlloc: return NULL for NULL format input.");54 "psLookupTableAlloc: return NULL for NULL format input."); 55 55 } 56 56 //Return properly allocated lookupTable for valid inputs 57 57 { 58 lt = psLookupTableAlloc("table F32.dat", "\%f \%lf \%d \%ld", 10);58 lt = psLookupTableAlloc("table.dat", "\%f \%lf \%d \%ld", 10); 59 59 ok( lt != NULL && psMemCheckLookupTable(lt), 60 "psLookupTableAlloc: "60 "psLookupTableAlloc: " 61 61 "return properly allocated lookupTable for valid inputs."); 62 62 } … … 67 67 int j = 2; 68 68 ok( !psMemCheckLookupTable(&j), 69 "psMemCheckLookupTable: return false for non-LookupTable input.");69 "psMemCheckLookupTable: return false for non-LookupTable input."); 70 70 } 71 71 … … 82 82 diag(" >>>Test 2: psVectorsReadFromFile, psLookupTableImport, psLookupTableRead Fxns"); 83 83 psArray *outVec = NULL; 84 psArray *vectors = NULL; 84 85 psLookupTable* table1 = NULL; 86 psLookupTable* tableOut = NULL; 85 87 long numRows = 0; 86 char filename[30];87 strcpy(filename, "tableF32.dat");88 88 89 89 //Tests for psVectorReadFromFile … … 93 93 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 94 94 ok( outVec == NULL, 95 "psVectorsReadFromFile: return NULL for NULL filename input.");95 "psVectorsReadFromFile: return NULL for NULL filename input."); 96 96 } 97 97 // Attempt to read from NULL format input 98 98 { 99 outVec = psVectorsReadFromFile( filename, NULL);100 ok( outVec == NULL, 101 "psVectorsReadFromFile: return NULL for NULL format input.");99 outVec = psVectorsReadFromFile("table.dat", NULL); 100 ok( outVec == NULL, 101 "psVectorsReadFromFile: return NULL for NULL format input."); 102 102 } 103 103 // Attempt to read from invalid filename input … … 106 106 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 107 107 ok( outVec == NULL, 108 "psVectorsReadFromFile: return NULL for invalid filename input.");108 "psVectorsReadFromFile: return NULL for invalid filename input."); 109 109 } 110 110 // Attempt to read from invalid format input 111 111 { 112 outVec = psVectorsReadFromFile(filename, "\%s"); 113 ok( outVec == NULL, 114 "psVectorsReadFromFile: return NULL for invalid format input."); 115 } 116 117 // Attempt to read from table containing missing entry 112 outVec = psVectorsReadFromFile("table.dat", "\%s"); 113 ok( outVec == NULL, 114 "psVectorsReadFromFile: return NULL for invalid format input."); 115 } 116 // Attempt to read from table containing invalid entry - F32 118 117 { 119 118 outVec = psVectorsReadFromFile("tableF32_err.dat", 120 119 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 121 120 ok( outVec == NULL, 122 "psVectorsReadFromFile: return NULL for table containing invalid entry."); 123 } 124 // Attempt to read from table containing missing entry 121 "psVectorsReadFromFile: return NULL for table containing invalid entry."); 122 } 123 // Attempt to read from table containing invalid entry - F64 124 { 125 outVec = psVectorsReadFromFile("tableF64_err.dat", 126 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 127 ok( outVec == NULL, 128 "psVectorsReadFromFile: return NULL for table containing invalid entry."); 129 } 130 // Attempt to read from table containing invalid entry - S32 131 { 132 outVec = psVectorsReadFromFile("tableS32_err.dat", 133 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 134 ok( outVec == NULL, 135 "psVectorsReadFromFile: return NULL for table containing invalid entry."); 136 } 137 // Attempt to read from table containing invalid entry - S64 138 { 139 outVec = psVectorsReadFromFile("tableS64_err.dat", 140 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 141 ok( outVec == NULL, 142 "psVectorsReadFromFile: return NULL for table containing invalid entry."); 143 } 144 // Attempt to read from empty table 125 145 { 126 146 outVec = psVectorsReadFromFile("tableF32_2.dat", 127 147 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 128 148 ok( outVec == NULL, 129 "psVectorsReadFromFile: return NULL for table containing invalid entry."); 130 } 131 149 "psVectorsReadFromFile: return NULL for empty table."); 150 } 132 151 //Attempt to read with valid inputs 133 152 { 134 outVec = psVectorsReadFromFile("tableF32.dat", 135 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 136 ok( outVec != NULL, 137 "psVectorsReadFromFile: return non-NULL array for valid format input."); 138 } 139 140 //Tests for psListToArray 141 // psLookupTable *lt = NULL; 142 143 153 outVec = psVectorsReadFromFile("table.dat", 154 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf"); 155 ok( outVec != NULL && outVec->n == 9 && 156 ((psVector*)(outVec->data[6]))->data.S32[1] == -8, 157 "psVectorsReadFromFile: return correct array for valid format input."); 158 } 159 160 //Tests for psLookupTableRead 144 161 // Attempt to read table with NULL input table specified 145 162 numRows = psLookupTableRead(table1); 146 163 { 147 164 ok( numRows == 0, 148 "psLookupTableRead: return NULL for NULL filename input."); 149 } 150 /* 151 psS32 testLookupTableRead(void) 152 { 153 154 // Set up valid table to read 155 table1 = psLookupTableAlloc(tableF32_filename,tableF32_format,tableF32_indexCol); 156 // Read table 157 numRows = psLookupTableRead(table1); 158 // Verify return value equals number of lines read 159 if(numRows != tableF32_size) { 160 psError(PS_ERR_UNKNOWN,true,"Return value %d not as expected %d", 161 numRows,tableF32_size); 162 return 1; 163 } 164 // Verify the members and values in table 165 if(fabs(table1->validFrom - tableF32_validFrom) > errorTol_psF64) { 166 psError(PS_ERR_UNKNOWN,true,"Member validFrom = %f not as expected %f", 167 table1->validFrom,tableF32_validFrom); 168 return 2; 169 } 170 if(fabs(table1->validTo - tableF32_validTo) > errorTol_psF64) { 171 psError(PS_ERR_UNKNOWN,true,"Member validTo = %f not as expected %f", 172 table1->validTo,tableF32_validTo); 173 return 3; 174 } 175 if(strcmp(table1->filename,tableF32_filename) != 0) { 176 psError(PS_ERR_UNKNOWN,true,"Member filename %s not as expected %s", 177 table1->filename,tableF32_filename); 178 return 4; 179 } 180 if(strcmp(table1->format,tableF32_format) != 0) { 181 psError(PS_ERR_UNKNOWN,true,"Member format %s not as expected %s", 182 table1->format,tableF32_format); 183 return 5; 184 } 185 if(table1->indexCol != tableF32_indexCol) { 186 psError(PS_ERR_UNKNOWN,true,"Member indexCol %d not as expected %d", 187 table1->indexCol,tableF32_indexCol); 188 return 6; 189 } 190 for(psS32 i = 0; i < table1->index->n; i++) { 191 if(fabs(table1->index->data.F32[i]-tableF32_index[i]) > errorTol_psF64) { 192 psError(PS_ERR_UNKNOWN,true,"Index column[%d] = %f not as expected %f", 193 i,table1->index->data.F32[i],tableF32_index[i]); 194 return i*7; 195 } 196 } 197 psVector* tempVector = table1->values->data[1]; 198 for(psS32 i = 0; i < tempVector->n; i++) { 199 if(tempVector->data.S32[i] != tableF32_col1[i]) { 200 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 201 i,tempVector->data.S32[i],tableF32_col1[i]); 202 return i*8; 203 } 204 } 205 tempVector = table1->values->data[2]; 206 for(psS32 i = 0; i < tempVector->n; i++) { 207 if(tempVector->data.S32[i] != tableF32_col2[i]) { 208 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 209 i,tempVector->data.S32[i],tableF32_col2[i]); 210 return i*9; 211 } 212 } 213 tempVector = table1->values->data[3]; 214 for(psS32 i = 0; i < tempVector->n; i++) { 215 if(tempVector->data.S64[i] != tableF32_col3[i]) { 216 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %ld not as expected %ld", 217 i,tempVector->data.S64[i],tableF32_col3[i]); 218 return i*10; 219 } 220 } 221 tempVector = table1->values->data[4]; 222 for(psS32 i = 0; i < tempVector->n; i++) { 223 if(tempVector->data.S32[i] != tableF32_col4[i]) { 224 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 225 i,tempVector->data.S32[i],tableF32_col4[i]); 226 return i*11; 227 } 228 } 229 tempVector = table1->values->data[5]; 230 for(psS32 i = 0; i < tempVector->n; i++) { 231 if(tempVector->data.S32[i] != tableF32_col5[i]) { 232 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 233 i,tempVector->data.S32[i],tableF32_col5[i]); 234 return i*12; 235 } 236 } 237 tempVector = table1->values->data[6]; 238 for(psS32 i = 0; i < tempVector->n; i++) { 239 if(tempVector->data.S32[i] != tableF32_col6[i]) { 240 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %d not as expected %d", 241 i,tempVector->data.S32[i],tableF32_col6[i]); 242 return i*13; 243 } 244 } 245 tempVector = table1->values->data[7]; 246 for(psS32 i = 0; i < tempVector->n; i++) { 247 if(tempVector->data.S64[i] != tableF32_col7[i]) { 248 psError(PS_ERR_UNKNOWN,true,"Value column[%d] = %ld not as expected %ld", 249 i,tempVector->data.S64[i],tableF32_col7[i]); 250 return i*14; 251 } 252 } 253 psFree(table1); 254 255 // Set up invalid table to read 256 table1 = psLookupTableAlloc(tableF32_filename,tableF32_format,tableF32_indexCol); 257 table1->indexCol = -1; 258 // Read invalid table 259 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid table indexCol"); 260 numRows = psLookupTableRead(table1); 261 // Verify the num of rows read is zero 262 if(numRows != 0) { 263 psError(PS_ERR_UNKNOWN,true,"Did not return 0 for line read for invalid table"); 264 return 15; 265 } 266 psFree(table1); 267 268 return 0; 269 } 270 */ 271 165 "psLookupTableRead: return NULL for NULL filename input."); 166 } 167 // Attempt to read table with bad filename specified 168 table1 = psLookupTableAlloc("psTable.dat", "\%f \%lf \%d \%ld", 10); 169 numRows = psLookupTableRead(table1); 170 { 171 ok( numRows == 0, 172 "psLookupTableRead: return NULL for table with invalid filename."); 173 } 174 175 // Attempt to read valid table with wrong indexCol 176 psFree(table1); 177 table1 = psLookupTableAlloc("table.dat", 178 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf", 10); 179 numRows = psLookupTableRead(table1); 180 { 181 ok( numRows == 0, 182 "psLookupTableRead: return correct number of rows for valid inputs."); 183 } 184 // Attempt to read valid table 185 psFree(table1); 186 table1 = psLookupTableAlloc("table.dat", 187 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf", 0); 188 numRows = psLookupTableRead(table1); 189 { 190 ok( numRows == 4, 191 "psLookupTableRead: return correct number of rows for valid inputs."); 192 } 193 194 //Tests for psLookupTableImport (remaining cases) 195 // Attempt to import table with negative indexCol 196 vectors = psVectorsReadFromFile(table1->filename, table1->format); 197 tableOut = psLookupTableImport(table1, vectors, -1 ); 198 { 199 ok( tableOut == NULL, 200 "psLookupTableImport: return NULL for negative indexCol input."); 201 } 202 //Attempt to import table with unsorted array column 203 psFree(table1); 204 table1 = psLookupTableAlloc("table.dat", 205 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf", 0); 206 tableOut = psLookupTableImport(table1, vectors, 7 ); 207 { 208 ok( tableOut != NULL, 209 "psLookupTableImport: return correct table for array with unsorted column"); 210 } 272 211 273 212 //Check for Memory leaks 274 213 { 214 psFree(vectors); 275 215 psFree(outVec); 276 216 psFree(table1); … … 283 223 { 284 224 diag(" >>>Test 3: psLookupTableInterpolate & psLookupTableInterpolateAll Fxns"); 285 286 287 288 //Tests for psListToArray 225 psLookupTable *table1 = NULL; 226 psVector *vec = NULL; 227 table1 = psLookupTableAlloc("table.dat", 228 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf", 0); 229 psLookupTable *table2 = NULL; 230 table2 = psLookupTableAlloc("table.dat", 231 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf", 0); 232 psLookupTableRead(table2); 233 234 //Tests for psLookupTableInterpolateAll 235 //Return NULL for NULL table input 236 { 237 vec = psLookupTableInterpolateAll(NULL, 0); 238 ok( vec == NULL, 239 "psLookupTableInterpolateAll: return NULL for NULL table input."); 240 } 241 //Return NULL for NULL table values 242 { 243 vec = psLookupTableInterpolateAll(table1, 0); 244 ok( vec == NULL, 245 "psLookupTableInterpolateAll: return NULL for NULL table values."); 246 } 247 //Return NULL for table with table->values->n == 0 248 { 249 long n = table2->values->n; 250 table2->values->n = 0; 251 vec = psLookupTableInterpolateAll(table2, 0); 252 ok( vec == NULL, 253 "psLookupTableInterpolateAll: return NULL for table with no columns."); 254 table2->values->n = n; 255 } 256 //Return NULL for invalid index input 257 { 258 vec = psLookupTableInterpolateAll(table2, -10.5); 259 ok( vec == NULL, 260 "psLookupTableInterpolateAll: return NULL for invalid index input."); 261 } 262 //Return correct vector output for valid inputs 263 { 264 vec = psLookupTableInterpolateAll(table2, 1); 265 skip_start( vec == NULL, 1, 266 "Skipping 1 tests because psLookupTableInterpolateAll failed"); 267 ok_double(vec->data.F64[0], 1.0, 268 "psLookupTableInterpolateAll: return correct output vector for valid inputs."); 269 skip_end(); 270 } 271 272 //Remaining tests for psLookupTableInterpolate 273 //Return NAN for invalid index - divide by zero error 274 psLookupTable *table3 = NULL; 275 table3 = psLookupTableAlloc("table2.dat", 276 "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf", 0); 277 psLookupTableRead(table3); 278 { 279 double retVal; 280 retVal = psLookupTableInterpolate(table3, 1.5e-20, 0); 281 ok( isnan(retVal), 282 "psLookupTableInterpolateAll: return NAN for invalid index input."); 283 } 289 284 290 285 //Check for Memory leaks 291 286 { 292 287 psFree(table3); 288 psFree(vec); 289 psFree(table2); 290 psFree(table1); 293 291 checkMem(); 294 292 } 295 293 296 294 } 297 298 299 300 /*301 //Return NULL for NULL list input302 {303 array = psListToArray(NULL);304 ok( array == NULL,305 "psListToArray: return NULL for NULL list input.");306 skip_start( !psArraySet(a, 0, s32) || !psArraySet(a, 1, s32), 1,307 "Skipping 1 tests because psArraySet failed");308 a = psArrayRealloc(a, 1);309 *s32_2 = *((psS32*)(a->data[0]));310 ok( a->n == 1 && a->nalloc == 1 && *s32_2 == 1,311 "psArrayRealloc: return properly reallocated psArray.");312 skip_end();313 }314 */315 316
Note:
See TracChangeset
for help on using the changeset viewer.
