Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/NameExpressionTests.cs @ 16958

Last change on this file since 16958 was 14952, checked in by pkimmesw, 8 years ago

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File size: 2.5 KB
Line 
1namespace HeuristicLab.Tests.Interpreter.Expressions {
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]
9  public class NameExpressionTests : CommonTests<string> {
10    protected override string TypeName
11    {
12      get
13      {
14        return "NAME";
15      }
16    }
17
18    protected override IPushStack<string> Stack
19    {
20      get
21      {
22        return interpreter.NameStack;
23      }
24    }
25
26    [TestMethod]
27    [TestProperty("Time", "Short")]
28    [TestCategory("ExpressionTest")]
29    [TestCategory("NameExpressionTest")]
30    public void TestRand() {
31      configuration.ErcOptions.NameErcOptions.IsEnabled = true;
32      interpreter.Run(new NameRandExpression());
33
34      Assert.IsTrue(interpreter.NameStack.Count == 1);
35
36      CheckOtherStacksAreEmpty();
37    }
38
39    [TestMethod]
40    [TestProperty("Time", "Short")]
41    [TestCategory("ExpressionTest")]
42    [TestCategory("NameExpressionTest")]
43    public void TestRandomBound() {
44      interpreter.CustomExpressions.Add("c1", new CodeNoopExpression());
45      interpreter.CustomExpressions.Add("c2", new CodeNoopExpression());
46      interpreter.CustomExpressions.Add("c3", new CodeNoopExpression());
47
48      interpreter.Run(new NameRandBoundNameExpression());
49
50      Assert.IsTrue(interpreter.CustomExpressions.Keys.Contains(interpreter.NameStack.Top));
51
52      CheckOtherStacksAreEmpty();
53    }
54
55    [TestMethod]
56    [TestProperty("Time", "Short")]
57    [TestCategory("ExpressionTest")]
58    [TestCategory("NameExpressionTest")]
59    public void TestRandomBoundWithInsufficientArguments() {
60      TestWithInsufficientArguments("RANDBOUNDNAME");
61    }
62
63    [TestMethod]
64    [TestProperty("Time", "Short")]
65    [TestCategory("ExpressionTest")]
66    [TestCategory("NameExpressionTest")]
67    public void TestQuote() {
68      interpreter.Run(new NameQuoteExpression());
69
70      Assert.IsTrue(interpreter.IsNameQuoteFlagSet);
71
72      TestStackCounts();
73    }
74
75    protected override string[] GetValues(int count) {
76      var ng = new StringGenerator();
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
84    protected override void CheckOtherStacksAreEmpty() {
85      TestStackCounts(nameStack: null);
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.