[14834] | 1 | namespace HeuristicLab.Tests.Interpreter.Expressions {
|
---|
[14727] | 2 | using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
|
---|
| 3 | using HeuristicLab.Problems.ProgramSynthesis.Push.Generators;
|
---|
| 4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
| 5 |
|
---|
| 6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 7 |
|
---|
| 8 | [TestClass]
|
---|
[14834] | 9 | public class NameExpressionTests : CommonTests<string> {
|
---|
[14727] | 10 | protected override string TypeName
|
---|
| 11 | {
|
---|
| 12 | get
|
---|
| 13 | {
|
---|
| 14 | return "NAME";
|
---|
| 15 | }
|
---|
| 16 | }
|
---|
| 17 |
|
---|
[14834] | 18 | protected override IPushStack<string> Stack
|
---|
[14727] | 19 | {
|
---|
| 20 | get
|
---|
| 21 | {
|
---|
[14908] | 22 | return interpreter.NameStack;
|
---|
[14727] | 23 | }
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | [TestMethod]
|
---|
| 27 | [TestProperty("Time", "Short")]
|
---|
| 28 | [TestCategory("ExpressionTest")]
|
---|
| 29 | [TestCategory("NameExpressionTest")]
|
---|
[14834] | 30 | public void TestRand() {
|
---|
[14952] | 31 | configuration.ErcOptions.NameErcOptions.IsEnabled = true;
|
---|
[14908] | 32 | interpreter.Run(new NameRandExpression());
|
---|
[14727] | 33 |
|
---|
[14908] | 34 | Assert.IsTrue(interpreter.NameStack.Count == 1);
|
---|
[14727] | 35 |
|
---|
[14908] | 36 | CheckOtherStacksAreEmpty();
|
---|
[14727] | 37 | }
|
---|
| 38 |
|
---|
| 39 | [TestMethod]
|
---|
| 40 | [TestProperty("Time", "Short")]
|
---|
| 41 | [TestCategory("ExpressionTest")]
|
---|
| 42 | [TestCategory("NameExpressionTest")]
|
---|
[14834] | 43 | public void TestRandomBound() {
|
---|
[14908] | 44 | interpreter.CustomExpressions.Add("c1", new CodeNoopExpression());
|
---|
| 45 | interpreter.CustomExpressions.Add("c2", new CodeNoopExpression());
|
---|
| 46 | interpreter.CustomExpressions.Add("c3", new CodeNoopExpression());
|
---|
[14727] | 47 |
|
---|
[14908] | 48 | interpreter.Run(new NameRandBoundNameExpression());
|
---|
[14727] | 49 |
|
---|
[14908] | 50 | Assert.IsTrue(interpreter.CustomExpressions.Keys.Contains(interpreter.NameStack.Top));
|
---|
[14727] | 51 |
|
---|
[14908] | 52 | CheckOtherStacksAreEmpty();
|
---|
[14727] | 53 | }
|
---|
| 54 |
|
---|
| 55 | [TestMethod]
|
---|
| 56 | [TestProperty("Time", "Short")]
|
---|
| 57 | [TestCategory("ExpressionTest")]
|
---|
| 58 | [TestCategory("NameExpressionTest")]
|
---|
[14834] | 59 | public void TestRandomBoundWithInsufficientArguments() {
|
---|
[14908] | 60 | TestWithInsufficientArguments("RANDBOUNDNAME");
|
---|
[14727] | 61 | }
|
---|
| 62 |
|
---|
| 63 | [TestMethod]
|
---|
| 64 | [TestProperty("Time", "Short")]
|
---|
| 65 | [TestCategory("ExpressionTest")]
|
---|
| 66 | [TestCategory("NameExpressionTest")]
|
---|
[14834] | 67 | public void TestQuote() {
|
---|
[14908] | 68 | interpreter.Run(new NameQuoteExpression());
|
---|
[14727] | 69 |
|
---|
[14908] | 70 | Assert.IsTrue(interpreter.IsNameQuoteFlagSet);
|
---|
[14727] | 71 |
|
---|
[14908] | 72 | TestStackCounts();
|
---|
[14727] | 73 | }
|
---|
| 74 |
|
---|
[14834] | 75 | protected override string[] GetValues(int count) {
|
---|
| 76 | var ng = new StringGenerator();
|
---|
[14727] | 77 | var values = new string[count];
|
---|
| 78 |
|
---|
| 79 | for (var i = 0; i < count; i++) values[i] = ng.GetNext();
|
---|
| 80 |
|
---|
| 81 | return values;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[14834] | 84 | protected override void CheckOtherStacksAreEmpty() {
|
---|
[14908] | 85 | TestStackCounts(nameStack: null);
|
---|
[14727] | 86 | }
|
---|
| 87 | }
|
---|
| 88 | } |
---|