Changeset 887 for trunk/psLib/test/dataManip/tst_psStats01.c
- Timestamp:
- Jun 6, 2004, 2:31:55 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psStats01.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psStats01.c
r717 r887 1 1 /***************************************************************************** 2 2 This routine must ensure that PS_STAT_MAX is correctly computed 3 by the procedure ps ArrayStats().3 by the procedure psVectorStats(). 4 4 *****************************************************************************/ 5 5 #include <stdio.h> … … 11 11 { 12 12 psStats *myStats = NULL; 13 psStats *myStats2 = NULL;14 13 int testStatus = true; 14 int globalTestStatus = true; 15 15 int i = 0; 16 16 psVector *myVector = NULL; 17 17 psVector *maskVector= NULL; 18 18 float max = 0.0; 19 float realMax1 = 0.0; 20 float realMax2 = 0.0; 19 float realMaxNoMask = 0.0; 20 float realMaxWithMask = 0.0; 21 int currentId = psMemGetId(); 22 int memLeaks = 0; 21 23 22 printPositiveTestHeader(stdout, 23 "psStats functions", 24 "PS_STAT_MAX"); 25 24 /*************************************************************************/ 25 /* Allocate and initialize data structures */ 26 /*************************************************************************/ 26 27 myStats = psStatsAlloc(PS_STAT_MAX); 27 myVector = psVectorAlloc( PS_TYPE_FLOAT, N);28 myVector = psVectorAlloc(N, PS_TYPE_F32); 28 29 myVector->n = N; 29 maskVector = psVectorAlloc( PS_TYPE_UINT8, N);30 maskVector = psVectorAlloc(N, PS_TYPE_U8); 30 31 maskVector->n = N; 31 32 33 // Set the appropriate values for the vector data. 32 34 for (i=0;i<N;i++) { 33 myVector->vec.f[i] = (float) i; 35 myVector->data.F32[i] = (float) i; 36 } 37 38 // Set the mask vector and calculate the expected maximum. 39 for (i=0;i<N;i++) { 40 if (myVector->data.F32[i] > realMaxNoMask) { 41 realMaxNoMask = myVector->data.F32[i]; 42 } 43 34 44 if (i < (N/2)) { 35 maskVector->vec.ui8[i] = 0; 36 if (myVector->vec.f[i] > realMax2) { 37 realMax2 = myVector->vec.f[i]; 45 maskVector->data.U8[i] = 0; 46 47 if (myVector->data.F32[i] > realMaxWithMask) { 48 realMaxWithMask = myVector->data.F32[i]; 38 49 } 39 50 } else { 51 maskVector->data.U8[i] = 1; 40 52 printf("Masking element %d\n", i); 41 maskVector->vec.ui8[i] = 1;42 if (myVector->vec.f[i] > realMax1) {43 realMax1 = myVector->vec.f[i];44 }45 53 } 46 54 } 47 55 48 myStats2 = psArrayStats(myVector, NULL, 0, myStats); 49 max = myStats2->max; 56 /*************************************************************************/ 57 /* Call psVectorStats() with no vector mask. */ 58 /*************************************************************************/ 59 printPositiveTestHeader(stdout, 60 "psStats functions", 61 "PS_STAT_MAX: no vector mask"); 50 62 51 printf("Called psArrayStats() on a vector with no elements masked.\n"); 52 printf("The expected max was %f; the calculated max was %f\n", realMax1, max); 53 if (max == realMax1) { 63 myStats = psVectorStats(myStats, myVector, NULL, 0); 64 max = myStats->max; 65 66 printf("Called psVectorStats() on a vector with no elements masked.\n"); 67 printf("The expected max was %f; the calculated max was %f\n", realMaxNoMask, max); 68 if (max == realMaxNoMask) { 54 69 testStatus = true; 55 70 } else { 56 71 testStatus = false; 72 globalTestStatus = false; 57 73 } 74 printFooter(stdout, 75 "psVector functions", 76 "PS_STAT_MAX: no vector mask", 77 testStatus); 58 78 59 myStats2 = psArrayStats(myVector, maskVector, 1, myStats); 60 max = myStats2->max; 61 printf("Called psArrayStats() on a vector with last N/2 elements masked.\n"); 62 printf("The expected max was %f; the calculated max was %f\n", realMax2, max); 63 if (max == realMax2) { 79 /*************************************************************************/ 80 /* Call psVectorStats() with vector mask. */ 81 /*************************************************************************/ 82 printPositiveTestHeader(stdout, 83 "psStats functions", 84 "PS_STAT_MAX: with vector mask"); 85 86 myStats = psVectorStats(myStats, myVector, maskVector, 1); 87 max = myStats->max; 88 printf("Called psVectorStats() on a vector with last N/2 elements masked.\n"); 89 printf("The expected max was %f; the calculated max was %f\n", realMaxWithMask, max); 90 if (max == realMaxWithMask) { 64 91 testStatus = true; 65 92 } else { 66 93 testStatus = false; 94 globalTestStatus = false; 67 95 } 68 96 69 97 printFooter(stdout, 70 "ps Hashfunctions",71 " psHashAlloc()",98 "psVector functions", 99 "PS_STAT_MAX: with vector mask", 72 100 testStatus); 73 101 74 return (!testStatus); 102 /*************************************************************************/ 103 /* Deallocate data structures */ 104 /*************************************************************************/ 105 printPositiveTestHeader(stdout, 106 "psStats functions", 107 "psStats(): deallocating memory"); 108 109 psStatsFree(myStats); 110 psVectorFree(myVector); 111 psVectorFree(maskVector); 112 113 psMemCheckCorruption(1); 114 memLeaks = psMemCheckLeaks(currentId,NULL,NULL); 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); 75 125 }
Note:
See TracChangeset
for help on using the changeset viewer.
