Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Tests/Interpreter/Expressions/NameExpressionTests.cs @ 16752

Last change on this file since 16752 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

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