Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/16 22:57:11 (7 years ago)
Author:
pkimmesw
Message:

#2665 Added Problem.ProgramSynthesis Project, Fixed Expression Issues, Fixed Code Generation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Tests/Interpreter/Expressions/ExecExpressionTests.cs

    r14398 r14513  
    1 using HeuristicLab.Algorithms.PushGP;
    2 using HeuristicLab.Algorithms.PushGP.Expressions;
    3 using HeuristicLab.Algorithms.PushGP.Stack;
    4 using Microsoft.VisualStudio.TestTools.UnitTesting;
     1namespace HeuristicLab.Tests.Interpreter.Expressions {
     2  using HeuristicLab.Algorithms.PushGP.Expressions;
     3  using HeuristicLab.Algorithms.PushGP.Parser;
     4  using HeuristicLab.Algorithms.PushGP.Stack;
    55
    6 namespace HeuristicLab.Tests.Interpreter.Expressions
    7 {
    8     [TestClass]
    9     public class ExecExpressionTests : CommonTests<Expression>
     6  using Microsoft.VisualStudio.TestTools.UnitTesting;
     7
     8  [TestClass]
     9  public class ExecExpressionTests : CommonTests<Expression> {
     10    protected override string TypeName
    1011    {
    11         protected override string TypeName { get { return "EXEC"; } }
     12      get
     13      {
     14        return "EXEC";
     15      }
     16    }
    1217
    13         protected override IStack<Expression> Stack { get { return interpreter.ExecStack; } }
     18    protected override IStack<Expression> Stack
     19    {
     20      get
     21      {
     22        return this.interpreter.ExecStack;
     23      }
     24    }
    1425
    15         protected override void Test(Expression expression)
    16         {
    17             interpreter.InterpretAsync(expression, true).Wait();
    18         }
     26    protected override void Test(Expression expression) {
     27      this.interpreter.InterpretAsync(expression, true).Wait();
     28    }
    1929
    20         [TestMethod]
    21         [TestProperty("Time", "Short")]
    22         [TestCategory("ExpressionTest")]
    23         [TestCategory("ExecExpressionTest")]
    24         public void TestIfTrue()
    25         {
    26             interpreter.BooleanStack.Push(true);
    27             interpreter.Interpret("( EXEC.IF WAHR FALSCH )");
     30    [TestMethod]
     31    [TestProperty("Time", "Short")]
     32    [TestCategory("ExpressionTest")]
     33    [TestCategory("ExecExpressionTest")]
     34    public void TestIfTrue() {
     35      this.interpreter.BooleanStack.Push(true);
     36      this.interpreter.Interpret("( EXEC.IF WAHR FALSCH )");
    2837
    29             Assert.AreEqual("WAHR", interpreter.NameStack.Top);
    30             TestStackCounts(nameStack: 1);
    31         }
     38      Assert.AreEqual("WAHR", this.interpreter.NameStack.Top);
     39      this.TestStackCounts(nameStack: 1);
     40    }
    3241
    33         [TestMethod]
    34         [TestProperty("Time", "Short")]
    35         [TestCategory("ExpressionTest")]
    36         [TestCategory("ExecExpressionTest")]
    37         public void TestIfFalse()
    38         {
    39             interpreter.BooleanStack.Push(false);
    40             interpreter.Interpret("( EXEC.IF WAHR FALSCH )");
     42    [TestMethod]
     43    [TestProperty("Time", "Short")]
     44    [TestCategory("ExpressionTest")]
     45    [TestCategory("ExecExpressionTest")]
     46    public void TestIfFalse() {
     47      this.interpreter.BooleanStack.Push(false);
     48      this.interpreter.Interpret("( EXEC.IF WAHR FALSCH )");
    4149
    42             Assert.AreEqual("FALSCH", interpreter.NameStack.Top);
    43             TestStackCounts(nameStack: 1);
    44         }
     50      Assert.AreEqual("FALSCH", this.interpreter.NameStack.Top);
     51      this.TestStackCounts(nameStack: 1);
     52    }
    4553
    46         [TestMethod]
    47         [TestProperty("Time", "Short")]
    48         [TestCategory("ExpressionTest")]
    49         [TestCategory("ExecExpressionTest")]
    50         public void TestK()
    51         {
    52             var first = Parser.Parse("A");
    53             var second = Parser.Parse("B");
    54             var third = Parser.Parse("C");
     54    [TestMethod]
     55    [TestProperty("Time", "Short")]
     56    [TestCategory("ExpressionTest")]
     57    [TestCategory("ExecExpressionTest")]
     58    public void TestK() {
     59      var first = PushGPParser.Parse("A");
     60      var second = PushGPParser.Parse("B");
     61      var third = PushGPParser.Parse("C");
    5562
    56             interpreter.ExecStack.Push(third, second, first);
    57             Test(new ExecKExpression());
     63      this.interpreter.ExecStack.Push(third, second, first);
     64      this.Test(new ExecKExpression());
    5865
    59             Assert.AreEqual(first, interpreter.ExecStack.Top);
    60             Assert.AreEqual(third, interpreter.ExecStack.Bottom);
    61             TestStackCounts(execStack: 2);
    62         }
     66      Assert.AreEqual(first, this.interpreter.ExecStack.Top);
     67      Assert.AreEqual(third, this.interpreter.ExecStack.Bottom);
     68      this.TestStackCounts(2);
     69    }
    6370
    64         [TestMethod]
    65         [TestProperty("Time", "Short")]
    66         [TestCategory("ExpressionTest")]
    67         [TestCategory("ExecExpressionTest")]
    68         public void TestS()
    69         {
    70             var first = Parser.Parse("A");
    71             var second = Parser.Parse("B");
    72             var third = Parser.Parse("C");
    73             var result = Parser.Parse("( B C )");
     71    [TestMethod]
     72    [TestProperty("Time", "Short")]
     73    [TestCategory("ExpressionTest")]
     74    [TestCategory("ExecExpressionTest")]
     75    public void TestS() {
     76      var first = PushGPParser.Parse("A");
     77      var second = PushGPParser.Parse("B");
     78      var third = PushGPParser.Parse("C");
     79      var result = PushGPParser.Parse("( B C )");
    7480
    75             interpreter.ExecStack.Push(third, second, first);
    76             Test(new ExecSExpression());
     81      this.interpreter.ExecStack.Push(third, second, first);
     82      this.Test(new ExecSExpression());
    7783
    78             Assert.AreEqual(result, interpreter.ExecStack.ReverseElementAt(2));
    79             Assert.AreEqual(third, interpreter.ExecStack.ReverseElementAt(1));
    80             Assert.AreEqual(first, interpreter.ExecStack.Top);
    81             TestStackCounts(execStack: 3);
    82         }
     84      Assert.AreEqual(result, this.interpreter.ExecStack.ReverseElementAt(2));
     85      Assert.AreEqual(third, this.interpreter.ExecStack.ReverseElementAt(1));
     86      Assert.AreEqual(first, this.interpreter.ExecStack.Top);
     87      this.TestStackCounts(3);
     88    }
    8389
    84         [TestMethod]
    85         [TestProperty("Time", "Short")]
    86         [TestCategory("ExpressionTest")]
    87         [TestCategory("ExecExpressionTest")]
    88         public void TestY()
    89         {
    90             var first = Parser.Parse("A");
    91             var result = Parser.Parse("( EXEC.Y A )");
     90    [TestMethod]
     91    [TestProperty("Time", "Short")]
     92    [TestCategory("ExpressionTest")]
     93    [TestCategory("ExecExpressionTest")]
     94    public void TestY() {
     95      var first = PushGPParser.Parse("A");
     96      var result = PushGPParser.Parse("( EXEC.Y A )");
    9297
    93             interpreter.ExecStack.Push(first);
    94             Test(new ExecYExpression());
     98      this.interpreter.ExecStack.Push(first);
     99      this.Test(new ExecYExpression());
    95100
    96             Assert.AreEqual(first, interpreter.ExecStack.Top);
    97             Assert.AreEqual(result, interpreter.ExecStack.ReverseElementAt(1));
    98             TestStackCounts(execStack: 2);
    99         }
     101      Assert.AreEqual(first, this.interpreter.ExecStack.Top);
     102      Assert.AreEqual(result, this.interpreter.ExecStack.ReverseElementAt(1));
     103      this.TestStackCounts(2);
     104    }
    100105
    101         [TestMethod]
    102         [TestProperty("Time", "Short")]
    103         [TestCategory("ExpressionTest")]
    104         [TestCategory("ExecExpressionTest")]
    105         public void TestNestedDoRange()
    106         {
    107             interpreter.Interpret("( 0 2 EXEC.DO*RANGE ( 1 INTEGER.+ 0 3 EXEC.DO*RANGE ( 1 INTEGER.+ INTEGER.* ) INTEGER.+ )");
     106    [TestMethod]
     107    [TestProperty("Time", "Short")]
     108    [TestCategory("ExpressionTest")]
     109    [TestCategory("ExecExpressionTest")]
     110    public void TestNestedDoRange() {
     111      this.interpreter.Interpret(
     112        "( 0 2 EXEC.DO*RANGE ( 1 INTEGER.+ 0 3 EXEC.DO*RANGE ( 1 INTEGER.+ INTEGER.* ) INTEGER.+ )");
    108113
    109             Assert.AreEqual(144, interpreter.IntegerStack.Top);
    110             TestStackCounts(integerStack: 1);
    111         }
     114      Assert.AreEqual(144, this.interpreter.IntegerStack.Top);
     115      this.TestStackCounts(integerStack: 1);
     116    }
    112117
    113         [TestMethod]
    114         [TestProperty("Time", "Short")]
    115         [TestCategory("ExpressionTest")]
    116         [TestCategory("ExecExpressionTest")]
    117         public void TestNestedDoCount()
    118         {
    119             interpreter.Interpret("( 2 EXEC.DO*COUNT ( 1 INTEGER.+ 3 EXEC.DO*COUNT ( 1 INTEGER.+ INTEGER.* ) INTEGER.+ )");
     118    [TestMethod]
     119    [TestProperty("Time", "Short")]
     120    [TestCategory("ExpressionTest")]
     121    [TestCategory("ExecExpressionTest")]
     122    public void TestNestedDoCount() {
     123      this.interpreter.Interpret(
     124        "( 2 EXEC.DO*COUNT ( 1 INTEGER.+ 3 EXEC.DO*COUNT ( 1 INTEGER.+ INTEGER.* ) INTEGER.+ )");
    120125
    121             Assert.AreEqual(144, interpreter.IntegerStack.Top);
    122             TestStackCounts(integerStack: 1);
    123         }
     126      Assert.AreEqual(144, this.interpreter.IntegerStack.Top);
     127      this.TestStackCounts(integerStack: 1);
     128    }
    124129
    125         [TestMethod]
    126         [TestProperty("Time", "Short")]
    127         [TestCategory("ExpressionTest")]
    128         [TestCategory("ExecExpressionTest")]
    129         public void TestNestedDoTimes()
    130         {
    131             interpreter.Interpret("( 3 EXEC.DO*TIMES ( 2 3 EXEC.DO*TIMES ( 2 INTEGER.* ) INTEGER.+ )");
     130    [TestMethod]
     131    [TestProperty("Time", "Short")]
     132    [TestCategory("ExpressionTest")]
     133    [TestCategory("ExecExpressionTest")]
     134    public void TestNestedDoTimes() {
     135      this.interpreter.Interpret("( 3 EXEC.DO*TIMES ( 2 3 EXEC.DO*TIMES ( 2 INTEGER.* ) INTEGER.+ )");
    132136
    133             Assert.AreEqual(128, interpreter.IntegerStack.Top);
    134             TestStackCounts(integerStack: 1);
    135         }
     137      Assert.AreEqual(128, this.interpreter.IntegerStack.Top);
     138      this.TestStackCounts(integerStack: 1);
     139    }
    136140
    137         protected override Expression[] GetValues(int count)
    138         {
    139             var values = new Expression[count];
     141    protected override Expression[] GetValues(int count) {
     142      var values = new Expression[count];
    140143
    141             for (var i = 0; i < count; i++)
    142             {
    143                 values[i] = new CodeNoopExpression();
    144             }
     144      for (var i = 0; i < count; i++) values[i] = new CodeNoopExpression();
    145145
    146             return values;
    147         }
     146      return values;
     147    }
    148148
    149         protected override Expression[] Get2Different()
    150         {
    151             return new Expression[]
    152             {
    153                 new CodeNoopExpression(),
    154                 new CodeNullExpression()
    155             };
    156         }
     149    protected override Expression[] Get2Different() {
     150      return new Expression[] { new CodeNoopExpression(), new CodeNullExpression() };
     151    }
    157152
    158         protected override void CheckOtherStacksAreEmpty()
    159         {
    160             TestStackCounts(execStack: null);
    161         }
     153    protected override void CheckOtherStacksAreEmpty() {
     154      this.TestStackCounts(null);
    162155    }
     156  }
    163157}
Note: See TracChangeset for help on using the changeset viewer.