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/BooleanExpressionTests.cs

    r14398 r14513  
    1 using HeuristicLab.Algorithms.PushGP.Expressions;
    2 using HeuristicLab.Algorithms.PushGP.Stack;
    3 using Microsoft.VisualStudio.TestTools.UnitTesting;
     1namespace HeuristicLab.Tests.Interpreter.Expressions
     2{
     3  using HeuristicLab.Algorithms.PushGP.Expressions;
     4  using HeuristicLab.Algorithms.PushGP.Stack;
    45
    5 namespace HeuristicLab.Tests.Interpreter.Expressions
    6 {
    7     [TestClass]
    8     public class BooleanExpressionTests : CommonTests<bool>
     6  using Microsoft.VisualStudio.TestTools.UnitTesting;
     7
     8  [TestClass]
     9  public class BooleanExpressionTests : CommonTests<bool>
     10  {
     11    protected override string TypeName
    912    {
    10         protected override string TypeName { get { return "BOOLEAN"; } }
    11         protected override IStack<bool> Stack { get { return interpreter.BooleanStack; } }
     13      get
     14      {
     15        return "BOOLEAN";
     16      }
     17    }
    1218
    13         [TestMethod]
    14         [TestProperty("Time", "Short")]
    15         [TestCategory("ExpressionTest")]
    16         [TestCategory("BooleanExpressionTest")]
    17         public void TestAnd()
    18         {
    19             interpreter.BooleanStack.Push(true, false);
    20             interpreter.Interpret(new BooleanAndExpression());
     19    protected override IStack<bool> Stack
     20    {
     21      get
     22      {
     23        return this.interpreter.BooleanStack;
     24      }
     25    }
    2126
    22             Assert.AreEqual(false, interpreter.BooleanStack.Top);
     27    [TestMethod]
     28    [TestProperty("Time", "Short")]
     29    [TestCategory("ExpressionTest")]
     30    [TestCategory("BooleanExpressionTest")]
     31    public void TestAnd()
     32    {
     33      this.interpreter.BooleanStack.Push(true, false);
     34      this.interpreter.Interpret(new BooleanAndExpression());
    2335
    24             TestStackCounts(booleanStack: 1);
    25         }
     36      Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
    2637
    27         [TestMethod]
    28         [TestProperty("Time", "Short")]
    29         [TestCategory("ExpressionTest")]
    30         [TestCategory("BooleanExpressionTest")]
    31         public void TestAndWithInsufficientArguments()
    32         {
    33             TestWithInsufficientArguments("AND", 1);
    34         }
     38      this.TestStackCounts(booleanStack: 1);
     39    }
    3540
    36         [TestMethod]
    37         [TestProperty("Time", "Short")]
    38         [TestCategory("ExpressionTest")]
    39         [TestCategory("BooleanExpressionTest")]
    40         public void TestOr()
    41         {
    42             interpreter.BooleanStack.Push(true, false);
    43             interpreter.Interpret(new BooleanOrExpression());
     41    [TestMethod]
     42    [TestProperty("Time", "Short")]
     43    [TestCategory("ExpressionTest")]
     44    [TestCategory("BooleanExpressionTest")]
     45    public void TestAndWithInsufficientArguments()
     46    {
     47      this.TestWithInsufficientArguments("AND", 1);
     48    }
    4449
    45             Assert.AreEqual(true, interpreter.BooleanStack.Top);
     50    [TestMethod]
     51    [TestProperty("Time", "Short")]
     52    [TestCategory("ExpressionTest")]
     53    [TestCategory("BooleanExpressionTest")]
     54    public void TestOr()
     55    {
     56      this.interpreter.BooleanStack.Push(true, false);
     57      this.interpreter.Interpret(new BooleanOrExpression());
    4658
    47             TestStackCounts(booleanStack: 1);
    48         }
     59      Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
    4960
    50         [TestMethod]
    51         [TestProperty("Time", "Short")]
    52         [TestCategory("ExpressionTest")]
    53         [TestCategory("BooleanExpressionTest")]
    54         public void TestOrWithInsufficientArguments()
    55         {
    56             TestWithInsufficientArguments("OR", 1);
    57         }
     61      this.TestStackCounts(booleanStack: 1);
     62    }
    5863
    59         [TestMethod]
    60         [TestProperty("Time", "Short")]
    61         [TestCategory("ExpressionTest")]
    62         [TestCategory("BooleanExpressionTest")]
    63         public void TestNot()
    64         {
    65             interpreter.BooleanStack.Push(true);
    66             interpreter.Interpret(new BooleanNotExpression());
     64    [TestMethod]
     65    [TestProperty("Time", "Short")]
     66    [TestCategory("ExpressionTest")]
     67    [TestCategory("BooleanExpressionTest")]
     68    public void TestOrWithInsufficientArguments()
     69    {
     70      this.TestWithInsufficientArguments("OR", 1);
     71    }
    6772
    68             Assert.AreEqual(false, interpreter.BooleanStack.Top);
     73    [TestMethod]
     74    [TestProperty("Time", "Short")]
     75    [TestCategory("ExpressionTest")]
     76    [TestCategory("BooleanExpressionTest")]
     77    public void TestNot()
     78    {
     79      this.interpreter.BooleanStack.Push(true);
     80      this.interpreter.Interpret(new BooleanNotExpression());
    6981
    70             TestStackCounts(booleanStack: 1);
    71         }
     82      Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
    7283
    73         [TestMethod]
    74         [TestProperty("Time", "Short")]
    75         [TestCategory("ExpressionTest")]
    76         [TestCategory("BooleanExpressionTest")]
    77         public void TestNotWithInsufficientArguments()
    78         {
    79             TestWithInsufficientArguments("NOT");
    80         }
     84      this.TestStackCounts(booleanStack: 1);
     85    }
    8186
    82         [TestMethod]
    83         [TestProperty("Time", "Short")]
    84         [TestCategory("ExpressionTest")]
    85         [TestCategory("BooleanExpressionTest")]
    86         public void TestFromFloat()
    87         {
    88             interpreter.FloatStack.Push(2.0);
    89             interpreter.Interpret(new BooleanFromFloatExpression());
     87    [TestMethod]
     88    [TestProperty("Time", "Short")]
     89    [TestCategory("ExpressionTest")]
     90    [TestCategory("BooleanExpressionTest")]
     91    public void TestNotWithInsufficientArguments()
     92    {
     93      this.TestWithInsufficientArguments("NOT");
     94    }
    9095
    91             Assert.AreEqual(true, interpreter.BooleanStack.Top);
     96    [TestMethod]
     97    [TestProperty("Time", "Short")]
     98    [TestCategory("ExpressionTest")]
     99    [TestCategory("BooleanExpressionTest")]
     100    public void TestFromFloat()
     101    {
     102      this.interpreter.FloatStack.Push(2.0);
     103      this.interpreter.Interpret(new BooleanFromFloatExpression());
    92104
    93             TestStackCounts(booleanStack: 1);
    94         }
     105      Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
    95106
    96         [TestMethod]
    97         [TestProperty("Time", "Short")]
    98         [TestCategory("ExpressionTest")]
    99         [TestCategory("BooleanExpressionTest")]
    100         public void TestFromFloatWithInsufficientArguments()
    101         {
    102             TestWithInsufficientArguments("FROMFLOAT");
    103         }
     107      this.TestStackCounts(booleanStack: 1);
     108    }
    104109
    105         [TestMethod]
    106         [TestProperty("Time", "Short")]
    107         [TestCategory("ExpressionTest")]
    108         [TestCategory("BooleanExpressionTest")]
    109         public void TestFromInteger()
    110         {
    111             interpreter.IntegerStack.Push(2);
    112             interpreter.Interpret(new BooleanFromIntegerExpression());
     110    [TestMethod]
     111    [TestProperty("Time", "Short")]
     112    [TestCategory("ExpressionTest")]
     113    [TestCategory("BooleanExpressionTest")]
     114    public void TestFromFloatWithInsufficientArguments()
     115    {
     116      this.TestWithInsufficientArguments("FROMFLOAT");
     117    }
    113118
    114             Assert.AreEqual(true, interpreter.BooleanStack.Top);
     119    [TestMethod]
     120    [TestProperty("Time", "Short")]
     121    [TestCategory("ExpressionTest")]
     122    [TestCategory("BooleanExpressionTest")]
     123    public void TestFromInteger()
     124    {
     125      this.interpreter.IntegerStack.Push(2);
     126      this.interpreter.Interpret(new BooleanFromIntegerExpression());
    115127
    116             TestStackCounts(booleanStack: 1);
    117         }
     128      Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
    118129
    119         [TestMethod]
    120         [TestProperty("Time", "Short")]
    121         [TestCategory("ExpressionTest")]
    122         [TestCategory("BooleanExpressionTest")]
    123         public void TestFromIntegerWithInsufficientArguments()
    124         {
    125             TestWithInsufficientArguments("FROMINTEGER");
    126         }
     130      this.TestStackCounts(booleanStack: 1);
     131    }
    127132
    128         protected override bool[] GetValues(int count)
    129         {
    130             var values = new bool[count];
     133    [TestMethod]
     134    [TestProperty("Time", "Short")]
     135    [TestCategory("ExpressionTest")]
     136    [TestCategory("BooleanExpressionTest")]
     137    public void TestFromIntegerWithInsufficientArguments()
     138    {
     139      this.TestWithInsufficientArguments("FROMINTEGER");
     140    }
    131141
    132             for (var i = 0; i < count; i++)
    133             {
    134                 values[i] = i % 2 == 0;
    135             }
     142    protected override bool[] GetValues(int count)
     143    {
     144      var values = new bool[count];
    136145
    137             return values;
    138         }
     146      for (var i = 0; i < count; i++) values[i] = i % 2 == 0;
    139147
    140         protected override void CheckOtherStacksAreEmpty()
    141         {
    142             TestStackCounts(booleanStack: null);
    143         }
     148      return values;
    144149    }
     150
     151    protected override void CheckOtherStacksAreEmpty()
     152    {
     153      this.TestStackCounts(booleanStack: null);
     154    }
     155  }
    145156}
Note: See TracChangeset for help on using the changeset viewer.