Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Tests/Interpreter/ExpressionTest.cs @ 17243

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

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

File size: 3.1 KB
Line 
1using HeuristicLab.Problems.ProgramSynthesis;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
3
4namespace HeuristicLab.Tests.Interpreter {
5  public class ExpressionTest {
6    protected PushInterpreter interpreter;
7
8    protected PushConfiguration configuration = new PushConfiguration {
9      TopLevelPushCode = false,
10      FloatStringFormat = "R",
11      ErcOptions = new ErcOptions {
12        ErcProbability = 0.05,
13        CharErcOptions = new CharErcOptions(new IntegerRangeErc(0x20, 0x7e)),
14        StringErcOptions = new StringErcOptions(new StringRandomErc {
15          IsEnabled = true,
16          AllowDigits = true,
17          NewStringProbability = 1,
18          AllowLowercaseLetters = true,
19          AllowUppercaseLetters = true
20        }),
21        IntegerErcOptions = new IntegerErcOptions(new IntegerRangeErc(-10000, 10000)),
22        FloatErcOptions = new FloatErcOptions(new FloatRangeErc(-10000, 10000)),
23        BooleanErcOptions = new BooleanErcOptions(new BooleanRandomErc(true, true, true)),
24        StringVectorErcOptions = new StringVectorErcOptions(
25          new StringVectorConstantsErc(new[] { "test", "123", "asdf", "a", "b" })),
26        IntegerVectorErcOptions = new IntegerVectorErcOptions(
27          new IntegerVectorConstantsErc(new[] { 0, -5, 10, 8, -3 })),
28        FloatVectorErcOptions = new FloatVectorErcOptions(
29          new FloatVectorConstantsErc(new[] { 0.0, -5.2, 10.3, 8.1, -3.4 }))
30      }
31    };
32
33    [TestInitialize]
34    public void BeforeTest() {
35      interpreter = new PushInterpreter(1337, configuration);
36    }
37
38    protected void TestStackCounts(
39      int? execStack = 0,
40      int? codeStack = 0,
41      int? nameStack = 0,
42      int? booleanStack = 0,
43      int? floatStack = 0,
44      int? integerStack = 0,
45      int? charStack = 0,
46      int? stringStack = 0,
47      int? integerVectorStack = 0,
48      int? floatVectorStack = 0,
49      int? booleanVectorStack = 0,
50      int? stringVectorStack = 0) {
51      if (execStack.HasValue) Assert.AreEqual(execStack, interpreter.ExecStack.Count);
52      if (codeStack.HasValue) Assert.AreEqual(codeStack, interpreter.CodeStack.Count);
53      if (nameStack.HasValue) Assert.AreEqual(nameStack, interpreter.NameStack.Count);
54      if (booleanStack.HasValue) Assert.AreEqual(booleanStack, interpreter.BooleanStack.Count);
55      if (floatStack.HasValue) Assert.AreEqual(floatStack, interpreter.FloatStack.Count);
56      if (integerStack.HasValue) Assert.AreEqual(integerStack, interpreter.IntegerStack.Count);
57      if (charStack.HasValue) Assert.AreEqual(charStack, interpreter.CharStack.Count);
58      if (stringStack.HasValue) Assert.AreEqual(stringStack, interpreter.StringStack.Count);
59      if (integerVectorStack.HasValue) Assert.AreEqual(integerVectorStack, interpreter.IntegerVectorStack.Count);
60      if (floatVectorStack.HasValue) Assert.AreEqual(floatVectorStack, interpreter.FloatVectorStack.Count);
61      if (booleanVectorStack.HasValue) Assert.AreEqual(booleanVectorStack, interpreter.BooleanVectorStack.Count);
62      if (stringVectorStack.HasValue) Assert.AreEqual(stringVectorStack, interpreter.StringVectorStack.Count);
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.