Changeset 887
- Timestamp:
- Jun 6, 2004, 2:31:55 PM (22 years ago)
- Location:
- trunk/psLib/test
- Files:
-
- 13 added
- 6 edited
-
dataManip/Makefile (modified) (4 diffs)
-
dataManip/tst_psFunc00.c (added)
-
dataManip/tst_psFunc01.c (added)
-
dataManip/tst_psHist00.c (added)
-
dataManip/tst_psHist01.c (added)
-
dataManip/tst_psHist02.c (added)
-
dataManip/tst_psStats00.c (modified) (1 diff)
-
dataManip/tst_psStats01.c (modified) (2 diffs)
-
dataManip/tst_psStats02.c (modified) (2 diffs)
-
dataManip/tst_psStats03.c (modified) (2 diffs)
-
dataManip/tst_psStats04.c (modified) (4 diffs)
-
dataManip/tst_psStats05.c (added)
-
dataManip/tst_psStats06.c (added)
-
dataManip/tst_psStats07.c (added)
-
dataManip/tst_psStats08.c (added)
-
dataManip/tst_psStats09.c (added)
-
image/tst_psImageStats00.c (added)
-
image/tst_psImageStats01.c (added)
-
image/tst_psImageStats02.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/Makefile
r815 r887 3 3 ## Makefile: test/sysUtils 4 4 ## 5 ## $Revision: 1. 8$ $Name: not supported by cvs2svn $6 ## $Date: 2004-0 5-29 01:15:41$5 ## $Revision: 1.9 $ $Name: not supported by cvs2svn $ 6 ## $Date: 2004-06-07 00:31:55 $ 7 7 ## 8 8 ## Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 17 17 18 18 TARGET = tst_psMatrix01 \ 19 tst_psMatrix02 \ 20 tst_psMatrix03 \ 21 tst_psMatrix04 \ 22 tst_psMatrix05 \ 23 tst_psMatrix06 \ 24 tst_psMatrix07 25 # tst_psStats00 \ 26 # tst_psStats01 \ 27 # tst_psStats02 \ 28 # tst_psStats03 \ 29 # tst_psStats04 19 tst_psMatrix02 \ 20 tst_psMatrix03 \ 21 tst_psMatrix04 \ 22 tst_psMatrix05 \ 23 tst_psMatrix06 \ 24 tst_psMatrix07 \ 25 tst_psStats00 \ 26 tst_psStats01 \ 27 tst_psStats02 \ 28 tst_psStats03 \ 29 tst_psStats05 \ 30 tst_psStats06 \ 31 tst_psStats07 \ 32 tst_psStats08 \ 33 tst_psStats09 \ 34 tst_psHist00 \ 35 tst_psHist01 \ 36 tst_psHist02 \ 37 tst_psFunc00 \ 38 tst_psFunc01 \ 39 tst_psImageStats00 \ 40 tst_psImageStats01 \ 41 tst_psImageStats02 30 42 31 43 all: $(TARGET) … … 43 55 tst_psStats03: tst_psStats03.o 44 56 tst_psStats04: tst_psStats04.o 57 tst_psStats05: tst_psStats05.o 58 tst_psStats06: tst_psStats06.o 59 tst_psStats07: tst_psStats07.o 60 tst_psStats08: tst_psStats08.o 61 tst_psStats09: tst_psStats09.o 62 tst_psHist00: tst_psHist00.o 63 tst_psHist01: tst_psHist01.o 64 tst_psHist02: tst_psHist02.o 65 tst_psFunc00: tst_psFunc00.o 66 tst_psFunc01: tst_psFunc01.o 67 tst_psFunc02: tst_psFunc02.o 68 tst_psFunc03: tst_psFunc03.o 69 tst_psImageStats00: tst_psImageStats00.o 70 tst_psImageStats01: tst_psImageStats01.o 71 tst_psImageStats02: tst_psImageStats02.o 72 tst_psImageStats03: tst_psImageStats03.o 45 73 46 74 clean: … … 54 82 $(CC) -o $@ $< -L$(PSLIB_LIB_DIR) -lpslib -lpstest -lgsl -lgslcblas $(LDFLAGS) 55 83 84 ## NOTE: The distclean target does not remove the .o files. The Makefiles must 85 ## be repaired. 86 distclean: 87 $(RM) $(TARGET) 88 56 89 %.lint: %.c 57 90 splint +posixlib -exportlocal -realcompare $(INCLUDE_GLOBAL) $? > $@; cat $@ -
trunk/psLib/test/dataManip/tst_psStats00.c
r717 r887 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 mean = 0.0; 19 float realMean 1= 0.0;20 float realMean 2= 0.0;19 float realMeanNoMask = 0.0; 20 float realMeanWithMask = 0.0; 21 21 int count = 0; 22 int currentId = psMemGetId(); 23 int memLeaks = 0; 22 24 23 printPositiveTestHeader(stdout, 24 "psStats functions", 25 "PS_STAT_SAMPLE_MEAN"); 26 25 /*************************************************************************/ 26 /* Allocate and initialize data structures */ 27 /*************************************************************************/ 27 28 myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 28 myVector = psVectorAlloc( PS_TYPE_FLOAT, N);29 myVector = psVectorAlloc(N, PS_TYPE_F32); 29 30 myVector->n = N; 30 maskVector = psVectorAlloc( PS_TYPE_UINT8, N);31 maskVector = psVectorAlloc(N, PS_TYPE_U8); 31 32 maskVector->n = N; 32 33 33 34 mean = 0.0; 34 realMean2 = 0.0; 35 realMeanWithMask = 0.0; 36 // Set the appropriate values for the vector data. 35 37 for (i=0;i<N;i++) { 36 myVector->vec.f[i] = (float) i; 38 myVector->data.F32[i] = (float) i; 39 } 40 41 // Set the mask vector and calculate the expected maximum. 42 for (i=0;i<N;i++) { 43 realMeanNoMask+= myVector->data.F32[i]; 44 37 45 if (i < (N/2)) { 38 maskVector-> vec.ui8[i] = 0;39 realMean 2+= myVector->vec.f[i];46 maskVector->data.U8[i] = 0; 47 realMeanWithMask+= myVector->data.F32[i]; 40 48 count++; 41 49 } else { 42 printf("Masking element %d\n", i); 43 maskVector->vec.ui8[i] = 1; 50 maskVector->data.U8[i] = 1; 44 51 } 45 realMean1+= myVector->vec.f[i];46 52 } 47 realMean 1/= (float) N;48 realMean 2/= (float) count;53 realMeanNoMask /= (float) N; 54 realMeanWithMask /= (float) count; 49 55 50 myStats2 = psArrayStats(myVector, NULL, 0, myStats); 51 mean = myStats2->sampleMean; 56 /*************************************************************************/ 57 /* Call psVectorStats() with no vector mask. */ 58 /*************************************************************************/ 59 printPositiveTestHeader(stdout, 60 "psStats functions", 61 "PS_STAT_SAMPLE_MEAN: no vector mask"); 52 62 53 printf("Called psArrayStats() on a vector with no elements masked.\n"); 54 printf("The expected mean was %f; the calculated mean was %f\n", realMean1, mean); 55 if (mean == realMean1) { 63 myStats = psVectorStats(myStats, myVector, NULL, 0); 64 mean = myStats->sampleMean; 65 66 printf("Called psVectorStats() on a vector with no elements masked.\n"); 67 printf("The expected mean was %f; the calculated mean was %f\n", realMeanNoMask, mean); 68 if (mean == realMeanNoMask) { 56 69 testStatus = true; 57 70 } else { 58 71 testStatus = false; 72 globalTestStatus = false; 59 73 } 74 printFooter(stdout, 75 "psVector functions", 76 "PS_STAT_SAMPLE_MEAN: no vector mask", 77 testStatus); 60 78 61 myStats2 = psArrayStats(myVector, maskVector, 1, myStats); 62 mean = myStats2->sampleMean; 63 printf("Called psArrayStats() on a vector with last N/2 elements masked.\n"); 64 printf("The expected mean was %f; the calculated mean was %f\n", realMean2, mean); 65 if (mean == realMean2) { 79 /*************************************************************************/ 80 /* Call psVectorStats() with vector mask. */ 81 /*************************************************************************/ 82 printPositiveTestHeader(stdout, 83 "psStats functions", 84 "PS_STAT_SAMPLE_MEAN: with vector mask"); 85 86 myStats = psVectorStats(myStats, myVector, maskVector, 1); 87 mean = myStats->sampleMean; 88 printf("Called psVectorStats() on a vector with last N/2 elements masked.\n"); 89 printf("The expected mean was %f; the calculated mean was %f\n", realMeanWithMask, mean); 90 if (mean == realMeanWithMask) { 66 91 testStatus = true; 67 92 } else { 68 93 testStatus = false; 94 globalTestStatus = false; 69 95 } 70 96 71 97 printFooter(stdout, 72 "ps Hashfunctions",73 " psHashAlloc()",98 "psVector functions", 99 "PS_STAT_SAMPLE_MEAN: with vector mask", 74 100 testStatus); 75 101 76 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); 77 125 } -
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 } -
trunk/psLib/test/dataManip/tst_psStats02.c
r717 r887 1 1 /***************************************************************************** 2 2 This routine must ensure that PS_STAT_MIN 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 min = 1e99; 19 float realMin1 = 1e99; 20 float realMin2 = 1e99; 19 float realMinNoMask = 1e99; 20 float realMinWithMask = 1e99; 21 int currentId = psMemGetId(); 22 int memLeaks = 0; 21 23 22 printPositiveTestHeader(stdout, 23 "psStats functions", 24 "PS_STAT_MIN"); 25 24 /*************************************************************************/ 25 /* Allocate and initialize data structures */ 26 /*************************************************************************/ 26 27 myStats = psStatsAlloc(PS_STAT_MIN); 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 minimum. 39 for (i=0;i<N;i++) { 40 if (myVector->data.F32[i] < realMinNoMask) { 41 realMinNoMask = myVector->data.F32[i]; 42 } 43 34 44 if (i < (N/2)) { 35 maskVector->vec.ui8[i] = 0; 36 if (myVector->vec.f[i] < realMin2) { 37 realMin2 = myVector->vec.f[i]; 38 } 45 maskVector->data.U8[i] = 1; 39 46 } else { 40 printf("Masking element %d\n", i); 41 maskVector->vec.ui8[i] = 1; 42 if (myVector->vec.f[i] < realMin1) { 43 realMin1 = myVector->vec.f[i]; 47 maskVector->data.U8[i] = 0; 48 if (myVector->data.F32[i] < realMinWithMask) { 49 realMinWithMask = myVector->data.F32[i]; 44 50 } 45 51 } 46 52 } 47 53 48 myStats2 = psArrayStats(myVector, NULL, 0, myStats); 49 min = myStats2->min; 54 /*************************************************************************/ 55 /* Call psVectorStats() with no vector mask. */ 56 /*************************************************************************/ 57 printPositiveTestHeader(stdout, 58 "psStats functions", 59 "PS_STAT_MIN: no vector mask"); 50 60 51 printf("Called psArrayStats() on a vector with no elements masked.\n"); 52 printf("The expected min was %f; the calculated min was %f\n", realMin1, min); 53 if (min == realMin1) { 61 myStats = psVectorStats(myStats, myVector, 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) { 54 68 testStatus = true; 55 69 } else { 56 70 testStatus = false; 71 globalTestStatus = false; 57 72 } 73 printFooter(stdout, 74 "psVector functions", 75 "PS_STAT_MIN: no vector mask", 76 testStatus); 58 77 59 myStats2 = psArrayStats(myVector, maskVector, 1, myStats); 60 min = myStats2->min; 61 printf("Called psArrayStats() on a vector with last N/2 elements masked.\n"); 62 printf("The expected min was %f; the calculated min was %f\n", realMin2, min); 63 if (min == realMin2) { 78 /*************************************************************************/ 79 /* Call psVectorStats() with vector mask. */ 80 /*************************************************************************/ 81 printPositiveTestHeader(stdout, 82 "psStats functions", 83 "PS_STAT_MIN: with vector mask"); 84 85 myStats = psVectorStats(myStats, myVector, maskVector, 1); 86 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) { 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_MIN: 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 } -
trunk/psLib/test/dataManip/tst_psStats03.c
r779 r887 1 1 /***************************************************************************** 2 2 This routine must ensure that PS_STAT_SAMPLE_MEDIAN is correctly computed 3 by the procedure ps ArrayStats().3 by the procedure psVectorStats(). 4 4 *****************************************************************************/ 5 5 #include <stdio.h> 6 6 #include "pslib.h" 7 7 #include "psTest.h" 8 #define N1 1029 8 #define N1 1029 // This should be an odd number. 9 9 #define N ((4 * N1) + 1) 10 10 … … 12 12 { 13 13 psStats *myStats = NULL; 14 psStats *myStats2 = NULL;15 14 int testStatus = true; 15 int globalTestStatus = true; 16 16 int i = 0; 17 17 psVector *myVector = NULL; 18 18 psVector *maskVector= NULL; 19 19 float median = 1e99; 20 float realMedian1 = 1e99; 21 float realMedian2 = 1e99; 20 float realMedianWithMask = (float) (N-3)/4; 21 float realMedianNoMask = (float) (N-1)/2; 22 int currentId = psMemGetId(); 23 int memLeaks = 0; 22 24 23 printPositiveTestHeader(stdout, 24 "psStats functions", 25 "PS_STAT_SAMPLE_MEDIAN"); 26 25 /*************************************************************************/ 26 /* Allocate and initialize data structures */ 27 /*************************************************************************/ 27 28 myStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 28 myVector = psVectorAlloc( PS_TYPE_FLOAT, N);29 myVector = psVectorAlloc(N, PS_TYPE_F32); 29 30 myVector->n = N; 30 maskVector = psVectorAlloc( PS_TYPE_UINT8, N);31 maskVector = psVectorAlloc(N, PS_TYPE_U8); 31 32 maskVector->n = N; 32 33 34 // Set the appropriate values for the vector data. 33 35 for (i=0;i<N;i++) { 34 myVector->vec.f[i] = (float) i; 36 myVector->data.F32[i] = (float) i; 37 } 38 39 // Set the mask vector and calculate the expected median. 40 for (i=0;i<N;i++) { 35 41 if (i < (N/2)) { 36 maskVector->vec.ui8[i] = 0; 37 if (myVector->vec.f[i] < realMedian2) { 38 realMedian2 = myVector->vec.f[i]; 39 } 42 maskVector->data.U8[i] = 0; 40 43 } else { 41 maskVector->vec.ui8[i] = 1; 42 if (myVector->vec.f[i] < realMedian1) { 43 realMedian1 = myVector->vec.f[i]; 44 } 44 maskVector->data.U8[i] = 1; 45 45 } 46 46 } 47 47 48 myStats2 = psArrayStats(myVector, NULL, 0, myStats); 49 median = myStats2->sampleMedian; 48 /*************************************************************************/ 49 /* Call psVectorStats() with no vector mask. */ 50 /*************************************************************************/ 51 printPositiveTestHeader(stdout, 52 "psStats functions", 53 "PS_STAT_SAMPLE_MEDIAN: no vector mask"); 50 54 51 printf("Called psArrayStats() on a vector with no elements masked.\n"); 55 myStats = psVectorStats(myStats, myVector, NULL, 0); 56 median = myStats->sampleMedian; 57 58 printf("Called psVectorStats() on a vector with no elements masked.\n"); 52 59 printf("The expected median was %f. The calculated median was %f.\n", 53 (float) (N-1)/2, median);54 if (median == (float) (N-1)/2) {60 realMedianNoMask, median); 61 if (median == realMedianNoMask) { 55 62 testStatus = true; 56 63 } else { 57 64 testStatus = false; 65 globalTestStatus = false; 58 66 } 59 67 60 myStats2 = psArrayStats(myVector, maskVector, 1, myStats); 61 median = myStats2->sampleMedian; 62 printf("Called psArrayStats() on a vector with last N/2 elements masked.\n"); 68 printFooter(stdout, 69 "psStats functions", 70 "PS_STAT_SAMPLE_MEDIAN: no vector mask", 71 testStatus); 72 73 /*************************************************************************/ 74 /* Call psVectorStats() with vector mask. */ 75 /*************************************************************************/ 76 printPositiveTestHeader(stdout, 77 "psStats functions", 78 "PS_STAT_SAMPLE_MEDIAN: with vector mask"); 79 80 myStats = psVectorStats(myStats, myVector, maskVector, 1); 81 median = myStats->sampleMedian; 82 printf("Called psVectorStats() on a vector with last N/2 elements masked.\n"); 63 83 printf("The expected median was %f. The calculated median was %f.\n", 64 (float) (N-3)/4, median);65 if (median == (float) (N-3)/4) {84 realMedianWithMask, median); 85 if (median == realMedianWithMask) { 66 86 testStatus = true; 67 87 } else { 68 88 testStatus = false; 89 globalTestStatus = false; 69 90 } 70 91 71 92 printFooter(stdout, 72 "ps Hashfunctions",73 " psHashAlloc()",93 "psStats functions", 94 "PS_STAT_SAMPLE_MEDIAN: with vector mask", 74 95 testStatus); 75 96 76 return (!testStatus); 97 /*************************************************************************/ 98 /* Deallocate data structures */ 99 /*************************************************************************/ 100 printPositiveTestHeader(stdout, 101 "psStats functions", 102 "psStats(): deallocating memory"); 103 104 psStatsFree(myStats); 105 psVectorFree(myVector); 106 psVectorFree(maskVector); 107 108 psMemCheckCorruption(1); 109 memLeaks = psMemCheckLeaks(currentId,NULL,NULL); 110 if (0 != memLeaks) { 111 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 112 } 113 114 printFooter(stdout, 115 "psStats functions", 116 "psStats(): deallocating memory", 117 testStatus); 118 119 return (!globalTestStatus); 77 120 } -
trunk/psLib/test/dataManip/tst_psStats04.c
r779 r887 1 1 /***************************************************************************** 2 2 This routine must ensure that PS_STAT_NVALUES is correctly computed 3 by the procedure psArrayStats(). 3 by the procedure psVectorStats(). 4 5 Note: The NVALUES stat was removed from the IfA requirements spec. So, 6 this test is no longer in use. 4 7 *****************************************************************************/ 5 8 #include <stdio.h> … … 12 15 { 13 16 psStats *myStats = NULL; 14 psStats *myStats2 = NULL;15 17 int testStatus = true; 16 18 int i = 0; … … 18 20 psVector *maskVector= NULL; 19 21 22 /*************************************************************************/ 23 /* Allocate and initialize data structures */ 24 /*************************************************************************/ 25 myStats = psStatsAlloc(PS_STAT_NVALUES); 26 myVector = psVectorAlloc(N, PS_TYPE_F32); 27 myVector->n = N; 28 maskVector = psVectorAlloc(N, PS_TYPE_U8); 29 maskVector->n = N; 30 31 // Set the appropriate values for the vector data. 32 for (i=0;i<N;i++) { 33 myVector->data.F32[i] = (float) i; 34 } 35 36 // Set the mask vector and calculate the expected maximum. 37 for (i=0;i<N;i++) { 38 if (i < (N/2)) { 39 maskVector->data.U8[i] = 0; 40 } else { 41 maskVector->data.U8[i] = 1; 42 } 43 } 44 45 /*************************************************************************/ 46 /* Call psVectorStats() with no vector mask. */ 47 /*************************************************************************/ 20 48 printPositiveTestHeader(stdout, 21 49 "psStats functions", 22 50 "PS_STAT_NVALUES"); 23 51 24 myStats = psStatsAlloc(PS_STAT_NVALUES); 25 myVector = psVectorAlloc(PS_TYPE_FLOAT, N); 26 myVector->n = N; 27 maskVector = psVectorAlloc(PS_TYPE_UINT8, N); 28 maskVector->n = N; 52 myStats = psVectorStats(myStats, myVector, NULL, 0); 29 53 30 for (i=0;i<N;i++) { 31 myVector->vec.f[i] = (float) i; 32 if (i < (N/2)) { 33 maskVector->vec.ui8[i] = 0; 34 } else { 35 maskVector->vec.ui8[i] = 1; 36 } 37 } 38 39 myStats2 = psArrayStats(myVector, NULL, 0, myStats); 40 41 printf("Called psArrayStats() on a vector with no elements masked.\n"); 54 printf("Called psVectorStats() on a vector with no elements masked.\n"); 42 55 printf("The expected nvalues was %d. The calculated nvalues was %d.\n", 43 N, myStats 2->nValues);44 if (myStats 2->nValues == N) {56 N, myStats->nValues); 57 if (myStats->nValues == N) { 45 58 testStatus = true; 46 59 } else { … … 48 61 } 49 62 50 myStats2 = psArrayStats(myVector, maskVector, 1, myStats); 51 printf("Called psArrayStats() on a vector with last N/2 elements masked.\n"); 63 /*************************************************************************/ 64 /* Call psVectorStats() with vector mask. */ 65 /*************************************************************************/ 66 myStats = psVectorStats(myStats, myVector, maskVector, 1); 67 printf("Called psVectorStats() on a vector with last N/2 elements masked.\n"); 52 68 printf("The expected nvalues was %d. The calculated nvalues was %d.\n", 53 N/2, myStats 2->nValues);54 if (myStats 2->nValues == N/2) {69 N/2, myStats->nValues); 70 if (myStats->nValues == N/2) { 55 71 testStatus = true; 56 72 } else {
Note:
See TracChangeset
for help on using the changeset viewer.
