Changeset 1406 for trunk/psLib/test/dataManip/tst_psHist02.c
- Timestamp:
- Aug 6, 2004, 12:34:06 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psHist02.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psHist02.c
r1365 r1406 2 2 This routine must ensure that the psHistogram structure is correctly 3 3 populated by the procedure psGetArrayHistogram(). 4 4 5 5 *****************************************************************************/ 6 6 #include <stdio.h> … … 26 26 int i = 0; 27 27 int currentId = 0; 28 28 29 29 currentId = psMemGetId(); 30 30 31 31 /*********************************************************************/ 32 32 /* Allocate and initialize data structures */ … … 35 35 myData->n = myData->nalloc; 36 36 for ( i = 0;i < NUM_DATA;i++ ) { 37 myData->data.F32[ i ] = LOWER + ( ( UPPER - LOWER ) / ( float ) NUM_DATA ) * ( float ) i;38 }39 37 myData->data.F32[ i ] = LOWER + ( ( UPPER - LOWER ) / ( float ) NUM_DATA ) * ( float ) i; 38 } 39 40 40 myMask = psVectorAlloc( NUM_DATA, PS_TYPE_U8 ); 41 41 myMask->n = myMask->nalloc; 42 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 } 43 if ( i >= ( NUM_DATA / 2 ) ) { 44 myMask->data.U8[ i ] = 1; 45 } else { 46 myMask->data.U8[ i ] = 0; 48 47 } 49 48 } 49 50 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 ); 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 ] ); 109 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 ); 109 } 110 110 psFree( myMask ); 111 111 112 112 printPositiveTestHeader( stdout, 113 113 "psStats functions", 114 114 "Calling psVectorHistogram() with various NULL inputs." ); 115 115 116 116 // Verify the return value is null and program execution doesn't stop, 117 117 // if input parameter myHist is null. 118 118 119 119 myHist2 = psVectorHistogram( NULL, myData, NULL, 0 ); 120 120 if ( myHist2 != NULL ) { 121 printf( "ERROR: myHist2!=NULL\n" );122 testStatus = false;123 }121 printf( "ERROR: myHist2!=NULL\n" ); 122 testStatus = false; 123 } 124 124 psFree( myData ); 125 126 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 130 131 131 myHist = psHistogramAlloc( LOWER, UPPER, numBins ); 132 132 myHist = psVectorHistogram( myHist, NULL, NULL, 0 ); 133 133 if ( myHist == NULL ) { 134 printf( "ERROR: myHist==NULL\n" );135 testStatus = false;136 }134 printf( "ERROR: myHist==NULL\n" ); 135 testStatus = false; 136 } 137 137 psFree( myHist ); 138 139 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 … … 159 159 "Calling psVectorHistogram() with various NULL inputs.", 160 160 testStatus ); 161 161 162 162 /*************************************************************************/ 163 163 /* Deallocate data structures */ … … 166 166 "psStats functions", 167 167 "Deallocate the psHistogram structure." ); 168 168 169 169 psMemCheckCorruption( 1 ); 170 170 memLeaks = psMemCheckLeaks( currentId, NULL, NULL ); 171 171 if ( 0 != memLeaks ) { 172 psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks );173 }172 psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks ); 173 } 174 174 psMemCheckCorruption( 1 ); 175 175 176 176 printFooter( stdout, 177 177 "psStats functions", 178 178 "Deallocate the psHistogram structure.", 179 179 testStatus ); 180 180 181 181 return ( !testStatus ); 182 182 }
Note:
See TracChangeset
for help on using the changeset viewer.
