Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/NameExpressionTests.cs @ 14906

Last change on this file since 14906 was 14834, checked in by pkimmesw, 8 years ago

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File size: 2.6 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 this.interpreter.NameStack;
23      }
24    }
25
26    [TestMethod]
27    [TestProperty("Time", "Short")]
28    [TestCategory("ExpressionTest")]
29    [TestCategory("NameExpressionTest")]
30    public void TestRand() {
31      this.interpreter.Configuration.ErcOptions.NameErcOptions.IsEnabled = true;
32      this.interpreter.Run(new NameRandExpression());
33
34      Assert.IsTrue(this.interpreter.NameStack.Count == 1);
35
36      this.CheckOtherStacksAreEmpty();
37    }
38
39    [TestMethod]
40    [TestProperty("Time", "Short")]
41    [TestCategory("ExpressionTest")]
42    [TestCategory("NameExpressionTest")]
43    public void TestRandomBound() {
44      this.interpreter.CustomExpressions.Add("c1", new CodeNoopExpression());
45      this.interpreter.CustomExpressions.Add("c2", new CodeNoopExpression());
46      this.interpreter.CustomExpressions.Add("c3", new CodeNoopExpression());
47
48      this.interpreter.Run(new NameRandBoundNameExpression());
49
50      Assert.IsTrue(this.interpreter.CustomExpressions.Keys.Contains(this.interpreter.NameStack.Top));
51
52      this.CheckOtherStacksAreEmpty();
53    }
54
55    [TestMethod]
56    [TestProperty("Time", "Short")]
57    [TestCategory("ExpressionTest")]
58    [TestCategory("NameExpressionTest")]
59    public void TestRandomBoundWithInsufficientArguments() {
60      this.TestWithInsufficientArguments("RANDBOUNDNAME");
61    }
62
63    [TestMethod]
64    [TestProperty("Time", "Short")]
65    [TestCategory("ExpressionTest")]
66    [TestCategory("NameExpressionTest")]
67    public void TestQuote() {
68      this.interpreter.Run(new NameQuoteExpression());
69
70      Assert.IsTrue(this.interpreter.IsNameQuoteFlagSet);
71
72      this.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      this.TestStackCounts(nameStack: null);
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.