Changeset 1982 for trunk/psLib/test/dataManip
- Timestamp:
- Oct 6, 2004, 11:30:53 AM (22 years ago)
- Location:
- trunk/psLib/test/dataManip
- Files:
-
- 2 edited
-
tst_psFunc04.c (modified) (2 diffs)
-
tst_psFunc07.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psFunc04.c
r1946 r1982 17 17 #define N 8 18 18 19 int main()19 int t00() 20 20 { 21 21 int testStatus = true; … … 68 68 return (!testStatus); 69 69 } 70 71 int t01() 72 { 73 int testStatus = true; 74 int memLeaks=0; 75 int i; 76 float x; 77 float y; 78 int currentId = psMemGetId(); 79 psSpline1D *tmpSpline; 80 psVector *data; 81 82 psTraceSetLevel(".", 0); 83 84 /****************************************************************************/ 85 /****************************************************************************/ 86 testStatus = true; 87 printPositiveTestHeader(stdout, 88 "psFunction functions", 89 "psSpline1DAlloc()"); 90 data = psVectorAlloc(N+1, PS_TYPE_F32); 91 tmpSpline = psSpline1DAlloc(N, 1, 1.0, 10.0); 92 93 for (i=0;i<N+1;i++) { 94 data->data.F32[i] = tmpSpline->domains[i]; 95 } 96 psVectorFitSpline1D(tmpSpline, data, data, NULL); 97 98 for (i=0;i<N+1;i++) { 99 x = 0.5 + (float) i+1; 100 y = psSpline1DEval(tmpSpline, x); 101 if (fabs(x-y) > FLT_EPSILON) { 102 printf("ERROR: f(%f) is %f\n", x, y); 103 testStatus = true; 104 } 105 } 106 107 p_psSpline1DFree(tmpSpline); 108 psMemCheckCorruption(1); 109 psFree(data); 110 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 111 if (0 != memLeaks) { 112 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 113 } 114 115 printFooter(stdout, 116 "psFunctions functions", 117 "psSpline1DAlloc()", 118 testStatus); 119 120 return (!testStatus); 121 } 122 123 int main() 124 { 125 t00(); 126 // t01(); 127 } -
trunk/psLib/test/dataManip/tst_psFunc07.c
r1946 r1982 12 12 #include "psFunctions.h" 13 13 14 #define NUM_SPLINES 5 14 #define NUM_SPLINES 50 15 15 #define A 4.0 16 16 #define B -3.0 … … 20 20 #define MAX 30 21 21 #define ERROR_TOLERANCE 0.10 22 #define OFFSET (NUM_SPLINES * ERROR_TOLERANCE) 22 23 23 24 float myFunc(float x) … … 26 27 } 27 28 28 int main()29 int t00() 29 30 { 30 31 int testStatus = true; … … 37 38 psVector *y = NULL; 38 39 psVector *newY = NULL; 39 float NRX[NUM_SPLINES+2];40 float NRY[NUM_SPLINES+2];41 // float tmpY;42 // float derivs[NUM_SPLINES+2];43 40 44 41 psTraceSetLevel(".", 0); … … 46 43 /****************************************************************************/ 47 44 testStatus = true; 48 printPositiveTestHeader(stdout,49 "psFunction functions",50 "psSpline1DAlloc()");51 45 x = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 52 46 newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); … … 55 49 56 50 for (i=0;i<NUM_SPLINES+1;i++) { 57 NRX[i+1] = x->data.F32[i] = tmpSpline->domains[i]; 58 NRY[i+1] = y->data.F32[i] = myFunc(x->data.F32[i]); 59 // printf("DATA: (x, y) is (%f, %f)\n", x->data.F32[i], y->data.F32[i]); 51 x->data.F32[i] = tmpSpline->domains[i]; 52 y->data.F32[i] = myFunc(x->data.F32[i]); 60 53 } 54 61 55 for (i=0;i<NUM_SPLINES;i++) { 62 56 newX->data.F32[i]= ((x->data.F32[i] + x->data.F32[i+1])/2.0); … … 66 60 /* psLib Code */ 67 61 /****************************************************************************/ 62 printPositiveTestHeader(stdout, 63 "psFunction functions", 64 "psSpline1DAlloc()"); 68 65 69 66 psVectorFitSpline1D(tmpSpline, x, y, NULL); 70 67 newY = psSpline1DEvalVector(newX, tmpSpline); 71 68 72 for (i= 0;i<NUM_SPLINES+1;i++) {69 for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) { 73 70 if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) { 74 71 printf("ERROR[%d]: f(%f) is %f. Should be %f\n", i, 75 72 newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i])); 76 73 } 77 // tmpY = p_psNRSpline1DEval(tmpSpline, x, y, newX->data.F32[i]);78 // printf("HMMM: p_psNRSpline1DEval(%f) is %f. Should be %f\n",79 // newX->data.F32[i], tmpY, myFunc(newX->data.F32[i]));80 74 } 81 75 … … 99 93 return (!testStatus); 100 94 } 95 96 int t00() 97 { 98 int testStatus = true; 99 int memLeaks=0; 100 int currentId = psMemGetId(); 101 int i; 102 psSpline1D *tmpSpline = NULL; 103 psVector *x = NULL; 104 psVector *newX = NULL; 105 psVector *y = NULL; 106 psVector *newY = NULL; 107 108 psTraceSetLevel(".", 0); 109 /****************************************************************************/ 110 /****************************************************************************/ 111 testStatus = true; 112 x = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 113 newX = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 114 y = psVectorAlloc(NUM_SPLINES+1, PS_TYPE_F32); 115 tmpSpline = psSpline1DAlloc(NUM_SPLINES, 3, MIN, MAX); 116 117 for (i=0;i<NUM_SPLINES+1;i++) { 118 x->data.F32[i] = tmpSpline->domains[i]; 119 y->data.F32[i] = myFunc(x->data.F32[i]); 120 } 121 122 for (i=0;i<NUM_SPLINES;i++) { 123 newX->data.F32[i]= ((x->data.F32[i] + x->data.F32[i+1])/2.0); 124 } 125 newX->data.F32[NUM_SPLINES] = x->data.F32[NUM_SPLINES]; 126 /****************************************************************************/ 127 /* psLib Code */ 128 /****************************************************************************/ 129 printPositiveTestHeader(stdout, 130 "psFunction functions", 131 "psSpline1DAlloc()"); 132 133 psVectorFitSpline1D(tmpSpline, x, y, NULL); 134 newY = psSpline1DEvalVector(newX, tmpSpline); 135 136 for (i=OFFSET;i<NUM_SPLINES-OFFSET+1;i++) { 137 if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) { 138 printf("ERROR[%d]: f(%f) is %f. Should be %f\n", i, 139 newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i])); 140 } 141 } 142 143 psFree(x); 144 psFree(newX); 145 psFree(y); 146 p_psSpline1DFree(tmpSpline); 147 psFree(newY); 148 149 psMemCheckCorruption(1); 150 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 151 if (0 != memLeaks) { 152 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 153 } 154 155 printFooter(stdout, 156 "psFunctions functions", 157 "psSpline1DAlloc()", 158 testStatus); 159 160 return (!testStatus); 161 } 162 163 int main() 164 { 165 t00(); 166 }
Note:
See TracChangeset
for help on using the changeset viewer.
