Changeset 15341 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests
- Timestamp:
- 08/28/17 09:03:34 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Benchmark/SolutionTests.cs
r15334 r15341 42 42 public void Checksum() { 43 43 TestProgram( 44 PushParser.ParseProgram("( IN1 0 STRING.ITERATE ( INTEGER.FROMCHAR INTEGER.+ ) 64 INTEGER.% \' \' INTEGER.FROMCHAR INTEGER.+ \"Check sum is \" PRINT.PRINTSTRING CHAR.FROMINTEGER PRINT.PRINTCHAR )"), 44 PushParser.ParseProgram( 45 @"( 46 0 STRING.ITERATE ( 47 INTEGER.FROMCHAR INTEGER.+ 48 ) 49 64 INTEGER.% ' ' INTEGER.FROMCHAR INTEGER.+ 50 ""Check sum is "" PRINT.PRINTSTRING 51 CHAR.FROMINTEGER PRINT.PRINTCHAR 52 )"), 45 53 new Checksum()); 46 54 } … … 51 59 public void CollatzNumbers() { 52 60 TestProgram( 53 PushParser.ParseProgram("( INTEGER.DUP 1 INTEGER.= BOOLEAN.NOT EXEC.WHILE ( INTEGER.DUP INTEGER.DUP 2 INTEGER.% 0 INTEGER.= EXEC.IF ( 2 INTEGER./ ) ( 3 INTEGER.* 1 INTEGER.+ ) INTEGER.DUP 1 INTEGER.= BOOLEAN.NOT ) INTEGER.POP INTEGER.STACKDEPTH )"), 61 PushParser.ParseProgram( 62 @"( 63 INTEGER.DUP 1 INTEGER.= BOOLEAN.NOT 64 EXEC.WHILE ( 65 INTEGER.DUP INTEGER.DUP 2 INTEGER.% 0 INTEGER.= 66 EXEC.IF ( 67 2 INTEGER./ 68 ) ( 69 3 INTEGER.* 1 INTEGER.+ 70 ) 71 INTEGER.DUP 1 INTEGER.= BOOLEAN.NOT 72 ) 73 INTEGER.POP INTEGER.STACKDEPTH 74 )"), 54 75 new CollatzNumbers()); 55 76 } … … 60 81 public void CompareStringLengths() { 61 82 TestProgram( 62 PushParser.ParseProgram("IN1 IN2 IN3 STRING.LENGTH STRING.LENGTH INTEGER.DUP STRING.LENGTH INTEGER.> INTEGER.> BOOLEAN.AND"), 83 PushParser.ParseProgram(@" 84 ( 85 STRING.LENGTH STRING.LENGTH INTEGER.DUP 86 STRING.LENGTH INTEGER.> INTEGER.> BOOLEAN.AND 87 )"), 63 88 new CompareStringLengths()); 64 89 } … … 69 94 public void CountOdds() { 70 95 TestProgram( 71 PushParser.ParseProgram("( IN1 0 INTEGER[].ITERATE ( 2 INTEGER.% INTEGER.DUP 1 INTEGER.= -1 INTEGER.= BOOLEAN.OR EXEC.WHEN INTEGER.INC ) )"), 96 PushParser.ParseProgram(@" 97 ( 98 0 INTEGER[].ITERATE ( 99 2 INTEGER.% INTEGER.DUP 100 1 INTEGER.= 101 -1 INTEGER.= 102 BOOLEAN.OR 103 EXEC.WHEN INTEGER.INC 104 ) 105 )"), 72 106 new CountOdds()); 73 107 } … … 108 142 public void DoubleLetters() { 109 143 TestProgram( 110 PushParser.ParseProgram( 111 @"IN1144 PushParser.ParseProgram(@" 145 ( 112 146 STRING.ITERATE ( 113 147 3 EXEC.DO*COUNT CHAR.DUP 114 148 CHAR.ISLETTER EXEC.WHEN PRINT.PRINTCHAR 115 '!' CHAR.= EXEC.WHEN ( CHAR.DUP PRINT.PRINTCHAR PRINT.PRINTCHAR ) 149 '!' CHAR.= EXEC.WHEN ( 150 CHAR.DUP PRINT.PRINTCHAR PRINT.PRINTCHAR 151 ) 116 152 PRINT.PRINTCHAR 153 ) 117 154 )"), 118 155 new DoubleLetters()); … … 124 161 public void EvenSquares() { 125 162 TestProgram( 126 PushParser.ParseProgram( 127 @"INTEGER.DUP EXEC.DO*COUNT ( 163 PushParser.ParseProgram(@" 164 ( 165 INTEGER.DUP EXEC.DO*COUNT ( 128 166 INTEGER.DUP 0 INTEGER.> 129 167 EXEC.WHEN ( … … 139 177 ) 140 178 INTEGER.POP 141 )"), 179 ) 180 )"), 142 181 new EvenSquares()); 143 182 } … … 148 187 public void ForLoopIndex() { 149 188 TestProgram( 150 PushParser.ParseProgram(@"( 151 STRING.FROMINTEGER INTEGER.SWAP true EXEC.WHILE ( 189 PushParser.ParseProgram(@" 190 ( 191 STRING.FROMINTEGER INTEGER.SWAP true 192 EXEC.WHILE ( 152 193 INTEGER.DUP PRINT.ENSURE_NEWLINE PRINT.PRINTINTEGER 153 194 STRING.DUP INTEGER.FROMSTRING INTEGER.+ … … 163 204 public void Grades() { 164 205 TestProgram( 165 PushParser.ParseProgram("( \"Student has a \" PRINT.PRINTSTRING INTEGER.DUP INTEGER.ROT INTEGER.> EXEC.WHEN ( \"F\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) INTEGER.DUP INTEGER.ROT INTEGER.> EXEC.WHEN ( \"D\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) INTEGER.DUP INTEGER.ROT INTEGER.> EXEC.WHEN ( \"C\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) INTEGER.DUP INTEGER.ROT INTEGER.> EXEC.WHEN ( \"B\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) \"A\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING )"), 206 PushParser.ParseProgram(@" 207 ( 208 ""Student has a "" PRINT.PRINTSTRING 209 INTEGER.DUP INTEGER.ROT INTEGER.> 210 EXEC.WHEN ( ""F"" "" grade."" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) 211 INTEGER.DUP INTEGER.ROT INTEGER.> 212 EXEC.WHEN ( ""D"" "" grade."" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) 213 INTEGER.DUP INTEGER.ROT INTEGER.> 214 EXEC.WHEN ( ""C"" "" grade."" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) 215 INTEGER.DUP INTEGER.ROT INTEGER.> 216 EXEC.WHEN ( ""B"" "" grade."" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) 217 ""A"" "" grade."" STRING.CONCAT PRINT.PRINTSTRING 218 )"), 166 219 new Grades()); 167 220 } … … 172 225 public void LastIndexOfZero() { 173 226 TestProgram( 174 PushParser.ParseProgram("( IN1 INTEGER[].DUP INTEGER[].LENGTH INTEGER[].REVERSE 0 INTEGER[].INDEXOF INTEGER.- INTEGER.DEC )"), 227 PushParser.ParseProgram(@" 228 ( 229 INTEGER[].DUP INTEGER[].LENGTH INTEGER[].REVERSE 230 0 INTEGER[].INDEXOF INTEGER.- INTEGER.DEC 231 )"), 175 232 new LastIndexOfZero()); 176 233 } … … 181 238 public void Median() { 182 239 TestProgram( 183 PushParser.ParseProgram("( IN1 IN2 IN3 INTEGER.ROT INTEGER.DUP 2 INTEGER.YANKDUP INTEGER.MAX 3 INTEGER.YANKDUP INTEGER.MIN INTEGER.ROT INTEGER.MIN INTEGER.MAX PRINT.PRINTINTEGER )"), 240 PushParser.ParseProgram(@" 241 ( 242 INTEGER.ROT INTEGER.DUP 2 INTEGER.YANKDUP 243 INTEGER.MAX 3 INTEGER.YANKDUP INTEGER.MIN 244 INTEGER.ROT INTEGER.MIN INTEGER.MAX 245 PRINT.PRINTINTEGER 246 )"), 184 247 new Median()); 185 248 } … … 190 253 public void MirrorImage() { 191 254 TestProgram( 192 PushParser.ParseProgram( 193 @"( IN1 IN2 194 INTEGER[].PUSHALL INTEGER[].ITERATE ( 195 INTEGER.= BOOLEAN.NOT EXEC.WHEN ( false EXEC.FLUSH ) 196 ) 197 true 198 )"), 255 PushParser.ParseProgram(@" 256 ( 257 INTEGER[].PUSHALL INTEGER[].ITERATE ( 258 INTEGER.= BOOLEAN.NOT EXEC.WHEN ( 259 false EXEC.FLUSH 260 ) 261 ) 262 true 263 )"), 199 264 new MirrorImage()); 200 265 } … … 205 270 public void NegativeToZero() { 206 271 TestProgram( 207 PushParser.ParseProgram("( IN1 INTEGER[].DUP INTEGER[].LENGTH INTEGER.DEC EXEC.DO*COUNT ( INTEGER.DUP INTEGER[].DUP INTEGER[].NTH 0 INTEGER.< EXEC.WHEN ( 0 INTEGER[].SET ) ) )"), 272 PushParser.ParseProgram(@" 273 ( 274 INTEGER[].DUP INTEGER[].LENGTH INTEGER.DEC 275 EXEC.DO*COUNT ( 276 INTEGER.DUP INTEGER[].DUP INTEGER[].NTH 0 INTEGER.< 277 EXEC.WHEN ( 278 0 INTEGER[].SET 279 ) 280 ) 281 )"), 208 282 new NegativeToZero()); 209 283 } … … 214 288 public void NumberIo() { 215 289 TestProgram( 216 PushParser.ParseProgram("IN1 IN2 FLOAT.FROMINTEGER FLOAT.+ PRINT.PRINTFLOAT"), 290 PushParser.ParseProgram(@" 291 ( 292 FLOAT.FROMINTEGER FLOAT.+ PRINT.PRINTFLOAT 293 )"), 217 294 new NumberIO()); 218 295 } … … 224 301 public void PigLatin() { 225 302 TestProgram( 226 PushParser.ParseProgram("@( STRING.SPLIT STRING.STACKDEPTH 0 INTEGER.= EXEC.WHEN EXEC.FLUSH STRING.STACKDEPTH EXEC.DO*TIMES ( STRING.DUP STRING.FIRST CHAR.ALLFROMSTRING CHAR.DUP \"aeiou\" STRING.CONTAINSCHAR EXEC.IF ( CHAR.POP ) ( STRING.REST STRING.CONJCHAR ) \"ay\" STRING.CONCAT STRING.STACKDEPTH 1 INTEGER.> EXEC.WHEN ( ' ' STRING.CONJCHAR ) PRINT.PRINTSTRING ) )"), 303 PushParser.ParseProgram(@" 304 ( 305 STRING.SPLIT STRING.STACKDEPTH 0 INTEGER.= 306 EXEC.WHEN EXEC.FLUSH 307 STRING.STACKDEPTH EXEC.DO*TIMES ( 308 STRING.DUP STRING.FIRST CHAR.ALLFROMSTRING CHAR.DUP ""aeiou"" 309 STRING.CONTAINSCHAR EXEC.IF ( 310 CHAR.POP 311 ) ( 312 STRING.REST STRING.CONJCHAR 313 ) 314 ""ay"" STRING.CONCAT 315 STRING.STACKDEPTH 1 INTEGER.> 316 EXEC.WHEN ( 317 ' ' STRING.CONJCHAR 318 ) 319 PRINT.PRINTSTRING 320 ) 321 )"), 227 322 new PigLatin()); 228 323 } … … 234 329 235 330 TestProgram( 236 PushParser.ParseProgram("IN1 STRING.DUP 0 STRING.ITERATE ( CHAR.DUP ' ' CHAR.= EXEC.IF ( CHAR.POP '\n' ) INTEGER.INC PRINT.PRINTCHAR )"), 331 PushParser.ParseProgram(@" 332 ( 333 STRING.DUP 0 STRING.ITERATE ( 334 CHAR.DUP ' ' CHAR.= 335 EXEC.IF ( 336 CHAR.POP '\n' 337 ) 338 INTEGER.INC PRINT.PRINTCHAR 339 )"), 237 340 new ReplaceSpaceWithNewline()); 238 341 } … … 243 346 public void ScrabbleScore() { 244 347 TestProgram( 245 PushParser.ParseProgram("( IN1 STRING.ITERATE ( INTEGER.FROMCHAR INTEGER.DUP INTEGER.DUP 96 INTEGER.> 123 INTEGER.< BOOLEAN.AND EXEC.WHEN ( 32 INTEGER.- ) 65 INTEGER.- INTEGER.DUP INTEGER.DUP 0 INTEGER.>= 26 INTEGER.< BOOLEAN.AND EXEC.IF ( [1 3 3 2 1 4 2 4 1 8 5 1 3 1 1 3 10 1 1 1 1 4 4 8 4 10] INTEGER[].NTH INTEGER.+ ) ( INTEGER.POP ) ) )"), 348 PushParser.ParseProgram(@" 349 ( 350 STRING.ITERATE ( 351 INTEGER.FROMCHAR INTEGER.DUP INTEGER.DUP 352 96 INTEGER.> 353 123 INTEGER.< 354 BOOLEAN.AND EXEC.WHEN ( 355 32 INTEGER.- 356 ) 357 65 INTEGER.- INTEGER.DUP INTEGER.DUP 358 0 INTEGER.>= 359 26 INTEGER.< 360 BOOLEAN.AND EXEC.IF ( 361 [1 3 3 2 1 4 2 4 1 8 5 1 3 1 1 3 10 1 1 1 1 4 4 8 4 10] 362 INTEGER[].NTH INTEGER.+ 363 ) ( 364 INTEGER.POP 365 ) 366 ) 367 )"), 246 368 new ScrabbleScore()); 247 369 } … … 252 374 public void Smallest() { 253 375 TestProgram( 254 PushParser.ParseProgram("( 3 EXEC.DO*TIMES INTEGER.MIN PRINT.PRINTINTEGER )"), 376 PushParser.ParseProgram(@" 377 ( 378 3 EXEC.DO*TIMES INTEGER.MIN 379 PRINT.PRINTINTEGER 380 )"), 255 381 new Smallest()); 256 382 } … … 261 387 public void SmallOrLarge() { 262 388 TestProgram( 263 PushParser.ParseProgram( 264 @"IN1 265 INTEGER.DUP 1000 INTEGER.< 2000 INTEGER.>= 266 EXEC.WHEN ""large"" 267 EXEC.WHEN ""small"" 268 STRING.EMPTY 269 EXEC.WHEN """" 270 PRINT.PRINTSTRING"), 389 PushParser.ParseProgram(@" 390 ( 391 INTEGER.DUP 1000 INTEGER.< 2000 INTEGER.>= 392 EXEC.WHEN ""large"" 393 EXEC.WHEN ""small"" 394 STRING.EMPTY 395 EXEC.WHEN """" 396 PRINT.PRINTSTRING 397 )"), 271 398 new SmallOrLarge()); 272 399 } … … 277 404 public void StringDifferences() { 278 405 TestProgram( 279 PushParser.ParseProgram( 280 @"CHAR.ALLFROMSTRING 0 STRING.ITERATE ( 406 PushParser.ParseProgram(@" 407 ( 408 CHAR.ALLFROMSTRING 0 409 STRING.ITERATE ( 281 410 CHAR.DUP 2 CHAR.YANKDUP CHAR.= BOOLEAN.NOT EXEC.IF ( 282 411 INTEGER.DUP PRINT.ENSURE_NEWLINE PRINT.PRINTINTEGER 283 412 ' ' PRINT.PRINTCHAR PRINT.PRINTCHAR 284 413 ' ' PRINT.PRINTCHAR PRINT.PRINTCHAR 285 ) 286 ( CHAR.POP CHAR.POP ) 287 INTEGER.INC )"), 414 ) ( 415 CHAR.POP CHAR.POP 416 ) 417 INTEGER.INC 418 ) 419 )"), 288 420 new StringDifferences()); 289 421 } … … 294 426 public void StringLengthsBackwards() { 295 427 TestProgram( 296 PushParser.ParseProgram(@"STRING[].ITERATE ( STRING.LENGTH PRINT.ENSURE_NEWLINE PRINT.PRINTINTEGER )"), 428 PushParser.ParseProgram(@" 429 ( 430 STRING[].ITERATE ( 431 STRING.LENGTH PRINT.ENSURE_NEWLINE PRINT.PRINTINTEGER 432 ) 433 )"), 297 434 new StringLengthsBackwards()); 298 435 } … … 303 440 public void SumOfSquares() { 304 441 TestProgram( 305 PushParser.ParseProgram(@"( EXEC.DO*COUNT ( INTEGER.DUP INTEGER.* INTEGER.+ ) )"), 306 new SumOfSquares()); 442 PushParser.ParseProgram(@" 443 ( 444 EXEC.DO*COUNT ( 445 INTEGER.DUP INTEGER.* INTEGER.+ 446 ) 447 )"), 448 new SumOfSquares()); 307 449 } 308 450 … … 312 454 public void SuperAnagrams() { 313 455 TestProgram( 314 PushParser.ParseProgram(@"( IN1 IN2 STRING.SWAP STRING.DUP STRING.ITERATE ( CHAR.DUP STRING.DUP STRING.OCCURRENCESOFCHAR 1 STRING.YANKDUP STRING.OCCURRENCESOFCHAR INTEGER.> EXEC.WHEN ( false EXEC.FLUSH ) ) true )"), 456 PushParser.ParseProgram(@" 457 ( 458 STRING.SWAP STRING.DUP STRING.ITERATE ( 459 CHAR.DUP STRING.DUP STRING.OCCURRENCESOFCHAR 460 1 STRING.YANKDUP STRING.OCCURRENCESOFCHAR 461 INTEGER.> EXEC.WHEN ( 462 false EXEC.FLUSH 463 ) 464 ) 465 true 466 )"), 315 467 new SuperAnagrams()); 316 468 } … … 321 473 public void Syllables() { 322 474 TestProgram( 323 PushParser.ParseProgram("( IN1 \"aeiouy\" 0 STRING.ITERATE ( STRING.DUP STRING.OCCURRENCESOFCHAR INTEGER.+ ) \"The number of syllables is \" PRINT.PRINTSTRING PRINT.PRINTINTEGER )"), 475 PushParser.ParseProgram(@" 476 ( 477 ""aeiouy"" 0 STRING.ITERATE ( 478 STRING.DUP STRING.OCCURRENCESOFCHAR INTEGER.+ 479 ) 480 ""The number of syllables is "" 481 PRINT.PRINTSTRING PRINT.PRINTINTEGER 482 )"), 324 483 new Syllables()); 325 484 } … … 330 489 public void VectorAverage() { 331 490 TestProgram( 332 PushParser.ParseProgram("( IN1 FLOAT[].DUP FLOAT[].LENGTH FLOAT[].ITERATE FLOAT.+ FLOAT.FROMINTEGER FLOAT./ )"), 491 PushParser.ParseProgram(@" 492 ( 493 FLOAT[].DUP FLOAT[].LENGTH 494 FLOAT[].ITERATE FLOAT.+ 495 FLOAT.FROMINTEGER FLOAT./ 496 )"), 333 497 new VectorAverage()); 334 498 } … … 339 503 public void VectorSummed() { 340 504 TestProgram( 341 PushParser.ParseProgram(@"( IN1 IN2 INTEGER[].PUSHALL INTEGER[].DUP INTEGER[].LENGTH INTEGER.DEC EXEC.DO*COUNT ( INTEGER.DUP INTEGER[].DUP INTEGER[].NTH INTEGER.SWAP INTEGER.ROT INTEGER.+ INTEGER[].SET ) )"), 505 PushParser.ParseProgram(@" 506 ( 507 INTEGER[].PUSHALL INTEGER[].DUP 508 INTEGER[].LENGTH INTEGER.DEC 509 EXEC.DO*COUNT ( 510 INTEGER.DUP INTEGER[].DUP INTEGER[].NTH 511 INTEGER.SWAP INTEGER.ROT INTEGER.+ INTEGER[].SET 512 ) 513 )"), 342 514 new VectorSummed()); 343 515 } … … 348 520 public void WallisPi() { 349 521 TestProgram( 350 PushParser.ParseProgram(@"( 351 IN1 2 3 INTEGER.ROT INTEGER.ROT 522 PushParser.ParseProgram(@" 523 ( 524 2 3 INTEGER.ROT INTEGER.ROT 352 525 EXEC.DO*TIMES ( 353 526 2 EXEC.DO*TIMES ( … … 370 543 public void WordStats() { 371 544 TestProgram( 372 PushParser.ParseProgram(@"( 545 PushParser.ParseProgram(@" 546 ( 373 547 STRING.DUP STRING.SPLIT 374 548 STRING.STACKDEPTH 1 INTEGER.= BOOLEAN.NOT … … 414 588 public void XWordLines() { 415 589 TestProgram( 416 PushParser.ParseProgram(@"( 590 PushParser.ParseProgram(@" 591 ( 417 592 STRING.SPLIT STRING.EMPTY BOOLEAN.NOT INTEGER.DUP 1 INTEGER.= 418 593 EXEC.IF (
Note: See TracChangeset
for help on using the changeset viewer.