Changeset 3535
- Timestamp:
- Mar 28, 2005, 1:54:14 PM (21 years ago)
- Location:
- trunk/psLib/test/dataManip
- Files:
-
- 1 added
- 2 edited
-
tst_psStats02.c (modified) (3 diffs)
-
verified/tst_psStats02.stderr (added)
-
verified/tst_psStats02.stdout (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psStats02.c
r2780 r3535 1 /***************************************************************************** 2 This routine must ensure that PS_STAT_MIN is correctly computed 3 by the procedure psVectorStats(). 4 *****************************************************************************/ 5 #include <stdio.h> 1 /** @file tst_psStats02.c 2 * 3 * @brief Contains tests for psVectorStats with min calculations 4 * 5 * @author George Gusciora, MHPCC 6 * 7 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-03-28 23:54:14 $ 9 * 10 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii 11 */ 12 6 13 #include "pslib.h" 7 14 #include "psTest.h" 8 #define N 10 9 10 psS32 main() 11 { 12 psStats *myStats = NULL; 13 psS32 testStatus = true; 14 psS32 globalTestStatus = true; 15 psS32 i = 0; 16 psVector *myVector = NULL; 17 psVector *maskVector= NULL; 18 float min = 1e99; 19 float realMinNoMask = 1e99; 20 float realMinWithMask = 1e99; 21 psS32 currentId = psMemGetId(); 22 psS32 memLeaks = 0; 15 16 #define N 15 17 #define ERROR_TOL 0.0001 18 19 static psS32 testStatsMinF32(void); 20 static psS32 testStatsMinS8(void); 21 static psS32 testStatsMinU16(void); 22 static psS32 testStatsMinF64(void); 23 24 testDescription tests[] = { 25 {testStatsMinF32, 518, "psVectorStats", 0, false}, 26 {testStatsMinS8, 518, "psVectorStats", 0, false}, 27 {testStatsMinU16, 518, "psVectorStats", 0, false}, 28 {testStatsMinF64, 518, "psVectorStats", 0, false}, 29 {NULL} 30 }; 31 32 static psF32 samplesF32[N] = { 1.1, 2.2, -3.3, 4.4, 5.5, -6.6, 7.7, 8.8, -9.9, 10.0, 33 11.01, -12.02, 13.03, 14.04, -15.05 }; 34 static psS8 samplesS8[N] = {1, 2, -3, 4, 5, -6, 7, 8, -9, 10, 11, -12, 13, 14, -15}; 35 static psU16 samplesU16[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 36 static psF64 samplesF64[N] = { 1.1, 2.2, -3.3, 4.4, 5.5, -6.6, 7.7, 8.8, -9.9, 10.0, 37 11.01, -12.02, 13.03, 14.04, -15.05 }; 38 39 static psF64 expectedMinNoMaskF32 = -15.05; 40 static psF64 expectedMinNoMaskS8 = -15.00; 41 static psF64 expectedMinNoMaskU16 = 1.00; 42 static psF64 expectedMinNoMaskF64 = -15.05; 43 44 static psF64 expectedMinWithMaskF32 = -12.02; 45 static psF64 expectedMinRangeNoMaskF32 = 1.10; 46 static psF64 expectedMinRangeWithMaskF32 = -12.02; 47 48 psS32 main(psS32 argc, char* argv[] ) 49 { 50 psLogSetLevel(PS_LOG_INFO); 51 52 return ( ! runTestSuite(stderr, "psVectorStats", tests, argc, argv) ); 53 } 54 55 psS32 testStatsMinF32(void) 56 { 57 psStats* myStats = NULL; 58 psVector* myVector = NULL; 59 psVector* maskVector = NULL; 60 psF64 min = 0.0; 23 61 24 62 /*************************************************************************/ … … 32 70 33 71 // Set the appropriate values for the vector data. 34 for (i=0;i<N;i++) { 35 myVector->data.F32[i] = (float) i; 36 } 37 38 // Set the mask vector and calculate the expected minimum. 39 for (i=0;i<N;i++) { 40 if (myVector->data.F32[i] < realMinNoMask) { 41 realMinNoMask = myVector->data.F32[i]; 72 for (psS32 i = 0; i < N; i++) { 73 myVector->data.F32[i] = samplesF32[i]; 74 } 75 76 // Set the mask vector and calculate the expected maximum. 77 for (psS32 i = 0; i < N; i++) { 78 if (i < 13) { 79 maskVector->data.U8[i] = 0; 80 } else { 81 maskVector->data.U8[i] = 1; 42 82 } 43 44 if (i < (N/2)) { 45 maskVector->data.U8[i] = 1; 46 } else { 47 maskVector->data.U8[i] = 0; 48 if (myVector->data.F32[i] < realMinWithMask) { 49 realMinWithMask = myVector->data.F32[i]; 50 } 51 } 52 } 53 54 /*************************************************************************/ 55 /* Call psVectorStats() with no vector mask. */ 56 /*************************************************************************/ 57 printPositiveTestHeader(stdout, 58 "psStats functions", 59 "PS_STAT_MIN: no vector mask"); 60 61 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 62 min = myStats->min; 63 64 printf("Called psVectorStats() on a vector with no elements masked.\n"); 65 printf("The expected min was %f; the calculated min was %f\n", 66 realMinNoMask, min); 67 if (min == realMinNoMask) { 68 testStatus = true; 69 } else { 70 testStatus = false; 71 globalTestStatus = false; 72 } 73 printFooter(stdout, 74 "psVector functions", 75 "PS_STAT_MIN: no vector mask", 76 testStatus); 83 } 84 85 /*************************************************************************/ 86 /* Call psVectorStats() with no vector mask. */ 87 /*************************************************************************/ 88 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 89 min = myStats->min; 90 91 if (fabs(min - expectedMinNoMaskF32) > ERROR_TOL) { 92 psError(PS_ERR_UNKNOWN,true,"Min no mask return value %lf not as expected %lf", 93 min, expectedMinNoMaskF32); 94 return 1; 95 } 77 96 78 97 /*************************************************************************/ 79 98 /* Call psVectorStats() with vector mask. */ 80 99 /*************************************************************************/ 81 printPositiveTestHeader(stdout,82 "psStats functions",83 "PS_STAT_MIN: with vector mask");84 85 100 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 86 101 min = myStats->min; 87 printf("Called psVectorStats() on a vector with last N/2 elements masked.\n"); 88 printf("The expected min was %f; the calculated min was %f\n", 89 realMinWithMask, min); 90 if (min == realMinWithMask) { 91 testStatus = true; 92 } else { 93 testStatus = false; 94 globalTestStatus = false; 95 } 96 97 printFooter(stdout, 98 "psVector functions", 99 "PS_STAT_MIN: with vector mask", 100 testStatus); 101 102 /*************************************************************************/ 103 /* Deallocate data structures */ 104 /*************************************************************************/ 105 printPositiveTestHeader(stdout, 106 "psStats functions", 107 "psStats(): deallocating memory"); 102 if (fabs(min - expectedMinWithMaskF32) > ERROR_TOL) { 103 psError(PS_ERR_UNKNOWN,true,"Min with mask return value %lf not as expected %lf", 104 min, expectedMinWithMaskF32); 105 return 2; 106 } 107 108 // Invoke function with data range with no mask 109 myStats->options = PS_STAT_MIN | PS_STAT_USE_RANGE; 110 myStats->max = 10.1; 111 myStats->min = 0.0; 112 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 113 min = myStats->min; 114 115 if(fabs(min - expectedMinRangeNoMaskF32) > ERROR_TOL) { 116 psError(PS_ERR_UNKNOWN,true,"Min with range no mask %lf not as expected %lf", 117 min, expectedMinRangeNoMaskF32); 118 return 3; 119 } 120 121 // Invoke function with data range and mask 122 myStats->max = 10.1; 123 myStats->min = -15.00; 124 myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1); 125 min = myStats->min; 126 if(fabs(min - expectedMinRangeWithMaskF32) > ERROR_TOL) { 127 psError(PS_ERR_UNKNOWN,true,"Min with range with mask %lf not as expected %lf", 128 min, expectedMinRangeWithMaskF32); 129 return 3; 130 } 131 132 // Invoke function with data range with no valid data 133 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 134 myStats->max = 100.00; 135 myStats->min = 90.00; 136 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 137 min = myStats->min; 138 139 if(!isnan(min)) { 140 psError(PS_ERR_UNKNOWN,true,"Min with range with no valid elemenets did not return NAN"); 141 return 4; 142 } 108 143 109 144 psFree(myStats); … … 111 146 psFree(maskVector); 112 147 113 psMemCheckCorruption(1); 114 memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false); 115 if (0 != memLeaks) { 116 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 117 } 118 119 printFooter(stdout, 120 "psVector functions", 121 "psStats(): deallocating memory", 122 testStatus); 123 124 return (!globalTestStatus); 125 } 148 return 0; 149 } 150 151 psS32 testStatsMinS8(void) 152 { 153 psStats* myStats = NULL; 154 psVector* myVector = NULL; 155 psF64 min = 0.0; 156 157 /*************************************************************************/ 158 /* Allocate and initialize data structures */ 159 /*************************************************************************/ 160 myStats = psStatsAlloc(PS_STAT_MIN); 161 myVector = psVectorAlloc(N, PS_TYPE_S8); 162 myVector->n = N; 163 164 // Set the appropriate values for the vector data. 165 for (psS32 i = 0; i < N; i++) { 166 myVector->data.S8[i] = samplesS8[i]; 167 } 168 169 /*************************************************************************/ 170 /* Call psVectorStats() with no vector mask. */ 171 /*************************************************************************/ 172 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 173 min = myStats->min; 174 175 if (fabs(min - expectedMinNoMaskS8) > ERROR_TOL) { 176 psError(PS_ERR_UNKNOWN,true,"Min no mask return value %lf not as expected %lf", 177 min, expectedMinNoMaskS8); 178 return 1; 179 } 180 181 psFree(myStats); 182 psFree(myVector); 183 184 return 0; 185 } 186 187 psS32 testStatsMinU16(void) 188 { 189 psStats* myStats = NULL; 190 psVector* myVector = NULL; 191 psF64 min = 0.0; 192 193 /*************************************************************************/ 194 /* Allocate and initialize data structures */ 195 /*************************************************************************/ 196 myStats = psStatsAlloc(PS_STAT_MAX); 197 myVector = psVectorAlloc(N, PS_TYPE_U16); 198 myVector->n = N; 199 200 // Set the appropriate values for the vector data. 201 for (psS32 i = 0; i < N; i++) { 202 myVector->data.U16[i] = samplesU16[i]; 203 } 204 205 /*************************************************************************/ 206 /* Call psVectorStats() with no vector mask. */ 207 /*************************************************************************/ 208 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 209 min = myStats->min; 210 211 if (fabs(min - expectedMinNoMaskU16) > ERROR_TOL) { 212 psError(PS_ERR_UNKNOWN,true,"Min no mask return value %lf not as expected %lf", 213 min, expectedMinNoMaskU16); 214 return 1; 215 } 216 217 psFree(myStats); 218 psFree(myVector); 219 220 return 0; 221 } 222 223 psS32 testStatsMinF64(void) 224 { 225 psStats* myStats = NULL; 226 psVector* myVector = NULL; 227 psF64 min = 0.0; 228 229 /*************************************************************************/ 230 /* Allocate and initialize data structures */ 231 /*************************************************************************/ 232 myStats = psStatsAlloc(PS_STAT_MIN); 233 myVector = psVectorAlloc(N, PS_TYPE_F64); 234 myVector->n = N; 235 236 // Set the appropriate values for the vector data. 237 for (psS32 i = 0; i < N; i++) { 238 myVector->data.F64[i] = samplesF64[i]; 239 } 240 241 /*************************************************************************/ 242 /* Call psVectorStats() with no vector mask. */ 243 /*************************************************************************/ 244 myStats = psVectorStats(myStats, myVector, NULL, NULL, 0); 245 min = myStats->min; 246 247 if (fabs(min - expectedMinNoMaskF64) > ERROR_TOL) { 248 psError(PS_ERR_UNKNOWN,true,"Min no mask return value %lf not as expected %lf", 249 min, expectedMinNoMaskF64); 250 return 1; 251 } 252 253 psFree(myStats); 254 psFree(myVector); 255 256 return 0; 257 } 258 -
trunk/psLib/test/dataManip/verified/tst_psStats02.stdout
r1034 r3535 1 /***************************** TESTPOINT ******************************************\2 * TestFile: tst_psStats02.c *3 * TestPoint: psStats functions{PS_STAT_MIN: no vector mask} *4 * TestType: Positive *5 \**********************************************************************************/6 7 Called psVectorStats() on a vector with no elements masked.8 The expected min was 0.000000; the calculated min was 0.0000009 10 ---> TESTPOINT PASSED (psVector functions{PS_STAT_MIN: no vector mask} | tst_psStats02.c)11 12 /***************************** TESTPOINT ******************************************\13 * TestFile: tst_psStats02.c *14 * TestPoint: psStats functions{PS_STAT_MIN: with vector mask} *15 * TestType: Positive *16 \**********************************************************************************/17 18 Called psVectorStats() on a vector with last N/2 elements masked.19 The expected min was 5.000000; the calculated min was 5.00000020 21 ---> TESTPOINT PASSED (psVector functions{PS_STAT_MIN: with vector mask} | tst_psStats02.c)22 23 /***************************** TESTPOINT ******************************************\24 * TestFile: tst_psStats02.c *25 * TestPoint: psStats functions{psStats(): deallocating memory} *26 * TestType: Positive *27 \**********************************************************************************/28 29 30 ---> TESTPOINT PASSED (psVector functions{psStats(): deallocating memory} | tst_psStats02.c)31
Note:
See TracChangeset
for help on using the changeset viewer.
