Changeset 9714 for trunk/psLib/test/types
- Timestamp:
- Oct 21, 2006, 2:49:57 PM (20 years ago)
- Location:
- trunk/psLib/test/types
- Files:
-
- 7 added
- 1 deleted
- 1 edited
-
table.dat (added)
-
table2.dat (added)
-
tableF32.dat (deleted)
-
tableF32_2.dat (added)
-
tableF32_err.dat (added)
-
tableF64_err.dat (added)
-
tableS32_err.dat (added)
-
tableS64_err.dat (added)
-
tap_psLookupTable_all.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
