Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 Full Push 3.0 instruction set and tests; Added first benchmark test (count odds) for random walk tests;

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