1 | namespace 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 | } |
---|