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