Changeset 4581 for trunk/psLib/test/math/tst_psFunc08.c
- Timestamp:
- Jul 19, 2005, 3:21:13 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/math/tst_psFunc08.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tst_psFunc08.c
r4547 r4581 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-07- 13 02:47:00$6 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-07-20 01:21:13 $ 8 8 * 9 9 * XXX: Probably should test single- and multi-dimensional polynomials in … … 22 22 23 23 static psS32 testPoly1DEval(void); 24 static psS32 testDPoly1DEval(void);25 24 static psS32 testPoly1DEvalVector(void); 26 static psS32 testDPoly1DEvalVector(void);27 25 28 26 testDescription tests[] = { 29 27 {testPoly1DEval,000,"psPolynomial1DEval",0,false}, 30 {testDPoly1DEval,000,"psDPolynomial1DEval",0,false},31 28 {testPoly1DEvalVector,000,"psPolynomial1DEvalVector",0,false}, 32 {testDPoly1DEvalVector,000,"psDPolynomial1DEvalVector",0,false},33 29 {NULL} 34 30 }; … … 58 54 psS32 testPoly1DEval(void) 59 55 { 60 psF 32result;61 psF 32resultCheb;56 psF64 result; 57 psF64 resultCheb; 62 58 63 59 // Allocate polynomial structure … … 103 99 } 104 100 105 // This test will verify operation of 1D polynomial evaluation106 psS32 testDPoly1DEval(void)107 {108 psF64 result;109 psF64 resultCheb;110 111 // Allocate polynomial structure112 psDPolynomial1D* polyOrd = psDPolynomial1DAlloc(TERMS, PS_POLYNOMIAL_ORD);113 psDPolynomial1D* polyCheb = psDPolynomial1DAlloc(TERMS, PS_POLYNOMIAL_CHEB);114 // Set polynomial members115 for(psS32 i = 0; i < TERMS; i++) {116 polyOrd->coeff[i] = Dpoly1DCoeff[i];117 polyOrd->mask[i] = poly1DMask[i];118 polyCheb->coeff[i] = 1.0;119 polyCheb->mask[i] = poly1DMask[i];120 }121 // Evaluate test points and verify results122 for(psS32 i = 0; i < TESTPOINTS; i++) {123 result = psDPolynomial1DEval(polyOrd,Dpoly1DXValue[i]);124 if(fabs(Dpoly1DXResult[i]-result) > ERROR_TOL ) {125 psError(PS_ERR_UNKNOWN,true,"Evaluated value %lg not as expected %lg",126 result, Dpoly1DXResult[i]);127 return i;128 }129 resultCheb = psDPolynomial1DEval(polyCheb,Dpoly1DXChebValue[i]);130 if(fabs(Dpoly1DXChebResult[i]-resultCheb) > ERROR_TOL ) {131 psError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg",132 resultCheb, Dpoly1DXChebResult[i]);133 return 5*i;134 }135 }136 psFree(polyOrd);137 psFree(polyCheb);138 139 // Allocate polynomial with invalid type140 polyOrd = psDPolynomial1DAlloc(TERMS, 99);141 // Attempt to evaluation invalid polynomial type142 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type");143 result = psDPolynomial1DEval(polyOrd,0.0);144 if ( !isnan(result) ) {145 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type");146 return 20;147 }148 psFree(polyOrd);149 150 return 0;151 }152 101 153 102 psS32 testPoly1DEvalVector(void) … … 156 105 psPolynomial1D* polyOrd = psPolynomial1DAlloc(TERMS,PS_POLYNOMIAL_ORD); 157 106 psPolynomial1D* polyCheb = psPolynomial1DAlloc(TERMS,PS_POLYNOMIAL_CHEB); 158 159 // Set polynomial members160 for(psS32 i = 0; i < TERMS; i++) {161 polyOrd->coeff[i] = poly1DCoeff[i];162 polyOrd->mask[i] = poly1DMask[i];163 polyCheb->coeff[i] = 1.0;164 polyCheb->mask[i] = poly1DMask[i];165 }166 167 // Create input vectors168 psVector* inputOrd = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);169 psVector* inputCheb = psVectorAlloc(TESTPOINTS, PS_TYPE_F32);170 for(psS32 i = 0; i < TESTPOINTS; i++) {171 inputOrd->data.F32[i] = poly1DXValue[i];172 inputCheb->data.F32[i] = poly1DXChebValue[i];173 }174 175 // Evaluate the vectors176 psVector* outputOrd = psPolynomial1DEvalVector(polyOrd, inputOrd);177 if(outputOrd == NULL) {178 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");179 return 1;180 }181 if(outputOrd->type.type != PS_TYPE_F32) {182 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",183 outputOrd->type.type, PS_TYPE_F32);184 return 2;185 }186 psVector* outputCheb = psPolynomial1DEvalVector(polyCheb, inputCheb);187 if(outputCheb == NULL) {188 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");189 return 1;190 }191 if(outputCheb->type.type != PS_TYPE_F32) {192 psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",193 outputCheb->type.type, PS_TYPE_F32);194 return 2;195 }196 197 // Verify the results198 for(psS32 i = 0; i < TESTPOINTS; i++) {199 if(fabs(poly1DXResult[i]-outputOrd->data.F32[i]) > ERROR_TOL) {200 psError(PS_ERR_UNKNOWN,true,"Result[%d] %g not equal to expected %g",201 i, outputOrd->data.F32[i], poly1DXResult[i]);202 return i*5;203 }204 if(fabs(poly1DXChebResult[i]-outputCheb->data.F32[i]) > ERROR_TOL) {205 psError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %g not equal to expected %g",206 i, outputCheb->data.F32[i], poly1DXChebResult[i]);207 return i*10;208 }209 }210 211 // Attempt to invoke function with null polynomial212 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");213 if(psPolynomial1DEvalVector(NULL, inputOrd) != NULL) {214 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial");215 return 60;216 }217 218 // Attempt to invoke function with null input vector219 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");220 if(psPolynomial1DEvalVector(polyOrd,NULL) != NULL) {221 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");222 return 61;223 }224 225 // Attempt to invoke function with a non F32 type input vector226 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");227 inputOrd->type.type = PS_TYPE_U8;228 if(psPolynomial1DEvalVector(polyOrd,inputOrd) != NULL) {229 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F32 input vector");230 return 62;231 }232 inputOrd->type.type = PS_TYPE_F32;233 234 psFree(inputOrd);235 psFree(inputCheb);236 psFree(outputOrd);237 psFree(outputCheb);238 psFree(polyOrd);239 psFree(polyCheb);240 241 return 0;242 }243 244 psS32 testDPoly1DEvalVector(void)245 {246 // Allocate polynomial247 psDPolynomial1D* polyOrd = psDPolynomial1DAlloc(TERMS,PS_POLYNOMIAL_ORD);248 psDPolynomial1D* polyCheb = psDPolynomial1DAlloc(TERMS,PS_POLYNOMIAL_CHEB);249 107 250 108 // Set polynomial members … … 265 123 266 124 // Evaluate the vectors 267 psVector* outputOrd = ps DPolynomial1DEvalVector(polyOrd, inputOrd);125 psVector* outputOrd = psPolynomial1DEvalVector(polyOrd, inputOrd); 268 126 if(outputOrd == NULL) { 269 127 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL."); … … 275 133 return 2; 276 134 } 277 psVector* outputCheb = ps DPolynomial1DEvalVector(polyCheb, inputCheb);135 psVector* outputCheb = psPolynomial1DEvalVector(polyCheb, inputCheb); 278 136 if(outputCheb == NULL) { 279 137 psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL."); … … 302 160 // Attempt to invoke function with null polynomial 303 161 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial"); 304 if(ps DPolynomial1DEvalVector(NULL, inputOrd) != NULL) {162 if(psPolynomial1DEvalVector(NULL, inputOrd) != NULL) { 305 163 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial"); 306 164 return 60; … … 309 167 // Attempt to invoke function with null input vector 310 168 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector"); 311 if(ps DPolynomial1DEvalVector(polyOrd,NULL) != NULL) {169 if(psPolynomial1DEvalVector(polyOrd,NULL) != NULL) { 312 170 psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector"); 313 171 return 61; … … 317 175 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type"); 318 176 inputOrd->type.type = PS_TYPE_U8; 319 if(ps DPolynomial1DEvalVector(polyOrd,inputOrd) != NULL) {177 if(psPolynomial1DEvalVector(polyOrd,inputOrd) != NULL) { 320 178 psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector"); 321 179 return 62;
Note:
See TracChangeset
for help on using the changeset viewer.
