Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/ExpressionTest.cs

Last change on this file was 15334, checked in by pkimmesw, 7 years ago

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

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