Changeset 2513 in Sophya
- Timestamp:
- Mar 16, 2004, 12:51:20 AM (22 years ago)
- Location:
- trunk/SophyaProg/Tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaProg/Tests/pizthr.cc
r2322 r2513 199 199 // syn_cntrl = 0; 200 200 // } 201 amon.lock(); // <ZThread>202 201 while (XtAppPending(*appctx) != 0) { 202 amon.lock(); // <ZThread> 203 203 XtAppNextEvent(*appctx, &evt); 204 204 XtDispatchEvent(&evt); 205 amon.unlock(); // <ZThread> 205 206 } 206 amon.unlock(); // <ZThread> 207 usleep(1000); 207 // usleep(1000); 208 208 } 209 209 } -
trunk/SophyaProg/Tests/tcmd.cc
r2480 r2513 7 7 #include "sophyainit.h" 8 8 #include "timing.h" 9 #include "cexpre.h" 10 #include "rpneval.h" 9 11 #include "commander.h" 10 12 … … 48 50 49 51 int InputLoop(Commander & cmd); 52 int tst_cexpreval(); // Test de CExpressionEvaluator 53 int tst_rpneval(); // Test de RPNEvaluator 50 54 51 55 /* --Main-- */ … … 53 57 { 54 58 59 if (narg < 2) { 60 cout << " Usage: tcmd commander/cexptst/rpntst \n " 61 << " - commander: Commader class test \n" 62 << " - cexptst: CExpressionEvaluator class test \n" 63 << " - rpntst: RPNExpressionEvaluator class test \n" << endl; 64 return 0; 65 } 66 string opt = arg[1]; 55 67 SophyaInit(); 56 68 InitTim(); 57 69 int rc = 0; 58 70 try { 59 Commander cmd; 60 TCmdExecutor cmdex(cmd); 61 InputLoop(cmd); 71 if (opt == "commander") { 72 Commander cmd; 73 TCmdExecutor cmdex(cmd); 74 InputLoop(cmd); 75 } 76 else if (opt == "cexptst") rc = tst_cexpreval(); 77 else rc = tst_rpneval(); 62 78 } 63 79 … … 71 87 72 88 PrtTim(" End of tcmd "); 73 return( 0);89 return(rc); 74 90 } 75 91 … … 77 93 int InputLoop(Commander & cmd) 78 94 { 95 cout << " ====================================================== " << endl; 96 cout << " ============== Test of Commander class ============ " << endl; 97 cout << " ====================================================== " << endl; 79 98 cout << " tcmd/InputLoop() : Type in your commands, \n" 80 99 << " end with a blanck line OR <Cntl>D " << endl; … … 102 121 } 103 122 104 123 /* -- Fonction Test de CExpressionEvaluator -- */ 124 int tst_cexpreval() 125 { 126 double res; 127 int nok=0; 128 int nerr=0; 129 int nerrparse=0; 130 int num = 0; 131 cout << " ====================================================== " << endl; 132 cout << " ============ Test of CExpressionEvaluator ========== " << endl; 133 cout << " ====================================================== " << endl; 134 try { 135 try { 136 num++; 137 CExpressionEvaluator cex("4*3+8"); 138 cout << "CExpr=" << cex; 139 cout << " -> cex.Value() = " << cex.Value() << " =? 4*3+8 = " << ( res=4*3+8 ) << endl; 140 if (fabs(cex.Value()-res) > 1.e-9) { 141 cout << " ERREUR CALCUL " << cex << endl; 142 nerr++; 143 } 144 else nok++; 145 } 146 catch (CExprException& err) { 147 nerrparse++; 148 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 149 } 150 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 151 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 152 153 try { 154 num++; 155 CExpressionEvaluator cex("cos(0)+2"); 156 cout << "CExpr=" << cex; 157 cout << " -> cex.Value() = " << cex.Value() << " =? cos(0)+2 = " << ( res=cos(0.)+2 ) << endl; 158 if (fabs(cex.Value()-res) > 1.e-9) { 159 cout << " ERREUR CALCUL " << cex << endl; 160 nerr++; 161 } 162 else nok++; 163 } 164 catch (CExprException& err) { 165 nerrparse++; 166 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 167 } 168 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 169 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 170 171 172 try { 173 num++; 174 CExpressionEvaluator cex("4+3*8"); 175 cout << "CExpr=" << cex; 176 cout << " -> cex.Value() = " << cex.Value() << " =? 4+3*8 = " << ( res=4+3*8 ) << endl; 177 if (fabs(cex.Value()-res) > 1.e-9) { 178 cout << " ERREUR CALCUL " << cex << endl; 179 nerr++; 180 } 181 else nok++; 182 } 183 catch (CExprException& err) { 184 nerrparse++; 185 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 186 } 187 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 188 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 189 190 191 try { 192 num++; 193 CExpressionEvaluator cex("4+3*6*2"); 194 cout << "CExpr=" << cex; 195 cout << " -> cex.Value() = " << cex.Value() << " =? 4+3*6*2 = " << ( res=4+3*6*2 ) << endl; 196 if (fabs(cex.Value()-res) > 1.e-9) { 197 cout << " ERREUR CALCUL " << cex << endl; 198 nerr++; 199 } 200 else nok++; 201 } 202 203 catch (CExprException& err) { 204 nerrparse++; 205 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 206 } 207 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 208 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 209 210 try { 211 num++; 212 CExpressionEvaluator cex("(12+3*6*cos(0))"); 213 cout << "CExpr=" << cex; 214 cout << " -> cex.Value() = " << cex.Value() << " =? (12+3*6*cos(0)) = " 215 << ( res=(12+3*6*cos(0.)) ) << endl; 216 if (fabs(cex.Value()-res) > 1.e-9) { 217 cout << " ERREUR CALCUL " << cex << endl; 218 nerr++; 219 } 220 else nok++; 221 } 222 catch (CExprException& err) { 223 nerrparse++; 224 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 225 } 226 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 227 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 228 229 try { 230 num++; 231 CExpressionEvaluator cex("(12+3*6*cos(0))-(5*pow(2,2))"); 232 cout << "CExpr=" << cex; 233 cout << " -> cex.Value() = " << cex.Value() << " =? (12+3*6*cos(0))-(5*pow(2,2)) = " 234 << ( res=(12+3*6*cos(0.))-(5*pow(2.,2.)) ) << endl; 235 if (fabs(cex.Value()-res) > 1.e-9) { 236 cout << " ERREUR CALCUL " << cex << endl; 237 nerr++; 238 } 239 else nok++; 240 } 241 catch (CExprException& err) { 242 nerrparse++; 243 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 244 } 245 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 246 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 247 248 try { 249 num++; 250 CExpressionEvaluator cex("sin(Pi/6)+E"); 251 cout << "CExpr=sin(Pi/6)+E " << cex; 252 cout << " -> cex.Value() = " << cex.Value() << " =? sin(M_PI/6)+M_E = " 253 << ( res=sin(M_PI/6)+M_E ) << endl; 254 if (fabs(cex.Value()-res) > 1.e-9) { 255 cout << " ERREUR CALCUL " << cex << endl; 256 nerr++; 257 } 258 else nok++; 259 } 260 catch (CExprException& err) { 261 nerrparse++; 262 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 263 } 264 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 265 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 266 267 // Expression avec erreur de syntaxe 268 try { 269 num++; 270 CExpressionEvaluator cex("6**8"); 271 cout << "CExpr=" << cex; 272 cout << " -> cex.Value() = " << cex.Value() << endl; 273 } 274 catch (CExprException& err) { 275 nerrparse++; 276 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 277 } 278 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 279 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 280 281 try { 282 num++; 283 CExpressionEvaluator cex("6*(8+4"); 284 cout << "CExpr=" << cex; 285 cout << " -> cex.Value() = " << cex.Value() << endl; 286 } 287 catch (CExprException& err) { 288 nerrparse++; 289 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 290 } 291 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 292 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 293 294 295 try { 296 num++; 297 CExpressionEvaluator cex("6*sin(4,)+12"); 298 cout << "CExpr=" << cex; 299 cout << " -> cex.Value() = " << cex.Value() << endl; 300 } 301 catch (CExprException& err) { 302 nerrparse++; 303 cout << "Exp[" << num << "] Exception: " << err.Msg() << endl; 304 } 305 cout << " [" << num << "] CExprBase::NbCreate() = " << CExprBase::NbCreate() 306 << "CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 307 308 } 309 catch (CExprException& err) { 310 cout << " Exception: " << err.Msg() << endl; 311 } 312 313 cout << "-------- CExprBase::NbCreate() = " << CExprBase::NbCreate() << " CExprBase::NbDelete()=" << CExprBase::NbDelete() << endl; 314 cout << "--- NExpr= " << num << " NOk= " << nok << " NErr=" << nerr << " NErrParse=" << nerrparse << endl; 315 return 0; 316 } 317 318 /* -- Fonction Test de CExpressionEvaluator -- */ 319 int tst_rpneval() 320 { 321 int num = 0; 322 cout << " ====================================================== " << endl; 323 cout << " ============ Test of RPNExpressionEvaluator ========== " << endl; 324 cout << " ====================================================== " << endl; 325 try { 326 { 327 num++; 328 RPNExpressionEvaluator rpn("4 2 print + 3 * "); 329 cout << "4 2 + 3 * -> rpn.Value() = " << rpn.Value() << endl; 330 } 331 { 332 num++; 333 RPNExpressionEvaluator rpn("1 2 3 4 5 sum"); 334 cout << "1 2 3 4 5 sum -> rpn.Value() = " << rpn.Value() << endl; 335 } 336 { 337 num++; 338 RPNExpressionEvaluator rpn("4 3 pow"); 339 cout << "4 3 pow -> rpn.Value() = " << rpn.Value() << endl; 340 } 341 } 342 catch (RPNExprException& err) { 343 cout << "RPNExp[" << num << "] Exception: " << err.Msg() << endl; 344 } 345 346 return 0; 347 }
Note:
See TracChangeset
for help on using the changeset viewer.