IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9714 for trunk/psLib


Ignore:
Timestamp:
Oct 21, 2006, 2:49:57 PM (20 years ago)
Author:
drobbin
Message:

Finished testing of psLookupTable. 100% coverage reported. Added tables for tests. Removed unnecessary table. Removed unreachable spot from psLookupTableInterpolate. Minor formatting in psLookupTable.h.

Location:
trunk/psLib
Files:
7 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psLookupTable.c

    r9672 r9714  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-10-20 02:36:51 $
     9*  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-10-22 00:49:57 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    6969static void lookupTableFree(psLookupTable* table);
    7070
    71 /** Determines if a line is blank (whitespace only) or a commentline. It returns true if so. The input string
    72  * 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. */
    7373static bool ignoreLine(char *inString)
    7474{
     
    8383
    8484
    85 /** Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null
    86  * 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. */
    8787static char *cleanString(char *inString,
    8888                         int sLen)
     
    9595
    9696    // Skip over leading # or whitespace
    97     while (isspace(*ptrB) || *ptrB=='#') {
    98         ptrB++;
    99     }
     97    //    while (isspace(*ptrB) || *ptrB=='#') {
     98    //        ptrB++;
     99    //    }
    100100
    101101    // Skip over trailing whitespace, null terminators, and # characters
     
    115115
    116116
    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. */
    119120static char* getToken(char **inString,
    120121                      char *delimiter,
     
    138139        // Move to end of token
    139140        (*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    */
    144146    return cleanToken;
    145147}
    146148
    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. */
    148151static psS32 parseS32(char *inString,
    149152                      psParseErrorType *status)
     
    164167}
    165168
    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. */
    167171static psS64 parseS64(char *inString,
    168172                      psParseErrorType *status)
     
    182186}
    183187
    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. */
    185190static psF32 parseF32(char *inString,
    186191                      psParseErrorType *status)
     
    200205}
    201206
    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. */
    203209static psF64 parseF64(char *inString,
    204210                      psParseErrorType *status)
     
    218224}
    219225
    220 /** Returns single parsed value as a double precision number. The input string must be cleaned and null
    221  * terminated. */
     226/* Returns single parsed value as a double precision number. The input string must be
     227   cleaned and null terminated. */
    222228static void parseValue(psVector *vec,
    223229                       psU64 index,
     
    474480            // Don't increase number of columns
    475481        } else {
    476             psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Invalid format specifier");
     482            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     483                    "Invalid format specifier");
    477484            psFree(strValue);
    478485            numCols = 0;
     
    500507
    501508            // 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))   {
    503511
    504512                // Copy pointer to line for parsing
     
    515523
    516524                    // 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)) ) {
    520527                        // Set column vector
    521528                        colVector = outputArray->data[arrayIndex];
     
    523530                        // Set column entries based on format string defining the type
    524531                        if(strcmp(strValue,"\%d") == 0 ) {
    525                             colVector = psVectorRecycle(colVector, numRows, colVector->type.type);
     532                            colVector = psVectorRecycle(colVector, numRows,
     533                                                        colVector->type.type);
    526534                            parseValue(colVector,numRows-1,strNum,&parseStatus);
    527535                            arrayIndex++;
    528536                        } else if (strcmp(strValue,"\%ld") == 0) {
    529                             colVector = psVectorRecycle(colVector, numRows, colVector->type.type);
     537                            colVector = psVectorRecycle(colVector, numRows,
     538                                                        colVector->type.type);
    530539                            parseValue(colVector,numRows-1,strNum,&parseStatus);
    531540                            arrayIndex++;
    532541                        } else if (strcmp(strValue,"\%f") == 0) {
    533                             colVector = psVectorRecycle(colVector, numRows, colVector->type.type);
     542                            colVector = psVectorRecycle(colVector, numRows,
     543                                                        colVector->type.type);
    534544                            parseValue(colVector,numRows-1,strNum,&parseStatus);
    535545                            arrayIndex++;
    536546                        } else if (strcmp(strValue,"\%lf") == 0) {
    537                             colVector = psVectorRecycle(colVector, numRows, colVector->type.type);
     547                            colVector = psVectorRecycle(colVector, numRows,
     548                                                        colVector->type.type);
    538549                            parseValue(colVector,numRows-1,strNum,&parseStatus);
    539550                            arrayIndex++;
     
    544555                        psFree(strNum);
    545556
    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
    547559                        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.");
    549562                            fclose(fp);
    550563                            psFree(outputArray);
     
    556569            }
    557570
     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
    558581            // Read on the lines in the file - close file pointer
    559582            fclose(fp);
     
    562585    } else {
    563586        // 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");
    565589        psFree(outputArray);
    566590        return NULL;
     
    588612    // Check for invalid index column
    589613    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");
    591616        return NULL;
    592617    }
    593618
    594619    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);
    597622        return NULL;
    598623    }
     
    647672    } else {
    648673        // 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
    650676        table->index = vectors->data[indexCol];
    651677        table->values = (psArray*)vectors;
     
    806832
    807833    // 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);
    809835
    810836    // Find location in table where specified index is between to entries
     
    812838    while(index > convertVal ) {
    813839        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        */
    819847        CONVERT_VALUE_TO_F64(indexVec, hiIdx, convertVal)
    820848    }
     
    833861    denom -= convertVal;
    834862    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."));
    836865        return NAN;
    837866    } else {
     
    848877}
    849878
    850 psVector* psLookupTableInterpolateAll(
    851     const psLookupTable *table,
    852     double index)
     879psVector* psLookupTableInterpolateAll(const psLookupTable *table,
     880                                      double index)
    853881{
    854882    long numCols = 0;
  • trunk/psLib/src/types/psLookupTable.h

    r7545 r9714  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.14 $ $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 $
    1111*
    1212*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8080 */
    8181psLookupTable* psLookupTableAlloc(
    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)
     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)
    8585);
    8686
     
    9292 */
    9393psArray *psVectorsReadFromFile(
    94     const char* filename,            ///< File to be read
    95     const char* format               ///< scanf-like format string
     94    const char* filename,              ///< File to be read
     95    const char* format                 ///< scanf-like format string
    9696);
    9797
     
    115115 */
    116116long psLookupTableRead(
    117     psLookupTable *table            ///< Table to read
     117    psLookupTable *table               ///< Table to read
    118118);
    119119
     
    140140psVector* psLookupTableInterpolateAll(
    141141    const psLookupTable *table,         ///< Table with data
    142     double index                       ///< Value to be interpolated
     142    double index                        ///< Value to be interpolated
    143143);
    144144
  • trunk/psLib/test/types/tap_psLookupTable_all.c

    r9672 r9714  
    2424int main(void)
    2525{
    26     plan_tests(13);
     26    plan_tests(27);
    2727
    2828    diag("Tests for psLookupTable Functions");
     
    4646        lt = psLookupTableAlloc(NULL, "\%f \%lf \%d \%ld", 10);
    4747        ok( lt == NULL,
    48             "psLookupTableAlloc:            return NULL for NULL filename input.");
     48            "psLookupTableAlloc:               return NULL for NULL filename input.");
    4949    }
    5050    //Return NULL for NULL format input
    5151    {
    52         lt = psLookupTableAlloc("tableF32.dat", NULL, 10);
     52        lt = psLookupTableAlloc("table.dat", NULL, 10);
    5353        ok( lt == NULL,
    54             "psLookupTableAlloc:            return NULL for NULL format input.");
     54            "psLookupTableAlloc:               return NULL for NULL format input.");
    5555    }
    5656    //Return properly allocated lookupTable for valid inputs
    5757    {
    58         lt = psLookupTableAlloc("tableF32.dat", "\%f \%lf \%d \%ld", 10);
     58        lt = psLookupTableAlloc("table.dat", "\%f \%lf \%d \%ld", 10);
    5959        ok( lt != NULL && psMemCheckLookupTable(lt),
    60             "psLookupTableAlloc:            "
     60            "psLookupTableAlloc:               "
    6161            "return properly allocated lookupTable for valid inputs.");
    6262    }
     
    6767        int j = 2;
    6868        ok( !psMemCheckLookupTable(&j),
    69             "psMemCheckLookupTable:         return false for non-LookupTable input.");
     69            "psMemCheckLookupTable:            return false for non-LookupTable input.");
    7070    }
    7171
     
    8282    diag("  >>>Test 2:  psVectorsReadFromFile, psLookupTableImport, psLookupTableRead Fxns");
    8383    psArray *outVec = NULL;
     84    psArray *vectors = NULL;
    8485    psLookupTable*  table1  = NULL;
     86    psLookupTable*  tableOut  = NULL;
    8587    long           numRows = 0;
    86     char filename[30];
    87     strcpy(filename, "tableF32.dat");
    8888
    8989    //Tests for psVectorReadFromFile
     
    9393                                       "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf");
    9494        ok( outVec == NULL,
    95             "psVectorsReadFromFile:         return NULL for NULL filename input.");
     95            "psVectorsReadFromFile:            return NULL for NULL filename input.");
    9696    }
    9797    // Attempt to read from NULL format input
    9898    {
    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.");
    102102    }
    103103    // Attempt to read from invalid filename input
     
    106106                                       "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf");
    107107        ok( outVec == NULL,
    108             "psVectorsReadFromFile:         return NULL for invalid filename input.");
     108            "psVectorsReadFromFile:            return NULL for invalid filename input.");
    109109    }
    110110    // Attempt to read from invalid format input
    111111    {
    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
    118117    {
    119118        outVec = psVectorsReadFromFile("tableF32_err.dat",
    120119                                       "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf");
    121120        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
    125145    {
    126146        outVec = psVectorsReadFromFile("tableF32_2.dat",
    127147                                       "\%f \%d \%d \%ld \%d \%d \%d \%ld \%*d \%lf");
    128148        ok( outVec == NULL,
    129             "psVectorsReadFromFile:         return NULL for table containing invalid entry.");
    130     }
    131 
     149            "psVectorsReadFromFile:           return NULL for empty table.");
     150    }
    132151    //Attempt to read with valid inputs
    133152    {
    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
    144161    // Attempt to read table with NULL input table specified
    145162    numRows = psLookupTableRead(table1);
    146163    {
    147164        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    }
    272211
    273212    //Check for Memory leaks
    274213    {
     214        psFree(vectors);
    275215        psFree(outVec);
    276216        psFree(table1);
     
    283223{
    284224    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    }
    289284
    290285    //Check for Memory leaks
    291286    {
    292 
     287        psFree(table3);
     288        psFree(vec);
     289        psFree(table2);
     290        psFree(table1);
    293291        checkMem();
    294292    }
    295293
    296294}
    297 
    298 
    299 
    300 /*
    301     //Return NULL for NULL list input
    302 {
    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.