Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/17 09:28:34 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/ExpressionTest.cs

    r14908 r15017  
    11namespace HeuristicLab.Tests.Interpreter {
    2   using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
    3   using HeuristicLab.Problems.ProgramSynthesis.Push.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;
    47
    58  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;
    615
    716  public class ExpressionTest {
    817    protected PushInterpreter interpreter;
    918
    10     protected PushConfiguration configuration = new PushConfiguration { TopLevelPushCode = false };
     19    protected PushConfiguration configuration = new PushConfiguration {
     20      TopLevelPushCode = false,
     21      ErcOptions = new ErcOptions {
     22        ErcProbability = 0.05,
     23        CharErcOptions = new CharErcOptions(new IntegerRangeErc(0x20, 0x7e)),
     24        StringErcOptions = new StringErcOptions(new StringRandomErc {
     25          IsEnabled = true,
     26          AllowDigits = true,
     27          NewStringProbability = 1,
     28          AllowLowercaseLetters = true,
     29          AllowUppercaseLetters = true
     30        }),
     31        IntegerErcOptions = new IntegerErcOptions(new IntegerRangeErc(-10000, 10000)),
     32        FloatErcOptions = new FloatErcOptions(new FloatRangeErc(-10000, 10000)),
     33        BooleanErcOptions = new BooleanErcOptions(new BooleanRandomErc(true, true, true)),
     34        StringVectorErcOptions = new StringVectorErcOptions(
     35          new StringVectorConstantsErc(new[] { "test", "123", "asdf", "a", "b" })),
     36        IntegerVectorErcOptions = new IntegerVectorErcOptions(
     37          new IntegerVectorConstantsErc(new[] { 0, -5, 10, 8, -3 })),
     38        FloatVectorErcOptions = new FloatVectorErcOptions(
     39          new FloatVectorConstantsErc(new[] { 0.0, -5.2, 10.3, 8.1, -3.4 }))
     40      }
     41    };
    1142
    1243    [TestInitialize]
    1344    public void BeforeTest() {
    14       interpreter = new PushInterpreter(configuration);
     45      interpreter = new PushInterpreter(1337, configuration);
    1546    }
    1647
     
    2152      int? booleanStack = 0,
    2253      int? floatStack = 0,
    23       int? integerStack = 0) {
     54      int? integerStack = 0,
     55      int? charStack = 0,
     56      int? stringStack = 0,
     57      int? integerVectorStack = 0,
     58      int? floatVectorStack = 0,
     59      int? booleanVectorStack = 0,
     60      int? stringVectorStack = 0) {
    2461      if (execStack.HasValue) Assert.AreEqual(execStack, interpreter.ExecStack.Count);
    25 
    2662      if (codeStack.HasValue) Assert.AreEqual(codeStack, interpreter.CodeStack.Count);
    27 
    2863      if (nameStack.HasValue) Assert.AreEqual(nameStack, interpreter.NameStack.Count);
    29 
    3064      if (booleanStack.HasValue) Assert.AreEqual(booleanStack, interpreter.BooleanStack.Count);
    31 
    3265      if (floatStack.HasValue) Assert.AreEqual(floatStack, interpreter.FloatStack.Count);
    33 
    3466      if (integerStack.HasValue) Assert.AreEqual(integerStack, interpreter.IntegerStack.Count);
     67      if (charStack.HasValue) Assert.AreEqual(charStack, interpreter.CharStack.Count);
     68      if (stringStack.HasValue) Assert.AreEqual(stringStack, interpreter.StringStack.Count);
     69      if (integerVectorStack.HasValue) Assert.AreEqual(integerVectorStack, interpreter.IntegerVectorStack.Count);
     70      if (floatVectorStack.HasValue) Assert.AreEqual(floatVectorStack, interpreter.FloatVectorStack.Count);
     71      if (booleanVectorStack.HasValue) Assert.AreEqual(booleanVectorStack, interpreter.BooleanVectorStack.Count);
     72      if (stringVectorStack.HasValue) Assert.AreEqual(stringVectorStack, interpreter.StringVectorStack.Count);
    3573    }
    3674  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/CodeExpressionTests.cs

    r14908 r15017  
    430430
    431431      Assert.AreEqual(3, interpreter.IntegerStack.Top);
    432       TestStackCounts(codeStack: 1, integerStack: 2);
     432      TestStackCounts(integerStack: 1);
    433433    }
    434434
     
    455455      var prog = PushParser.Parse("( INTEGER.DUP INTEGER.+ )");
    456456
    457       interpreter.IntegerStack.Push(2, 3);
     457      interpreter.IntegerStack.Push(2, 4);
    458458      interpreter.CodeStack.Push(prog);
    459459      interpreter.Run(new CodeDoTimesExpression());
     
    508508    public void TestNestedDoTimes() {
    509509      interpreter.Run(
    510         "( 3 CODE.QUOTE ( 2 3 CODE.QUOTE ( 2 INTEGER.* ) CODE.DO*TIMES INTEGER.+ ) CODE.DO*TIMES )");
     510        "( 4 CODE.QUOTE ( 2 4 CODE.QUOTE ( 2 INTEGER.* ) CODE.DO*TIMES INTEGER.+ ) CODE.DO*TIMES )");
    511511
    512512      Assert.AreEqual(128, interpreter.IntegerStack.Top);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/CommonTests.cs

    r14908 r15017  
    3535
    3636      var isBooleanStack = interpreter.BooleanStack.Count == 2;
    37 
    3837      Test(ExpressionTable.GetStatelessExpression(TypeName + ".="));
    3938
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/ExampleTests.cs

    r14908 r15017  
    145145    public void Example10() {
    146146      interpreter.IntegerStack.Push(5);
    147       interpreter.Run("( 1 INTEGER.MAX 1 EXEC.DO*RANGE ( 2 INTEGER.* ) )");
    148 
    149       Assert.AreEqual(2, interpreter.IntegerStack.Top);
     147      interpreter.Run("( 1 INTEGER.MAX 1 EXEC.DO*RANGE ( 2 INTEGER.* INTEGER.* ) )");
     148
     149      Assert.AreEqual(3840, interpreter.IntegerStack.Top);
    150150      Assert.IsTrue(interpreter.CodeStack.IsEmpty);
    151151      Assert.IsTrue(interpreter.ExecStack.IsEmpty);
     
    254254      interpreter.FloatStack.Push(2);
    255255      interpreter.Run(@"( ARG FLOAT.DEFINE
    256                                      EXEC.Y (
    257                                        ARG FLOAT.*
    258                                        1 INTEGER.-
    259                                        INTEGER.DUP 1 INTEGER.>
    260                                        EXEC.IF ( ) EXEC.POP
    261                                      )
    262                                    )");
     256                          EXEC.Y (
     257                            ARG FLOAT.*
     258                            1 INTEGER.-
     259                            INTEGER.DUP 1 INTEGER.>
     260                            EXEC.IF ( ) EXEC.POP
     261                          )
     262                        )");
    263263
    264264      Assert.AreEqual(1024, interpreter.FloatStack.Top, Delta);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/ExecExpressionTests.cs

    r14908 r15017  
    111111    public void TestNestedDoRange() {
    112112      interpreter.Run(
    113         "( 0 2 EXEC.DO*RANGE ( 1 INTEGER.+ 0 3 EXEC.DO*RANGE ( 1 INTEGER.+ INTEGER.* ) INTEGER.+ )");
     113        "( 1 0 2 EXEC.DO*RANGE ( INTEGER.POP 1 1 4 EXEC.DO*RANGE INTEGER.* INTEGER.* ) )");
    114114
    115       Assert.AreEqual(144, interpreter.IntegerStack.Top);
     115      Assert.AreEqual(13824, interpreter.IntegerStack.Top);
    116116      TestStackCounts(integerStack: 1);
    117117    }
     
    134134    [TestCategory("ExecExpressionTest")]
    135135    public void TestNestedDoTimes() {
    136       interpreter.Run("( 3 EXEC.DO*TIMES ( 2 3 EXEC.DO*TIMES ( 2 INTEGER.* ) INTEGER.+ )");
     136      interpreter.Run("( 4 EXEC.DO*TIMES ( 2 4 EXEC.DO*TIMES ( 2 INTEGER.* ) INTEGER.+ )");
    137137
    138138      Assert.AreEqual(128, interpreter.IntegerStack.Top);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/IntegerExpressionTests.cs

    r14908 r15017  
    3232
    3333      Assert.AreEqual(10, interpreter.IntegerStack.Top);
    34 
    3534      TestStackCounts(integerStack: 1);
    3635    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/StandardTests.cs

    r14746 r15017  
    1313  public class StandardTests {
    1414    [TestMethod]
     15    [TestProperty("Time", "Short")]
     16    [TestCategory("ExpressionTest")]
     17    [TestCategory("StandartTests")]
    1518    public void TestGetHashCode() {
    1619      var expressionTypes = from domainAssembly in AppDomain.CurrentDomain.GetAssemblies()
     
    2225
    2326      var expressions = expressionTypes.Select(et => Activator.CreateInstance(et) as Expression);
    24       var ids = expressions.Select(e => new { Epxression = e, Id = e.GetHashCode() });
     27      var ids = expressions.Select(e => new { Expression = e, Id = e.GetHashCode() });
    2528
    26       var duplicates = ids.GroupBy(s => s).SelectMany(grp => grp.Skip(1));
     29      var duplicateGroups = ids.GroupBy(s => s.Id).Where(grp => grp.Count() > 2).ToList();
    2730
    28       if (!duplicates.Any())
     31      if (!duplicateGroups.Any())
    2932        return;
    3033
    3134      Debug.WriteLine("Duplicates: ");
    32       foreach (var duplicate in duplicates)
    33         Debug.WriteLine("Id: {0}, Expression: {1}", duplicate.Id, duplicate.Epxression);
     35      foreach (var group in duplicateGroups) {
     36        foreach (var duplicate in group) {
     37          string name;
     38          if (!ExpressionTable.TypeToNameTable.TryGetValue(duplicate.Expression.GetType(), out name)) {
     39            name = duplicate.Expression.ToString();
     40          }
     41
     42          Debug.WriteLine("Id: {0}, Expression: {1}", duplicate.Id, name);
     43        }
     44
     45        Debug.WriteLine("");
     46      }
    3447
    3548      Assert.Fail();
     
    3750
    3851    [TestMethod]
     52    [TestProperty("Time", "Short")]
     53    [TestCategory("ExpressionTest")]
     54    [TestCategory("StandartTests")]
    3955    public void TestExpandGetHashCode() {
    4056      var expand = PushParser.Parse("( A B C D E F )");
     
    4460
    4561    [TestMethod]
     62    [TestProperty("Time", "Short")]
     63    [TestCategory("ExpressionTest")]
     64    [TestCategory("StandartTests")]
    4665    public void TestExecExpandCopy() {
    4766      var expressions = new Expression[]
     
    5978
    6079    [TestMethod]
     80    [TestProperty("Time", "Short")]
     81    [TestCategory("ExpressionTest")]
     82    [TestCategory("StandartTests")]
    6183    public void TestExecExpandRecursiveCopy() {
    6284      var expressions = new List<Expression>
     
    83105
    84106    [TestMethod]
     107    [TestProperty("Time", "Short")]
     108    [TestCategory("ExpressionTest")]
     109    [TestCategory("StandartTests")]
    85110    public void TestExecExpandRecursiveGetHashCode() {
    86111      var expressions = new List<Expression>
Note: See TracChangeset for help on using the changeset viewer.