Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14727 was 14727, checked in by pkimmesw, 7 years ago

#2665 PushGP HL Integration, Views, Parameters

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