Changeset 1365 for trunk/psLib/test/dataManip/tst_psHist02.c
- Timestamp:
- Aug 2, 2004, 9:43:23 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psHist02.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psHist02.c
r1327 r1365 1 1 /***************************************************************************** 2 This routine must ensure that the psHistogram structure is correctly3 populated by the procedure psGetArrayHistogram().4 5 *****************************************************************************/2 This routine must ensure that the psHistogram structure is correctly 3 populated by the procedure psGetArrayHistogram(). 4 5 *****************************************************************************/ 6 6 #include <stdio.h> 7 7 #include "pslib.h" … … 16 16 int main() 17 17 { 18 psHistogram * myHist = NULL;19 psHistogram *myHist2 = NULL;20 psVector *myData = NULL;21 psVector *myMask = NULL;22 int testStatus = true;23 int memLeaks = 0;24 int nb = 0;25 int numBins = 0;26 int i = 0;27 int currentId = 0;28 29 currentId = psMemGetId();30 18 psHistogram * myHist = NULL; 19 psHistogram *myHist2 = NULL; 20 psVector *myData = NULL; 21 psVector *myMask = NULL; 22 int testStatus = true; 23 int memLeaks = 0; 24 int nb = 0; 25 int numBins = 0; 26 int i = 0; 27 int currentId = 0; 28 29 currentId = psMemGetId(); 30 31 31 /*********************************************************************/ 32 32 /* Allocate and initialize data structures */ 33 33 /*********************************************************************/ 34 myData = psVectorAlloc( NUM_DATA, PS_TYPE_F32);34 myData = psVectorAlloc( NUM_DATA, PS_TYPE_F32 ); 35 35 myData->n = myData->nalloc; 36 for ( i=0;i<NUM_DATA;i++) {37 myData->data.F32[i] = LOWER + ((UPPER - LOWER) / (float) NUM_DATA) * (float) i;38 }39 40 myMask = psVectorAlloc( NUM_DATA, PS_TYPE_U8);36 for ( i = 0;i < NUM_DATA;i++ ) { 37 myData->data.F32[ i ] = LOWER + ( ( UPPER - LOWER ) / ( float ) NUM_DATA ) * ( float ) i; 38 } 39 40 myMask = psVectorAlloc( NUM_DATA, PS_TYPE_U8 ); 41 41 myMask->n = myMask->nalloc; 42 for (i=0;i<NUM_DATA;i++) { 43 if (i >= (NUM_DATA/2)) { 44 myMask->data.U8[i] = 1; 45 } else { 46 myMask->data.U8[i] = 0; 42 for ( i = 0;i < NUM_DATA;i++ ) { 43 if ( i >= ( NUM_DATA / 2 ) ) { 44 myMask->data.U8[ i ] = 1; 45 } else { 46 myMask->data.U8[ i ] = 0; 47 } 47 48 } 48 } 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 = psVectorHistogram(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.U32[i]); 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 = psVectorHistogram( myHist, myData, NULL, 0 ); 69 70 for ( i = 0;i < numBins;i++ ) { 71 printf( "Bin number %d bounds: (%.2f - %.2f) data (%d)\n", i, 72 myHist->bounds->data.F32[ i ], 73 myHist->bounds->data.F32[ i + 1 ], 74 myHist->nums->data.U32[ i ] ); 75 } 76 psMemCheckCorruption( 1 ); 77 psFree( 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 = psVectorHistogram( myHist, myData, myMask, 1 ); 94 95 for ( i = 0;i < numBins;i++ ) { 96 printf( "Bin number %d bounds: (%6.3f - %6.3f) data (%d)\n", i, 97 myHist->bounds->data.F32[ i ], 98 myHist->bounds->data.F32[ i + 1 ], 99 myHist->nums->data.U32[ i ] ); 100 } 101 psMemCheckCorruption( 1 ); 102 psFree( myHist ); 103 psMemCheckCorruption( 1 ); 104 105 printFooter( stdout, 106 "psStats functions", 107 "Allocate and Perform Histogram with mask", 108 testStatus ); 75 109 } 76 psMemCheckCorruption(1); 77 psFree(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 = psVectorHistogram(myHist, myData, myMask, 1); 94 95 for (i=0;i<numBins;i++) { 96 printf("Bin number %d bounds: (%6.3f - %6.3f) data (%d)\n", i, 97 myHist->bounds->data.F32[i], 98 myHist->bounds->data.F32[i+1], 99 myHist->nums->data.U32[i]); 100 } 101 psMemCheckCorruption(1); 102 psFree(myHist); 103 psMemCheckCorruption(1); 104 105 printFooter(stdout, 106 "psStats functions", 107 "Allocate and Perform Histogram with mask", 108 testStatus); 109 } 110 psFree(myMask); 111 112 printPositiveTestHeader(stdout, 113 "psStats functions", 114 "Calling psVectorHistogram() with various NULL inputs."); 115 110 psFree( myMask ); 111 112 printPositiveTestHeader( stdout, 113 "psStats functions", 114 "Calling psVectorHistogram() with various NULL inputs." ); 115 116 116 // Verify the return value is null and program execution doesn't stop, 117 117 // if input parameter myHist is null. 118 119 myHist2 = psVectorHistogram( NULL, myData, NULL, 0);120 if ( myHist2 != NULL) {121 printf("ERROR: myHist2!=NULL\n");122 testStatus = false;123 }124 psFree( myData);125 126 118 119 myHist2 = psVectorHistogram( NULL, myData, NULL, 0 ); 120 if ( myHist2 != NULL ) { 121 printf( "ERROR: myHist2!=NULL\n" ); 122 testStatus = false; 123 } 124 psFree( myData ); 125 126 127 127 // Verify the retrun value is the same as the input parameter myHist and 128 128 // program execution doesn't stop, if the input parameter myArray is 129 129 // null. 130 131 myHist = psHistogramAlloc( LOWER, UPPER, numBins);132 myHist = psVectorHistogram( myHist, NULL, NULL, 0);133 if ( myHist == NULL) {134 printf("ERROR: myHist==NULL\n");135 testStatus = false;136 }137 psFree( myHist);138 139 130 131 myHist = psHistogramAlloc( LOWER, UPPER, numBins ); 132 myHist = psVectorHistogram( myHist, NULL, NULL, 0 ); 133 if ( myHist == NULL ) { 134 printf( "ERROR: myHist==NULL\n" ); 135 testStatus = false; 136 } 137 psFree( myHist ); 138 139 140 140 // Verify the return value is the same as the input parameter myHist and 141 141 // program execution doesn't stop, if the input parameter myArray has no … … 155 155 psFree(myData); 156 156 */ 157 printFooter( stdout,158 "psStats functions",159 "Calling psVectorHistogram() with various NULL inputs.",160 testStatus);161 157 printFooter( stdout, 158 "psStats functions", 159 "Calling psVectorHistogram() with various NULL inputs.", 160 testStatus ); 161 162 162 /*************************************************************************/ 163 163 /* Deallocate data structures */ 164 164 /*************************************************************************/ 165 printPositiveTestHeader( stdout,166 "psStats functions",167 "Deallocate the psHistogram structure.");168 169 psMemCheckCorruption( 1);170 memLeaks = psMemCheckLeaks( currentId,NULL,NULL);171 if ( 0 != memLeaks) {172 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);173 }174 psMemCheckCorruption( 1);175 176 printFooter( stdout,177 "psStats functions",178 "Deallocate the psHistogram structure.",179 testStatus);180 181 return ( !testStatus);165 printPositiveTestHeader( stdout, 166 "psStats functions", 167 "Deallocate the psHistogram structure." ); 168 169 psMemCheckCorruption( 1 ); 170 memLeaks = psMemCheckLeaks( currentId, NULL, NULL ); 171 if ( 0 != memLeaks ) { 172 psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks ); 173 } 174 psMemCheckCorruption( 1 ); 175 176 printFooter( stdout, 177 "psStats functions", 178 "Deallocate the psHistogram structure.", 179 testStatus ); 180 181 return ( !testStatus ); 182 182 }
Note:
See TracChangeset
for help on using the changeset viewer.
