IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 6, 2004, 5:14:39 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psHist02.c

    r887 r893  
    1212#define LOWER 20.0
    1313#define UPPER 30.0
    14 #define NUM_BINS 20
    1514#define NUM_DATA 10000
    1615
     
    1817{
    1918    psHistogram *myHist = NULL;
     19    psHistogram *myHist2= NULL;
    2020    psVector *myData    = NULL;
    2121    psVector *myMask    = NULL;
    2222    int testStatus      = true;
    2323    int memLeaks        = 0;
     24    int nb              = 0;
     25    int numBins         = 0;
    2426    int i               = 0;
    2527    int currentId       = 0;
     
    2729    currentId       = psMemGetId();
    2830
     31    /*********************************************************************/
     32    /*  Allocate and initialize data structures                          */
     33    /*********************************************************************/
    2934    myData = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
    3035    myData->n = myData->nalloc;
     
    4247        }
    4348    }
    44     /*************************************************************************/
    45     /*  Allocate and Perform Histogram, no mask                      */
    46     /*************************************************************************/
     49
     50    for (nb=0;nb<4;nb++) {
     51        if (nb == 0)
     52            numBins = 1;
     53        if (nb == 1)
     54            numBins = 2;
     55        if (nb == 2)
     56            numBins = 10;
     57        if (nb == 3)
     58            numBins = 20;
     59
     60        /*********************************************************************/
     61        /*  Allocate and Perform Histogram, no mask                          */
     62        /*********************************************************************/
     63        printPositiveTestHeader(stdout,
     64                                "psStats functions",
     65                                "Allocate and Perform Histogram, no mask");
     66
     67        myHist = psHistogramAlloc(LOWER, UPPER, numBins);
     68        myHist = psHistogramVector(myHist, myData, NULL, 0);
     69
     70        for (i=0;i<numBins;i++) {
     71            printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
     72                   myHist->bounds->data.F32[i],
     73                   myHist->bounds->data.F32[i+1],
     74                   myHist->nums->data.S32[i]);
     75        }
     76        psMemCheckCorruption(1);
     77        psHistogramFree(myHist);
     78        psMemCheckCorruption(1);
     79
     80        printFooter(stdout,
     81                    "psStats functions",
     82                    "Allocate and Perform Histogram, no mask",
     83                    testStatus);
     84
     85        /*********************************************************************/
     86        /*  Allocate and Perform Histogram with mask                         */
     87        /*********************************************************************/
     88        printPositiveTestHeader(stdout,
     89                                "psStats functions",
     90                                "Allocate and Perform Histogram with mask");
     91
     92        myHist = psHistogramAlloc(LOWER, UPPER, numBins);
     93        myHist = psHistogramVector(myHist, myData, myMask, 1);
     94
     95        for (i=0;i<numBins;i++) {
     96            printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
     97                   myHist->bounds->data.F32[i],
     98                   myHist->bounds->data.F32[i+1],
     99                   myHist->nums->data.S32[i]);
     100        }
     101        psMemCheckCorruption(1);
     102        psHistogramFree(myHist);
     103        psMemCheckCorruption(1);
     104
     105        printFooter(stdout,
     106                    "psStats functions",
     107                    "Allocate and Perform Histogram with mask",
     108                    testStatus);
     109    }
     110    psVectorFree(myMask);
     111
    47112    printPositiveTestHeader(stdout,
    48113                            "psStats functions",
    49                             "Allocate and Perform Histogram, no mask");
     114                            "Calling psHistogramVector() with various NULL inputs.");
    50115
    51     myHist = psHistogramAlloc(LOWER, UPPER, NUM_BINS);
    52     myHist = psHistogramVector(myHist, myData, NULL, 0);
     116    // Verify the return value is null and program execution doesn't stop,
     117    // if input parameter myHist is null.
    53118
    54     for (i=0;i<NUM_BINS;i++) {
    55         printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
    56                myHist->bounds->data.F32[i],
    57                myHist->bounds->data.F32[i+1],
    58                myHist->nums->data.S32[i]);
     119    myHist2 = psHistogramVector(NULL, myData, NULL, 0);
     120    if (myHist2 != NULL) {
     121        printf("ERROR: myHist2!=NULL\n");
     122        testStatus = false;
     123    }
     124    psVectorFree(myData);
     125
     126
     127    // Verify the retrun value is the same as the input parameter myHist and
     128    // program execution doesn't stop, if the input parameter myArray is
     129    // null.
     130
     131    myHist = psHistogramAlloc(LOWER, UPPER, numBins);
     132    myHist = psHistogramVector(myHist, NULL, NULL, 0);
     133    if (myHist == NULL) {
     134        printf("ERROR: myHist==NULL\n");
     135        testStatus = false;
    59136    }
    60137    psHistogramFree(myHist);
    61138
     139
     140    // Verify the return value is the same as the input parameter myHist and
     141    // program execution doesn't stop, if the input parameter myArray has no
     142    // elements.
     143    // NOTE: This code segment is commented out because psVectorAlloc returns
     144    // NULL if called with an N element data.
     145    /*
     146    myData = psVectorAlloc(0, PS_TYPE_F32);
     147    myData->n = myData->nalloc;
     148    myHist = psHistogramAlloc(LOWER, UPPER, numBins);
     149    myHist = psHistogramVector(myHist, NULL, NULL, 0);
     150    if (myHist == NULL) {
     151        printf("ERROR: myHist==NULL\n");
     152        testStatus = false;
     153    }
     154    psHistogramFree(myHist);
     155    psVectorFree(myData);
     156    */
    62157    printFooter(stdout,
    63158                "psStats functions",
    64                 "Allocate and Perform Histogram, no mask",
    65                 testStatus);
    66 
    67     /*************************************************************************/
    68     /*  Allocate and Perform Histogram with mask                     */
    69     /*************************************************************************/
    70     printPositiveTestHeader(stdout,
    71                             "psStats functions",
    72                             "Allocate and Perform Histogram with mask");
    73 
    74     myHist = psHistogramAlloc(LOWER, UPPER, NUM_BINS);
    75     myHist = psHistogramVector(myHist, myData, myMask, 1);
    76 
    77     for (i=0;i<NUM_BINS;i++) {
    78         printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
    79                myHist->bounds->data.F32[i],
    80                myHist->bounds->data.F32[i+1],
    81                myHist->nums->data.S32[i]);
    82     }
    83 
    84     printFooter(stdout,
    85                 "psStats functions",
    86                 "Allocate and Perform Histogram with mask",
     159                "Calling psHistogramVector() with various NULL inputs.",
    87160                testStatus);
    88161
     
    93166                            "psStats functions",
    94167                            "Deallocate the psHistogram structure.");
    95     psHistogramFree(myHist);
    96     psVectorFree(myData);
    97     psVectorFree(myMask);
    98168
    99169    psMemCheckCorruption(1);
Note: See TracChangeset for help on using the changeset viewer.