Changeset 14908 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/CodeExpressionTests.cs
- Timestamp:
- 05/02/17 22:03:01 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/CodeExpressionTests.cs
r14834 r14908 20 20 get 21 21 { 22 return this.interpreter.CodeStack;22 return interpreter.CodeStack; 23 23 } 24 24 } … … 33 33 var result = PushParser.Parse("( A B )"); 34 34 35 this.interpreter.CodeStack.Push(second, first);36 this.interpreter.Run(new CodeAppendExpression());37 38 Assert.AreEqual(result, this.interpreter.CodeStack.Top);39 this.CheckOtherStacksAreEmpty();35 interpreter.CodeStack.Push(second, first); 36 interpreter.Run(new CodeAppendExpression()); 37 38 Assert.AreEqual(result, interpreter.CodeStack.Top); 39 CheckOtherStacksAreEmpty(); 40 40 } 41 41 … … 49 49 var result = PushParser.Parse("( A 5 )"); 50 50 51 this.interpreter.CodeStack.Push(second, first);52 this.interpreter.Run(new CodeAppendExpression());53 54 Assert.AreEqual(result, this.interpreter.CodeStack.Top);55 this.CheckOtherStacksAreEmpty();51 interpreter.CodeStack.Push(second, first); 52 interpreter.Run(new CodeAppendExpression()); 53 54 Assert.AreEqual(result, interpreter.CodeStack.Top); 55 CheckOtherStacksAreEmpty(); 56 56 } 57 57 … … 65 65 var result = PushParser.Parse("( 4 5 )"); 66 66 67 this.interpreter.CodeStack.Push(second, first);68 this.interpreter.Run(new CodeAppendExpression());69 70 Assert.AreEqual(result, this.interpreter.CodeStack.Top);71 this.CheckOtherStacksAreEmpty();67 interpreter.CodeStack.Push(second, first); 68 interpreter.Run(new CodeAppendExpression()); 69 70 Assert.AreEqual(result, interpreter.CodeStack.Top); 71 CheckOtherStacksAreEmpty(); 72 72 } 73 73 … … 80 80 var result = PushParser.Parse("( A B C )"); 81 81 82 this.interpreter.CodeStack.Push(list);83 this.interpreter.Run(new CodeDuplicateExpression());84 85 Assert.AreEqual( this.Stack.Count, 2);86 Assert.AreEqual( this.Stack[0], list);87 Assert.AreEqual( this.Stack[1], result);88 89 this.CheckOtherStacksAreEmpty();82 interpreter.CodeStack.Push(list); 83 interpreter.Run(new CodeDuplicateExpression()); 84 85 Assert.AreEqual(Stack.Count, 2); 86 Assert.AreEqual(Stack[0], list); 87 Assert.AreEqual(Stack[1], result); 88 89 CheckOtherStacksAreEmpty(); 90 90 } 91 91 … … 97 97 var first = PushParser.Parse("( A )"); 98 98 99 this.interpreter.CodeStack.Push(first);100 this.interpreter.Run(new CodeAtomExpression());101 102 Assert.AreEqual(false, this.interpreter.BooleanStack.Top);103 this.TestStackCounts(booleanStack: 1);99 interpreter.CodeStack.Push(first); 100 interpreter.Run(new CodeAtomExpression()); 101 102 Assert.AreEqual(false, interpreter.BooleanStack.Top); 103 TestStackCounts(booleanStack: 1); 104 104 } 105 105 … … 111 111 var first = PushParser.Parse("5"); 112 112 113 this.interpreter.CodeStack.Push(first);114 this.interpreter.Run(new CodeAtomExpression());115 116 Assert.AreEqual(true, this.interpreter.BooleanStack.Top);117 this.TestStackCounts(booleanStack: 1);113 interpreter.CodeStack.Push(first); 114 interpreter.Run(new CodeAtomExpression()); 115 116 Assert.AreEqual(true, interpreter.BooleanStack.Top); 117 TestStackCounts(booleanStack: 1); 118 118 } 119 119 … … 125 125 var first = PushParser.Parse("INTEGER.+"); 126 126 127 this.interpreter.CodeStack.Push(first);128 this.interpreter.Run(new CodeAtomExpression());129 130 Assert.AreEqual(true, this.interpreter.BooleanStack.Top);131 this.TestStackCounts(booleanStack: 1);127 interpreter.CodeStack.Push(first); 128 interpreter.Run(new CodeAtomExpression()); 129 130 Assert.AreEqual(true, interpreter.BooleanStack.Top); 131 TestStackCounts(booleanStack: 1); 132 132 } 133 133 … … 140 140 var result = PushParser.Parse("A"); 141 141 142 this.interpreter.CodeStack.Push(first);143 this.interpreter.Run(new CodeCarExpression());144 145 Assert.AreEqual(result, this.interpreter.CodeStack.Top);146 this.CheckOtherStacksAreEmpty();142 interpreter.CodeStack.Push(first); 143 interpreter.Run(new CodeCarExpression()); 144 145 Assert.AreEqual(result, interpreter.CodeStack.Top); 146 CheckOtherStacksAreEmpty(); 147 147 } 148 148 … … 155 155 var result = PushParser.Parse("5"); 156 156 157 this.interpreter.CodeStack.Push(first);158 this.interpreter.Run(new CodeCarExpression());159 160 Assert.AreEqual(result, this.interpreter.CodeStack.Top);161 this.CheckOtherStacksAreEmpty();157 interpreter.CodeStack.Push(first); 158 interpreter.Run(new CodeCarExpression()); 159 160 Assert.AreEqual(result, interpreter.CodeStack.Top); 161 CheckOtherStacksAreEmpty(); 162 162 } 163 163 … … 170 170 var result = PushParser.Parse("( B C )"); 171 171 172 this.interpreter.CodeStack.Push(first);173 this.interpreter.Run(new CodeCdrExpression());174 175 Assert.AreEqual(result, this.interpreter.CodeStack.Top);176 this.CheckOtherStacksAreEmpty();172 interpreter.CodeStack.Push(first); 173 interpreter.Run(new CodeCdrExpression()); 174 175 Assert.AreEqual(result, interpreter.CodeStack.Top); 176 CheckOtherStacksAreEmpty(); 177 177 } 178 178 … … 185 185 var result = PushParser.Parse("( )"); 186 186 187 this.interpreter.CodeStack.Push(first);188 this.interpreter.Run(new CodeCdrExpression());189 190 Assert.AreEqual(result, this.interpreter.CodeStack.Top);191 this.CheckOtherStacksAreEmpty();187 interpreter.CodeStack.Push(first); 188 interpreter.Run(new CodeCdrExpression()); 189 190 Assert.AreEqual(result, interpreter.CodeStack.Top); 191 CheckOtherStacksAreEmpty(); 192 192 } 193 193 … … 201 201 var result = PushParser.Parse("( A B C )"); 202 202 203 this.interpreter.CodeStack.Push(second, first);204 this.interpreter.Run(new CodeConsExpression());205 206 Assert.AreEqual(result, this.interpreter.CodeStack.Top);207 this.CheckOtherStacksAreEmpty();203 interpreter.CodeStack.Push(second, first); 204 interpreter.Run(new CodeConsExpression()); 205 206 Assert.AreEqual(result, interpreter.CodeStack.Top); 207 CheckOtherStacksAreEmpty(); 208 208 } 209 209 … … 216 216 var second = PushParser.Parse("( A B C )"); 217 217 218 this.interpreter.CodeStack.Push(second, first);219 this.interpreter.Run(new CodeContainsExpression());220 221 Assert.AreEqual(true, this.interpreter.BooleanStack.Top);222 this.TestStackCounts(booleanStack: 1);218 interpreter.CodeStack.Push(second, first); 219 interpreter.Run(new CodeContainsExpression()); 220 221 Assert.AreEqual(true, interpreter.BooleanStack.Top); 222 TestStackCounts(booleanStack: 1); 223 223 } 224 224 … … 231 231 var second = PushParser.Parse("( A B C )"); 232 232 233 this.interpreter.CodeStack.Push(second, first);234 this.interpreter.Run(new CodeContainsExpression());235 236 Assert.AreEqual(false, this.interpreter.BooleanStack.Top);237 this.TestStackCounts(booleanStack: 1);233 interpreter.CodeStack.Push(second, first); 234 interpreter.Run(new CodeContainsExpression()); 235 236 Assert.AreEqual(false, interpreter.BooleanStack.Top); 237 TestStackCounts(booleanStack: 1); 238 238 } 239 239 … … 247 247 var result = PushParser.Parse("( C ( A ) )"); 248 248 249 this.interpreter.CodeStack.Push(second, first);250 this.interpreter.Run(new CodeContainerExpression());251 252 Assert.AreEqual(result, this.interpreter.CodeStack.Top);253 this.CheckOtherStacksAreEmpty();249 interpreter.CodeStack.Push(second, first); 250 interpreter.Run(new CodeContainerExpression()); 251 252 Assert.AreEqual(result, interpreter.CodeStack.Top); 253 CheckOtherStacksAreEmpty(); 254 254 } 255 255 … … 261 261 var code = PushParser.Parse("( A )"); 262 262 263 this.interpreter.CustomExpressions.Add("Test", code);264 this.interpreter.NameStack.Push("Test");265 266 this.interpreter.Run(new CodeDefinitionExpression());267 268 Assert.AreEqual(code, this.interpreter.CodeStack.Top);269 this.CheckOtherStacksAreEmpty();263 interpreter.CustomExpressions.Add("Test", code); 264 interpreter.NameStack.Push("Test"); 265 266 interpreter.Run(new CodeDefinitionExpression()); 267 268 Assert.AreEqual(code, interpreter.CodeStack.Top); 269 CheckOtherStacksAreEmpty(); 270 270 } 271 271 … … 278 278 var program = new CodeDefinitionExpression(); 279 279 280 this.interpreter.CustomExpressions.Add("Test1", code);281 this.interpreter.NameStack.Push("Test2");282 this.interpreter.Run(program);283 284 this.TestStackCounts(nameStack: 1);280 interpreter.CustomExpressions.Add("Test1", code); 281 interpreter.NameStack.Push("Test2"); 282 interpreter.Run(program); 283 284 TestStackCounts(nameStack: 1); 285 285 } 286 286 … … 293 293 var second = PushParser.Parse("( B C )"); 294 294 295 this.interpreter.CodeStack.Push(second, first);296 this.interpreter.Run(new CodeDiscrepancyExpression());297 298 Assert.AreEqual(2, this.interpreter.IntegerStack.Top);299 this.TestStackCounts(integerStack: 1);295 interpreter.CodeStack.Push(second, first); 296 interpreter.Run(new CodeDiscrepancyExpression()); 297 298 Assert.AreEqual(2, interpreter.IntegerStack.Top); 299 TestStackCounts(integerStack: 1); 300 300 } 301 301 … … 308 308 var second = PushParser.Parse("( B A )"); 309 309 310 this.interpreter.CodeStack.Push(second, first);311 this.interpreter.Run(new CodeDiscrepancyExpression());312 313 Assert.AreEqual(0, this.interpreter.IntegerStack.Top);314 this.TestStackCounts(integerStack: 1);310 interpreter.CodeStack.Push(second, first); 311 interpreter.Run(new CodeDiscrepancyExpression()); 312 313 Assert.AreEqual(0, interpreter.IntegerStack.Top); 314 TestStackCounts(integerStack: 1); 315 315 } 316 316 … … 323 323 var second = PushParser.Parse("( A A B D E )"); 324 324 325 this.interpreter.CodeStack.Push(second, first);326 this.interpreter.Run(new CodeDiscrepancyExpression());327 328 Assert.AreEqual(3, this.interpreter.IntegerStack.Top);329 this.TestStackCounts(integerStack: 1);325 interpreter.CodeStack.Push(second, first); 326 interpreter.Run(new CodeDiscrepancyExpression()); 327 328 Assert.AreEqual(3, interpreter.IntegerStack.Top); 329 TestStackCounts(integerStack: 1); 330 330 } 331 331 … … 338 338 var second = PushParser.Parse("( A ( A ) B D E )"); 339 339 340 this.interpreter.CodeStack.Push(second, first);341 this.interpreter.Run(new CodeDiscrepancyExpression());342 343 Assert.AreEqual(5, this.interpreter.IntegerStack.Top);344 this.TestStackCounts(integerStack: 1);340 interpreter.CodeStack.Push(second, first); 341 interpreter.Run(new CodeDiscrepancyExpression()); 342 343 Assert.AreEqual(5, interpreter.IntegerStack.Top); 344 TestStackCounts(integerStack: 1); 345 345 } 346 346 … … 352 352 var prog = PushParser.Parse("( 10 )"); 353 353 354 this.interpreter.CodeStack.Push(prog);355 this.interpreter.Run(new CodeDoExpression());356 357 Assert.AreEqual(10, this.interpreter.IntegerStack.Top);358 this.TestStackCounts(integerStack: 1);354 interpreter.CodeStack.Push(prog); 355 interpreter.Run(new CodeDoExpression()); 356 357 Assert.AreEqual(10, interpreter.IntegerStack.Top); 358 TestStackCounts(integerStack: 1); 359 359 } 360 360 … … 366 366 var prog = PushParser.Parse("( 10 )"); 367 367 368 this.interpreter.CodeStack.Push(prog);369 this.interpreter.Run(new CodeDoXExpression());370 371 Assert.AreEqual(10, this.interpreter.IntegerStack.Top);372 this.TestStackCounts(integerStack: 1);368 interpreter.CodeStack.Push(prog); 369 interpreter.Run(new CodeDoXExpression()); 370 371 Assert.AreEqual(10, interpreter.IntegerStack.Top); 372 TestStackCounts(integerStack: 1); 373 373 } 374 374 … … 380 380 var prog = PushParser.Parse("INTEGER.+"); 381 381 382 this.interpreter.IntegerStack.Push(3);383 this.interpreter.CodeStack.Push(prog);384 this.interpreter.Run(new CodeDoCountExpression());385 386 Assert.AreEqual(6, this.interpreter.IntegerStack.Top);387 this.TestStackCounts(integerStack: 1);382 interpreter.IntegerStack.Push(3); 383 interpreter.CodeStack.Push(prog); 384 interpreter.Run(new CodeDoCountExpression()); 385 386 Assert.AreEqual(6, interpreter.IntegerStack.Top); 387 TestStackCounts(integerStack: 1); 388 388 } 389 389 … … 395 395 var prog = PushParser.Parse("INTEGER.+"); 396 396 397 this.interpreter.IntegerStack.Push(-1);398 this.interpreter.CodeStack.Push(prog);399 this.interpreter.Run(new CodeDoCountExpression());400 401 Assert.AreEqual(-1, this.interpreter.IntegerStack.Top);402 this.TestStackCounts(codeStack: 1, integerStack: 1);397 interpreter.IntegerStack.Push(-1); 398 interpreter.CodeStack.Push(prog); 399 interpreter.Run(new CodeDoCountExpression()); 400 401 Assert.AreEqual(-1, interpreter.IntegerStack.Top); 402 TestStackCounts(codeStack: 1, integerStack: 1); 403 403 } 404 404 … … 410 410 var prog = PushParser.Parse("INTEGER.+"); 411 411 412 this.interpreter.IntegerStack.Push(3, 5);413 this.interpreter.CodeStack.Push(prog);414 this.interpreter.Run(new CodeDoRangeExpression());415 416 Assert.AreEqual(12, this.interpreter.IntegerStack.Top);417 this.TestStackCounts(integerStack: 1);412 interpreter.IntegerStack.Push(3, 5); 413 interpreter.CodeStack.Push(prog); 414 interpreter.Run(new CodeDoRangeExpression()); 415 416 Assert.AreEqual(12, interpreter.IntegerStack.Top); 417 TestStackCounts(integerStack: 1); 418 418 } 419 419 … … 425 425 var prog = PushParser.Parse("INTEGER.+"); 426 426 427 this.interpreter.IntegerStack.Push(3, 3);428 this.interpreter.CodeStack.Push(prog);429 this.interpreter.Run(new CodeDoRangeExpression());430 431 Assert.AreEqual(3, this.interpreter.IntegerStack.Top);432 this.TestStackCounts(codeStack: 1, integerStack: 2);427 interpreter.IntegerStack.Push(3, 3); 428 interpreter.CodeStack.Push(prog); 429 interpreter.Run(new CodeDoRangeExpression()); 430 431 Assert.AreEqual(3, interpreter.IntegerStack.Top); 432 TestStackCounts(codeStack: 1, integerStack: 2); 433 433 } 434 434 … … 440 440 var prog = PushParser.Parse("INTEGER.+"); 441 441 442 this.interpreter.IntegerStack.Push(-3, -5);443 this.interpreter.CodeStack.Push(prog);444 this.interpreter.Run(new CodeDoRangeExpression());445 446 Assert.AreEqual(-12, this.interpreter.IntegerStack.Top);447 this.TestStackCounts(integerStack: 1);442 interpreter.IntegerStack.Push(-3, -5); 443 interpreter.CodeStack.Push(prog); 444 interpreter.Run(new CodeDoRangeExpression()); 445 446 Assert.AreEqual(-12, interpreter.IntegerStack.Top); 447 TestStackCounts(integerStack: 1); 448 448 } 449 449 … … 455 455 var prog = PushParser.Parse("( INTEGER.DUP INTEGER.+ )"); 456 456 457 this.interpreter.IntegerStack.Push(2, 3);458 this.interpreter.CodeStack.Push(prog);459 this.interpreter.Run(new CodeDoTimesExpression());460 461 Assert.AreEqual(32, this.interpreter.IntegerStack.Top);462 this.TestStackCounts(integerStack: 1);457 interpreter.IntegerStack.Push(2, 3); 458 interpreter.CodeStack.Push(prog); 459 interpreter.Run(new CodeDoTimesExpression()); 460 461 Assert.AreEqual(32, interpreter.IntegerStack.Top); 462 TestStackCounts(integerStack: 1); 463 463 } 464 464 … … 470 470 var prog = PushParser.Parse("( INTEGER.DUP INTEGER.+ )"); 471 471 472 this.interpreter.IntegerStack.Push(2, -3);473 this.interpreter.CodeStack.Push(prog);474 this.interpreter.Run(new CodeDoTimesExpression());475 476 Assert.AreEqual(-3, this.interpreter.IntegerStack.Top);477 this.TestStackCounts(codeStack: 1, integerStack: 2);472 interpreter.IntegerStack.Push(2, -3); 473 interpreter.CodeStack.Push(prog); 474 interpreter.Run(new CodeDoTimesExpression()); 475 476 Assert.AreEqual(-3, interpreter.IntegerStack.Top); 477 TestStackCounts(codeStack: 1, integerStack: 2); 478 478 } 479 479 … … 483 483 [TestCategory("CodeExpressionTest")] 484 484 public void TestNestedDoRange() { 485 this.interpreter.Run(485 interpreter.Run( 486 486 "( 0 2 CODE.QUOTE ( 1 INTEGER.+ 0 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*RANGE INTEGER.+ ) CODE.DO*RANGE )"); 487 487 488 Assert.AreEqual(144, this.interpreter.IntegerStack.Top);489 this.TestStackCounts(integerStack: 1);488 Assert.AreEqual(144, interpreter.IntegerStack.Top); 489 TestStackCounts(integerStack: 1); 490 490 } 491 491 … … 495 495 [TestCategory("CodeExpressionTest")] 496 496 public void TestNestedDoCount() { 497 this.interpreter.Run(497 interpreter.Run( 498 498 "( 2 CODE.QUOTE ( 1 INTEGER.+ 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*COUNT INTEGER.+ ) CODE.DO*COUNT )"); 499 499 500 Assert.AreEqual(144, this.interpreter.IntegerStack.Top);501 this.TestStackCounts(integerStack: 1);500 Assert.AreEqual(144, interpreter.IntegerStack.Top); 501 TestStackCounts(integerStack: 1); 502 502 } 503 503 … … 507 507 [TestCategory("CodeExpressionTest")] 508 508 public void TestNestedDoTimes() { 509 this.interpreter.Run(509 interpreter.Run( 510 510 "( 3 CODE.QUOTE ( 2 3 CODE.QUOTE ( 2 INTEGER.* ) CODE.DO*TIMES INTEGER.+ ) CODE.DO*TIMES )"); 511 511 512 Assert.AreEqual(128, this.interpreter.IntegerStack.Top);513 this.TestStackCounts(integerStack: 1);512 Assert.AreEqual(128, interpreter.IntegerStack.Top); 513 TestStackCounts(integerStack: 1); 514 514 } 515 515 … … 522 522 var result = PushParser.Parse("( D )"); 523 523 524 this.interpreter.IntegerStack.Push(5);525 this.interpreter.CodeStack.Push(prog);526 this.interpreter.Run(new CodeExtractExpression());527 528 Assert.AreEqual(result, this.interpreter.CodeStack.Top);529 this.CheckOtherStacksAreEmpty();524 interpreter.IntegerStack.Push(5); 525 interpreter.CodeStack.Push(prog); 526 interpreter.Run(new CodeExtractExpression()); 527 528 Assert.AreEqual(result, interpreter.CodeStack.Top); 529 CheckOtherStacksAreEmpty(); 530 530 } 531 531 … … 538 538 var result = PushParser.Parse("5"); 539 539 540 this.interpreter.IntegerStack.Push(3);541 this.interpreter.CodeStack.Push(prog);542 this.interpreter.Run(new CodeExtractExpression());543 544 Assert.AreEqual(result, this.interpreter.CodeStack.Top);545 this.CheckOtherStacksAreEmpty();540 interpreter.IntegerStack.Push(3); 541 interpreter.CodeStack.Push(prog); 542 interpreter.Run(new CodeExtractExpression()); 543 544 Assert.AreEqual(result, interpreter.CodeStack.Top); 545 CheckOtherStacksAreEmpty(); 546 546 } 547 547 … … 554 554 var result = PushParser.Parse("4.2"); 555 555 556 this.interpreter.IntegerStack.Push(6);557 this.interpreter.CodeStack.Push(prog);558 this.interpreter.Run(new CodeExtractExpression());559 560 Assert.AreEqual(result, this.interpreter.CodeStack.Top);561 this.CheckOtherStacksAreEmpty();556 interpreter.IntegerStack.Push(6); 557 interpreter.CodeStack.Push(prog); 558 interpreter.Run(new CodeExtractExpression()); 559 560 Assert.AreEqual(result, interpreter.CodeStack.Top); 561 CheckOtherStacksAreEmpty(); 562 562 } 563 563 … … 570 570 var result = PushParser.Parse("FALSE"); 571 571 572 this.interpreter.IntegerStack.Push(8);573 this.interpreter.CodeStack.Push(prog);574 this.interpreter.Run(new CodeExtractExpression());575 576 Assert.AreEqual(result, this.interpreter.CodeStack.Top);577 this.CheckOtherStacksAreEmpty();572 interpreter.IntegerStack.Push(8); 573 interpreter.CodeStack.Push(prog); 574 interpreter.Run(new CodeExtractExpression()); 575 576 Assert.AreEqual(result, interpreter.CodeStack.Top); 577 CheckOtherStacksAreEmpty(); 578 578 } 579 579 … … 586 586 var result = PushParser.Parse("INTEGER.+"); 587 587 588 this.interpreter.IntegerStack.Push(7);589 this.interpreter.CodeStack.Push(prog);590 this.interpreter.Run(new CodeExtractExpression());591 592 Assert.AreEqual(result, this.interpreter.CodeStack.Top);593 this.CheckOtherStacksAreEmpty();588 interpreter.IntegerStack.Push(7); 589 interpreter.CodeStack.Push(prog); 590 interpreter.Run(new CodeExtractExpression()); 591 592 Assert.AreEqual(result, interpreter.CodeStack.Top); 593 CheckOtherStacksAreEmpty(); 594 594 } 595 595 … … 600 600 public void TestFromBoolean() { 601 601 var result = PushParser.Parse("FALSE"); 602 this.interpreter.BooleanStack.Push(false);603 this.interpreter.Run(new CodeFromBooleanExpression());604 605 Assert.AreEqual(result, this.interpreter.CodeStack.Top);606 this.CheckOtherStacksAreEmpty();602 interpreter.BooleanStack.Push(false); 603 interpreter.Run(new CodeFromBooleanExpression()); 604 605 Assert.AreEqual(result, interpreter.CodeStack.Top); 606 CheckOtherStacksAreEmpty(); 607 607 } 608 608 … … 613 613 public void TestFromFloat() { 614 614 var result = PushParser.Parse("4.1"); 615 this.interpreter.FloatStack.Push(4.1);616 this.interpreter.Run(new CodeFromFloatExpression());617 618 Assert.AreEqual(result, this.interpreter.CodeStack.Top);619 this.CheckOtherStacksAreEmpty();615 interpreter.FloatStack.Push(4.1); 616 interpreter.Run(new CodeFromFloatExpression()); 617 618 Assert.AreEqual(result, interpreter.CodeStack.Top); 619 CheckOtherStacksAreEmpty(); 620 620 } 621 621 … … 626 626 public void TestFromInteger() { 627 627 var result = PushParser.Parse("4"); 628 this.interpreter.IntegerStack.Push(4);629 this.interpreter.Run(new CodeFromIntegerExpression());630 631 Assert.AreEqual(result, this.interpreter.CodeStack.Top);632 this.CheckOtherStacksAreEmpty();628 interpreter.IntegerStack.Push(4); 629 interpreter.Run(new CodeFromIntegerExpression()); 630 631 Assert.AreEqual(result, interpreter.CodeStack.Top); 632 CheckOtherStacksAreEmpty(); 633 633 } 634 634 … … 639 639 public void TestFromName() { 640 640 var result = PushParser.Parse("A"); 641 this.interpreter.NameStack.Push("A");642 this.interpreter.Run(new CodeFromNameExpression());643 644 Assert.AreEqual(result, this.interpreter.CodeStack.Top);645 this.CheckOtherStacksAreEmpty();641 interpreter.NameStack.Push("A"); 642 interpreter.Run(new CodeFromNameExpression()); 643 644 Assert.AreEqual(result, interpreter.CodeStack.Top); 645 CheckOtherStacksAreEmpty(); 646 646 } 647 647 … … 654 654 var second = PushParser.Parse("WAHR"); 655 655 656 this.interpreter.BooleanStack.Push(true);657 this.interpreter.CodeStack.Push(second, first);658 this.interpreter.Run(new CodeIfExpression());659 660 Assert.AreEqual("WAHR", this.interpreter.NameStack.Top);661 this.TestStackCounts(nameStack: 1);656 interpreter.BooleanStack.Push(true); 657 interpreter.CodeStack.Push(second, first); 658 interpreter.Run(new CodeIfExpression()); 659 660 Assert.AreEqual("WAHR", interpreter.NameStack.Top); 661 TestStackCounts(nameStack: 1); 662 662 } 663 663 … … 670 670 var second = PushParser.Parse("WAHR"); 671 671 672 this.interpreter.BooleanStack.Push(false);673 this.interpreter.CodeStack.Push(second, first);674 this.interpreter.Run(new CodeIfExpression());675 676 Assert.AreEqual("FALSCH", this.interpreter.NameStack.Top);677 this.TestStackCounts(nameStack: 1);672 interpreter.BooleanStack.Push(false); 673 interpreter.CodeStack.Push(second, first); 674 interpreter.Run(new CodeIfExpression()); 675 676 Assert.AreEqual("FALSCH", interpreter.NameStack.Top); 677 TestStackCounts(nameStack: 1); 678 678 } 679 679 … … 687 687 var result = PushParser.Parse("( A ( B ) ( E ) D )"); 688 688 689 this.interpreter.IntegerStack.Push(2);690 this.interpreter.CodeStack.Push(second, first);691 this.interpreter.Run(new CodeInsertExpression());692 693 Assert.AreEqual(result, this.interpreter.CodeStack.Top);694 this.CheckOtherStacksAreEmpty();689 interpreter.IntegerStack.Push(2); 690 interpreter.CodeStack.Push(second, first); 691 interpreter.Run(new CodeInsertExpression()); 692 693 Assert.AreEqual(result, interpreter.CodeStack.Top); 694 CheckOtherStacksAreEmpty(); 695 695 } 696 696 … … 704 704 var result = PushParser.Parse("( A ( B ) ( E ) D )"); 705 705 706 this.interpreter.IntegerStack.Push(-2);707 this.interpreter.CodeStack.Push(second, first);708 this.interpreter.Run(new CodeInsertExpression());709 710 Assert.AreEqual(result, this.interpreter.CodeStack.Top);711 this.CheckOtherStacksAreEmpty();706 interpreter.IntegerStack.Push(-2); 707 interpreter.CodeStack.Push(second, first); 708 interpreter.Run(new CodeInsertExpression()); 709 710 Assert.AreEqual(result, interpreter.CodeStack.Top); 711 CheckOtherStacksAreEmpty(); 712 712 } 713 713 … … 721 721 var result = PushParser.Parse("( A ( B ) ( E ) D )"); 722 722 723 this.interpreter.IntegerStack.Push(10);724 this.interpreter.CodeStack.Push(second, first);725 this.interpreter.Run(new CodeInsertExpression());726 727 Assert.AreEqual(result, this.interpreter.CodeStack.Top);728 this.CheckOtherStacksAreEmpty();723 interpreter.IntegerStack.Push(10); 724 interpreter.CodeStack.Push(second, first); 725 interpreter.Run(new CodeInsertExpression()); 726 727 Assert.AreEqual(result, interpreter.CodeStack.Top); 728 CheckOtherStacksAreEmpty(); 729 729 } 730 730 … … 738 738 var result = PushParser.Parse("( A ( B ) )"); 739 739 740 this.interpreter.CodeStack.Push(second, first);741 this.interpreter.Run(new CodeListExpression());742 743 Assert.AreEqual(result, this.interpreter.CodeStack.Top);744 this.CheckOtherStacksAreEmpty();740 interpreter.CodeStack.Push(second, first); 741 interpreter.Run(new CodeListExpression()); 742 743 Assert.AreEqual(result, interpreter.CodeStack.Top); 744 CheckOtherStacksAreEmpty(); 745 745 } 746 746 … … 753 753 var second = PushParser.Parse("( B )"); 754 754 755 this.interpreter.CodeStack.Push(second, first);756 this.interpreter.Run(new CodeMemberExpression());757 758 Assert.AreEqual(true, this.interpreter.BooleanStack.Top);759 this.TestStackCounts(booleanStack: 1);755 interpreter.CodeStack.Push(second, first); 756 interpreter.Run(new CodeMemberExpression()); 757 758 Assert.AreEqual(true, interpreter.BooleanStack.Top); 759 TestStackCounts(booleanStack: 1); 760 760 } 761 761 … … 768 768 var second = PushParser.Parse("( B )"); 769 769 770 this.interpreter.CodeStack.Push(second, first);771 this.interpreter.Run(new CodeMemberExpression());772 773 Assert.AreEqual(false, this.interpreter.BooleanStack.Top);774 this.TestStackCounts(booleanStack: 1);770 interpreter.CodeStack.Push(second, first); 771 interpreter.Run(new CodeMemberExpression()); 772 773 Assert.AreEqual(false, interpreter.BooleanStack.Top); 774 TestStackCounts(booleanStack: 1); 775 775 } 776 776 … … 783 783 var second = PushParser.Parse("B"); 784 784 785 this.interpreter.CodeStack.Push(second, first);786 this.interpreter.Run(new CodeMemberExpression());787 788 Assert.AreEqual(true, this.interpreter.BooleanStack.Top);789 this.TestStackCounts(booleanStack: 1);785 interpreter.CodeStack.Push(second, first); 786 interpreter.Run(new CodeMemberExpression()); 787 788 Assert.AreEqual(true, interpreter.BooleanStack.Top); 789 TestStackCounts(booleanStack: 1); 790 790 } 791 791 … … 795 795 [TestCategory("CodeExpressionTest")] 796 796 public void TestNoop() { 797 this.interpreter.Run(new CodeNoopExpression());798 799 this.CheckOtherStacksAreEmpty();797 interpreter.Run(new CodeNoopExpression()); 798 799 CheckOtherStacksAreEmpty(); 800 800 } 801 801 … … 808 808 var result = PushParser.Parse("A"); 809 809 810 this.interpreter.IntegerStack.Push(3);811 this.interpreter.CodeStack.Push(prog);812 this.interpreter.Run(new CodeNthExpression());813 814 Assert.AreEqual(result, this.interpreter.CodeStack.Top);815 this.CheckOtherStacksAreEmpty();810 interpreter.IntegerStack.Push(3); 811 interpreter.CodeStack.Push(prog); 812 interpreter.Run(new CodeNthExpression()); 813 814 Assert.AreEqual(result, interpreter.CodeStack.Top); 815 CheckOtherStacksAreEmpty(); 816 816 } 817 817 … … 824 824 var result = PushParser.Parse("( )"); 825 825 826 this.interpreter.IntegerStack.Push(3);827 this.interpreter.CodeStack.Push(prog);828 this.interpreter.Run(new CodeNthExpression());829 830 Assert.AreEqual(result, this.interpreter.CodeStack.Top);831 this.CheckOtherStacksAreEmpty();826 interpreter.IntegerStack.Push(3); 827 interpreter.CodeStack.Push(prog); 828 interpreter.Run(new CodeNthExpression()); 829 830 Assert.AreEqual(result, interpreter.CodeStack.Top); 831 CheckOtherStacksAreEmpty(); 832 832 } 833 833 … … 840 840 var result = PushParser.Parse("D"); 841 841 842 this.interpreter.IntegerStack.Push(3);843 this.interpreter.CodeStack.Push(prog);844 this.interpreter.Run(new CodeNthExpression());845 846 Assert.AreEqual(result, this.interpreter.CodeStack.Top);847 this.CheckOtherStacksAreEmpty();842 interpreter.IntegerStack.Push(3); 843 interpreter.CodeStack.Push(prog); 844 interpreter.Run(new CodeNthExpression()); 845 846 Assert.AreEqual(result, interpreter.CodeStack.Top); 847 CheckOtherStacksAreEmpty(); 848 848 } 849 849 … … 856 856 var result = PushParser.Parse("D"); 857 857 858 this.interpreter.IntegerStack.Push(13);859 this.interpreter.CodeStack.Push(prog);860 this.interpreter.Run(new CodeNthExpression());861 862 Assert.AreEqual(result, this.interpreter.CodeStack.Top);863 this.CheckOtherStacksAreEmpty();858 interpreter.IntegerStack.Push(13); 859 interpreter.CodeStack.Push(prog); 860 interpreter.Run(new CodeNthExpression()); 861 862 Assert.AreEqual(result, interpreter.CodeStack.Top); 863 CheckOtherStacksAreEmpty(); 864 864 } 865 865 … … 872 872 var result = PushParser.Parse("D"); 873 873 874 this.interpreter.IntegerStack.Push(-3);875 this.interpreter.CodeStack.Push(prog);876 this.interpreter.Run(new CodeNthExpression());877 878 Assert.AreEqual(result, this.interpreter.CodeStack.Top);879 this.CheckOtherStacksAreEmpty();874 interpreter.IntegerStack.Push(-3); 875 interpreter.CodeStack.Push(prog); 876 interpreter.Run(new CodeNthExpression()); 877 878 Assert.AreEqual(result, interpreter.CodeStack.Top); 879 CheckOtherStacksAreEmpty(); 880 880 } 881 881 … … 888 888 var result = PushParser.Parse("D"); 889 889 890 this.interpreter.IntegerStack.Push(2);891 this.interpreter.CodeStack.Push(prog);892 this.interpreter.Run(new CodeNthCdrExpression());893 894 Assert.AreEqual(result, this.interpreter.CodeStack.Top);895 this.CheckOtherStacksAreEmpty();890 interpreter.IntegerStack.Push(2); 891 interpreter.CodeStack.Push(prog); 892 interpreter.Run(new CodeNthCdrExpression()); 893 894 Assert.AreEqual(result, interpreter.CodeStack.Top); 895 CheckOtherStacksAreEmpty(); 896 896 } 897 897 … … 904 904 var result = PushParser.Parse("D"); 905 905 906 this.interpreter.IntegerStack.Push(10);907 this.interpreter.CodeStack.Push(prog);908 this.interpreter.Run(new CodeNthCdrExpression());909 910 Assert.AreEqual(result, this.interpreter.CodeStack.Top);911 this.CheckOtherStacksAreEmpty();906 interpreter.IntegerStack.Push(10); 907 interpreter.CodeStack.Push(prog); 908 interpreter.Run(new CodeNthCdrExpression()); 909 910 Assert.AreEqual(result, interpreter.CodeStack.Top); 911 CheckOtherStacksAreEmpty(); 912 912 } 913 913 … … 920 920 var result = PushParser.Parse("D"); 921 921 922 this.interpreter.IntegerStack.Push(-2);923 this.interpreter.CodeStack.Push(prog);924 this.interpreter.Run(new CodeNthCdrExpression());925 926 Assert.AreEqual(result, this.interpreter.CodeStack.Top);927 this.CheckOtherStacksAreEmpty();922 interpreter.IntegerStack.Push(-2); 923 interpreter.CodeStack.Push(prog); 924 interpreter.Run(new CodeNthCdrExpression()); 925 926 Assert.AreEqual(result, interpreter.CodeStack.Top); 927 CheckOtherStacksAreEmpty(); 928 928 } 929 929 … … 936 936 var result = PushParser.Parse("( )"); 937 937 938 this.interpreter.IntegerStack.Push(3);939 this.interpreter.CodeStack.Push(prog);940 this.interpreter.Run(new CodeNthCdrExpression());941 942 Assert.AreEqual(result, this.interpreter.CodeStack.Top);943 this.CheckOtherStacksAreEmpty();938 interpreter.IntegerStack.Push(3); 939 interpreter.CodeStack.Push(prog); 940 interpreter.Run(new CodeNthCdrExpression()); 941 942 Assert.AreEqual(result, interpreter.CodeStack.Top); 943 CheckOtherStacksAreEmpty(); 944 944 } 945 945 … … 952 952 var result = PushParser.Parse("A"); 953 953 954 this.interpreter.IntegerStack.Push(3);955 this.interpreter.CodeStack.Push(prog);956 this.interpreter.Run(new CodeNthCdrExpression());957 958 Assert.AreEqual(result, this.interpreter.CodeStack.Top);959 this.CheckOtherStacksAreEmpty();954 interpreter.IntegerStack.Push(3); 955 interpreter.CodeStack.Push(prog); 956 interpreter.Run(new CodeNthCdrExpression()); 957 958 Assert.AreEqual(result, interpreter.CodeStack.Top); 959 CheckOtherStacksAreEmpty(); 960 960 } 961 961 … … 967 967 var prog = PushParser.Parse("( )"); 968 968 969 this.interpreter.CodeStack.Push(prog);970 this.interpreter.Run(new CodeNullExpression());971 972 Assert.AreEqual(true, this.interpreter.BooleanStack.Top);973 this.TestStackCounts(booleanStack: 1);969 interpreter.CodeStack.Push(prog); 970 interpreter.Run(new CodeNullExpression()); 971 972 Assert.AreEqual(true, interpreter.BooleanStack.Top); 973 TestStackCounts(booleanStack: 1); 974 974 } 975 975 … … 981 981 var prog = PushParser.Parse("A"); 982 982 983 this.interpreter.CodeStack.Push(prog);984 this.interpreter.Run(new CodeNullExpression());985 986 Assert.AreEqual(false, this.interpreter.BooleanStack.Top);987 this.TestStackCounts(booleanStack: 1);983 interpreter.CodeStack.Push(prog); 984 interpreter.Run(new CodeNullExpression()); 985 986 Assert.AreEqual(false, interpreter.BooleanStack.Top); 987 TestStackCounts(booleanStack: 1); 988 988 } 989 989 … … 996 996 var second = PushParser.Parse("C"); 997 997 998 this.interpreter.CodeStack.Push(second, first);999 this.interpreter.Run(new CodePositionExpression());1000 1001 Assert.AreEqual(2, this.interpreter.IntegerStack.Top);1002 this.TestStackCounts(integerStack: 1);998 interpreter.CodeStack.Push(second, first); 999 interpreter.Run(new CodePositionExpression()); 1000 1001 Assert.AreEqual(2, interpreter.IntegerStack.Top); 1002 TestStackCounts(integerStack: 1); 1003 1003 } 1004 1004 … … 1010 1010 var result = PushParser.Parse("A"); 1011 1011 1012 this.interpreter.Run("( CODE.QUOTE A )");1013 1014 Assert.AreEqual(result, this.interpreter.CodeStack.Top);1015 this.CheckOtherStacksAreEmpty();1012 interpreter.Run("( CODE.QUOTE A )"); 1013 1014 Assert.AreEqual(result, interpreter.CodeStack.Top); 1015 CheckOtherStacksAreEmpty(); 1016 1016 } 1017 1017 … … 1023 1023 var prog = PushParser.Parse("( A ( B ( C ) ) ( D ) INTEGER.+ )"); 1024 1024 1025 this.interpreter.CodeStack.Push(prog);1026 this.interpreter.Run(new CodeSizeExpression());1027 1028 Assert.AreEqual(4, this.interpreter.IntegerStack.Top);1029 this.TestStackCounts(integerStack: 1);1025 interpreter.CodeStack.Push(prog); 1026 interpreter.Run(new CodeSizeExpression()); 1027 1028 Assert.AreEqual(4, interpreter.IntegerStack.Top); 1029 TestStackCounts(integerStack: 1); 1030 1030 } 1031 1031 … … 1040 1040 var result = PushParser.Parse("( E B C D E B C D )"); 1041 1041 1042 this.interpreter.CodeStack.Push(third, second, first);1043 this.interpreter.Run(new CodeSubstitutionExpression());1044 1045 Assert.AreEqual(result, this.interpreter.CodeStack.Top);1046 this.CheckOtherStacksAreEmpty();1042 interpreter.CodeStack.Push(third, second, first); 1043 interpreter.Run(new CodeSubstitutionExpression()); 1044 1045 Assert.AreEqual(result, interpreter.CodeStack.Top); 1046 CheckOtherStacksAreEmpty(); 1047 1047 } 1048 1048 … … 1060 1060 1061 1061 protected override void CheckOtherStacksAreEmpty() { 1062 this.TestStackCounts(codeStack: null);1062 TestStackCounts(codeStack: null); 1063 1063 } 1064 1064 }
Note: See TracChangeset
for help on using the changeset viewer.