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_psHist01.c

    r887 r893  
    77#include "psTest.h"
    88#include "psMemory.h"
    9 #define MISC_FLOAT_NUMBER 345.0
    10 #define MISC_INT_NUMBER 345
    119#define LOWER 20.0
    1210#define UPPER 30.0
    13 #define NUM_BINS 200
    1411
    1512int main()
     
    2017    int memLeaks        = 0;
    2118    int i               = 0;
     19    int nb              = 0;
     20    int numBins         = 0;
    2221    int currentId       = 0;
    2322
    2423    currentId       = psMemGetId();
     24    for (nb=0;nb<4;nb++) {
     25        if (nb == 0)
     26            numBins = 1;
     27        if (nb == 1)
     28            numBins = 2;
     29        if (nb == 2)
     30            numBins = 10;
     31        if (nb == 3)
     32            numBins = 20;
     33        /*********************************************************************/
     34        /*  Allocate and initialize data structures                          */
     35        /*********************************************************************/
     36        printPositiveTestHeader(stdout,
     37                                "psStats functions",
     38                                "Allocate the psHistogram structure.");
     39        myBounds = psVectorAlloc(numBins+1, PS_TYPE_F32);
     40        myBounds->n = myBounds->nalloc;
     41        for (i=0;i<numBins+1;i++) {
     42            myBounds->data.F32[i] = LOWER + ((UPPER - LOWER) / (float) numBins) *
     43                                    (float) i;
     44        }
     45        myHist = psHistogramAllocGeneric(myBounds);
     46
     47        if (myHist->nums->n != numBins) {
     48            printf("ERROR: myHist->nums->n is wrong size (%d)\n", myHist->nums->n);
     49            testStatus = false;
     50        }
     51
     52        if (myHist->bounds->n != numBins+1) {
     53            printf("ERROR: myHist->bounds->n is wrong size (%d)\n", myHist->bounds->n);
     54            testStatus = false;
     55        }
     56
     57        for (i=0;i<numBins;i++) {
     58            if (myHist->nums->data.S32[i] != 0) {
     59                printf("ERROR: myHist->nums->data.S32[%d] not initialized to 0.\n", i);
     60                testStatus = false;
     61            }
     62            myHist->nums->data.S32[i] = 0;
     63        }
     64
     65        if (myHist->minNum != 0) {
     66            printf("ERROR: myHist->minNum is %d\n", myHist->minNum);
     67            testStatus = false;
     68        }
     69
     70        if (myHist->maxNum != 0) {
     71            printf("myHist->maxNum is %d\n", myHist->maxNum);
     72            testStatus = false;
     73        }
     74
     75        if (myHist->uniform != 0) {
     76            printf("ERROR: myHist->uniform is %d\n", myHist->uniform);
     77            testStatus = false;
     78        }
     79
     80        for (i=0;i<numBins;i++) {
     81            printf("Bin number %d bounds: (%f - %f)\n", i,
     82                   myHist->bounds->data.F32[i],
     83                   myHist->bounds->data.F32[i+1]);
     84        }
     85        psMemCheckCorruption(1);
     86        psHistogramFree(myHist);
     87        psMemCheckCorruption(1);
     88        psVectorFree(myBounds);
     89
     90        printFooter(stdout,
     91                    "psStats functions",
     92                    "Allocate the psHistogram structure.",
     93                    testStatus);
     94    }
    2595    /*************************************************************************/
    26     /*  Allocate and initialize data structures                      */
    27     /*************************************************************************/
    28     printPositiveTestHeader(stdout,
    29                             "psStats functions",
    30                             "Allocate the psHistogram structure.");
    31     myBounds = psVectorAlloc(NUM_BINS+1, PS_TYPE_F32);
    32     myBounds->n = myBounds->nalloc;
    33     for (i=0;i<NUM_BINS+1;i++) {
    34         myBounds->data.F32[i] = LOWER + ((UPPER - LOWER) / (float) NUM_BINS) *
    35                                 (float) i;
    36     }
    37     myHist = psHistogramAllocGeneric(myBounds);
    38 
    39     for (i=0;i<NUM_BINS;i++) {
    40         myHist->nums->data.S32[i] = MISC_INT_NUMBER;
    41     }
    42 
    43     for (i=0;i<NUM_BINS;i++) {
    44         printf("Bin number %d bounds: (%f - %f)\n", i,
    45                myHist->bounds->data.F32[i],
    46                myHist->bounds->data.F32[i+1]);
    47     }
    48     printf("myHist->minNum is %d\n", myHist->minNum);
    49     printf("myHist->maxNum is %d\n", myHist->maxNum);
    50     printf("myHist->uniform is %d\n", myHist->uniform);
    51 
    52     psMemCheckCorruption(1);
    53 
    54     printFooter(stdout,
    55                 "psStats functions",
    56                 "Allocate the psHistogram structure.",
    57                 testStatus);
    58 
    59     /*************************************************************************/
    60     /*  Deallocate data structures                                   */
     96    /*  Deallocate data structures                                           */
    6197    /*************************************************************************/
    6298    printPositiveTestHeader(stdout,
    6399                            "psStats functions",
    64100                            "Deallocate the psHistogram structure.");
    65     psHistogramFree(myHist);
    66     psVectorFree(myBounds);
    67 
    68101    psMemCheckCorruption(1);
    69102    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
Note: See TracChangeset for help on using the changeset viewer.