Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Tests/Interpreter/Expressions/IntegerExpressionTests.cs @ 17432

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

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

File size: 8.0 KB
RevLine 
[15771]1using HeuristicLab.Problems.ProgramSynthesis;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
[14727]3
[15771]4namespace HeuristicLab.Tests.Interpreter.Expressions {
[14727]5  [TestClass]
[14906]6  public class IntegerExpressionTests : CommonTests<long> {
[15771]7    protected override string TypeName {
8      get {
[14727]9        return "INTEGER";
10      }
11    }
12
[15771]13    protected override IPushStack<long> Stack {
14      get {
[14908]15        return interpreter.IntegerStack;
[14727]16      }
17    }
18
19    [TestMethod]
20    [TestProperty("Time", "Short")]
21    [TestCategory("ExpressionTest")]
22    [TestCategory("IntegerExpressionTest")]
[14906]23    public void TestAdd() {
[14908]24      interpreter.IntegerStack.Push(5, 5);
25      interpreter.Run(new IntegerAddExpression());
[14727]26
[14908]27      Assert.AreEqual(10, interpreter.IntegerStack.Top);
28      TestStackCounts(integerStack: 1);
[14727]29    }
30
31    [TestMethod]
32    [TestProperty("Time", "Short")]
33    [TestCategory("ExpressionTest")]
34    [TestCategory("IntegerExpressionTest")]
[14906]35    public void TestAddWithInsufficientArguments() {
[14908]36      TestWithInsufficientArguments("+", 1);
[14727]37    }
38
39    [TestMethod]
40    [TestProperty("Time", "Short")]
41    [TestCategory("ExpressionTest")]
42    [TestCategory("IntegerExpressionTest")]
[14906]43    public void TestSubtract() {
[14908]44      interpreter.IntegerStack.Push(10, 5);
45      interpreter.Run(new IntegerSubtractExpression());
[14727]46
[14908]47      Assert.AreEqual(5, interpreter.IntegerStack.Top);
[14727]48
[14908]49      TestStackCounts(integerStack: 1);
[14727]50    }
51
52    [TestMethod]
53    [TestProperty("Time", "Short")]
54    [TestCategory("ExpressionTest")]
55    [TestCategory("IntegerExpressionTest")]
[14906]56    public void TestSubtractWithInsufficientArguments() {
[14908]57      TestWithInsufficientArguments("-", 1);
[14727]58    }
59
60    [TestMethod]
61    [TestProperty("Time", "Short")]
62    [TestCategory("ExpressionTest")]
63    [TestCategory("IntegerExpressionTest")]
[14906]64    public void TestMultiply() {
[14908]65      interpreter.IntegerStack.Push(10, 5);
66      interpreter.Run(new IntegerMultiplyExpression());
[14727]67
[14908]68      Assert.AreEqual(50, interpreter.IntegerStack.Top);
[14727]69
[14908]70      TestStackCounts(integerStack: 1);
[14727]71    }
72
73    [TestMethod]
74    [TestProperty("Time", "Short")]
75    [TestCategory("ExpressionTest")]
76    [TestCategory("IntegerExpressionTest")]
[14906]77    public void TestMultiplyWithInsufficientArguments() {
[14908]78      TestWithInsufficientArguments("*", 1);
[14727]79    }
80
81    [TestMethod]
82    [TestProperty("Time", "Short")]
83    [TestCategory("ExpressionTest")]
84    [TestCategory("IntegerExpressionTest")]
[14906]85    public void TestDivide() {
[14908]86      interpreter.IntegerStack.Push(10, 5);
87      interpreter.Run(new IntegerDivideExpression());
[14727]88
[14908]89      Assert.AreEqual(2, interpreter.IntegerStack.Top);
[14727]90
[14908]91      TestStackCounts(integerStack: 1);
[14727]92    }
93
94    [TestMethod]
95    [TestProperty("Time", "Short")]
96    [TestCategory("ExpressionTest")]
97    [TestCategory("IntegerExpressionTest")]
[14906]98    public void TestDivideWithInsufficientArguments() {
[14908]99      TestWithInsufficientArguments("/", 1);
[14727]100    }
101
102    [TestMethod]
103    [TestProperty("Time", "Short")]
104    [TestCategory("ExpressionTest")]
105    [TestCategory("IntegerExpressionTest")]
[14906]106    public void TestModulo() {
[14908]107      interpreter.IntegerStack.Push(10, 5);
108      interpreter.Run(new IntegerModuloExpression());
[14727]109
[14908]110      Assert.AreEqual(0, interpreter.IntegerStack.Top);
[14727]111
[14908]112      TestStackCounts(integerStack: 1);
[14727]113    }
114
115    [TestMethod]
116    [TestProperty("Time", "Short")]
117    [TestCategory("ExpressionTest")]
118    [TestCategory("IntegerExpressionTest")]
[14906]119    public void TestModuloWithInsufficientArguments() {
[14908]120      TestWithInsufficientArguments("%", 1);
[14727]121    }
122
123    [TestMethod]
124    [TestProperty("Time", "Short")]
125    [TestCategory("ExpressionTest")]
126    [TestCategory("IntegerExpressionTest")]
[14906]127    public void TestMin() {
[14908]128      interpreter.IntegerStack.Push(10, 5);
129      interpreter.Run(new IntegerMinExpression());
[14727]130
[14908]131      Assert.AreEqual(5, interpreter.IntegerStack.Top);
[14727]132
[14908]133      TestStackCounts(integerStack: 1);
[14727]134    }
135
136    [TestMethod]
137    [TestProperty("Time", "Short")]
138    [TestCategory("ExpressionTest")]
139    [TestCategory("IntegerExpressionTest")]
[14906]140    public void TestMinWithInsufficientArguments() {
[14908]141      TestWithInsufficientArguments("MIN", 1);
[14727]142    }
143
144    [TestMethod]
145    [TestProperty("Time", "Short")]
146    [TestCategory("ExpressionTest")]
147    [TestCategory("IntegerExpressionTest")]
[14906]148    public void TestMax() {
[14908]149      interpreter.IntegerStack.Push(10, 5);
150      interpreter.Run(new IntegerMaxExpression());
[14727]151
[14908]152      Assert.AreEqual(10, interpreter.IntegerStack.Top);
[14727]153
[14908]154      TestStackCounts(integerStack: 1);
[14727]155    }
156
157    [TestMethod]
158    [TestProperty("Time", "Short")]
159    [TestCategory("ExpressionTest")]
160    [TestCategory("IntegerExpressionTest")]
[14906]161    public void TestMaxWithInsufficientArguments() {
[14908]162      TestWithInsufficientArguments("MAX", 1);
[14727]163    }
164
165    [TestMethod]
166    [TestProperty("Time", "Short")]
167    [TestCategory("ExpressionTest")]
168    [TestCategory("IntegerExpressionTest")]
[14906]169    public void TestSmallerThan() {
[14908]170      interpreter.IntegerStack.Push(10, 5);
171      interpreter.Run(new IntegerSmallerThanExpression());
[14727]172
[14908]173      Assert.AreEqual(false, interpreter.BooleanStack.Top);
[14727]174
[14908]175      TestStackCounts(booleanStack: 1);
[14727]176    }
177
178    [TestMethod]
179    [TestProperty("Time", "Short")]
180    [TestCategory("ExpressionTest")]
181    [TestCategory("IntegerExpressionTest")]
[14906]182    public void TestSmallerThanWithInsufficientArguments() {
[14908]183      TestWithInsufficientArguments("<", 1);
[14727]184    }
185
186    [TestMethod]
187    [TestProperty("Time", "Short")]
188    [TestCategory("ExpressionTest")]
189    [TestCategory("IntegerExpressionTest")]
[14906]190    public void TestGreaterThan() {
[14908]191      interpreter.IntegerStack.Push(10, 5);
192      interpreter.Run(new IntegerGreaterThanExpression());
[14727]193
[14908]194      Assert.AreEqual(true, interpreter.BooleanStack.Top);
[14727]195
[14908]196      TestStackCounts(booleanStack: 1);
[14727]197    }
198
199    [TestMethod]
200    [TestProperty("Time", "Short")]
201    [TestCategory("ExpressionTest")]
202    [TestCategory("IntegerExpressionTest")]
[14906]203    public void TestGreaterThanWithInsufficientArguments() {
[14908]204      TestWithInsufficientArguments(">", 1);
[14727]205    }
206
207    [TestMethod]
208    [TestProperty("Time", "Short")]
209    [TestCategory("ExpressionTest")]
210    [TestCategory("IntegerExpressionTest")]
[14906]211    public void TestFromBooleanTrue() {
[14908]212      interpreter.BooleanStack.Push(true);
213      interpreter.Run(new IntegerFromBooleanExpression());
[14727]214
[14908]215      Assert.AreEqual(1, interpreter.IntegerStack.Top);
[14727]216
[14908]217      TestStackCounts(integerStack: 1);
[14727]218    }
219
220    [TestMethod]
221    [TestProperty("Time", "Short")]
222    [TestCategory("ExpressionTest")]
223    [TestCategory("IntegerExpressionTest")]
[14906]224    public void TestFromBooleanWithInsufficientArguments() {
[14908]225      TestWithInsufficientArguments("FROMBOOLEAN");
[14727]226    }
227
228    [TestMethod]
229    [TestProperty("Time", "Short")]
230    [TestCategory("ExpressionTest")]
231    [TestCategory("IntegerExpressionTest")]
[14906]232    public void TestFromBooleanFalse() {
[14908]233      interpreter.BooleanStack.Push(false);
234      interpreter.Run(new IntegerFromBooleanExpression());
[14727]235
[14908]236      Assert.AreEqual(0, interpreter.IntegerStack.Top);
[14727]237
[14908]238      TestStackCounts(integerStack: 1);
[14727]239    }
240
241    [TestMethod]
242    [TestProperty("Time", "Short")]
243    [TestCategory("ExpressionTest")]
244    [TestCategory("IntegerExpressionTest")]
[14906]245    public void TestFromFloat() {
[14908]246      interpreter.FloatStack.Push(1.5);
247      interpreter.Run(new IntegerFromFloatExpression());
[14727]248
[14908]249      Assert.AreEqual(1, interpreter.IntegerStack.Top);
[14727]250
[14908]251      TestStackCounts(integerStack: 1);
[14727]252    }
253
254    [TestMethod]
255    [TestProperty("Time", "Short")]
256    [TestCategory("ExpressionTest")]
257    [TestCategory("IntegerExpressionTest")]
[14906]258    public void TestFromFloatWithInsufficientArguments() {
[14908]259      TestWithInsufficientArguments("FROMFLOAT");
[14727]260    }
261
[14906]262    protected override long[] GetValues(int count) {
[14727]263      var values = new long[count];
264
265      for (long i = 0; i < count; i++) values[i] = i;
266
267      return values;
268    }
269
[14906]270    protected override void CheckOtherStacksAreEmpty() {
[14908]271      TestStackCounts(integerStack: null);
[14727]272    }
273  }
274}
Note: See TracBrowser for help on using the repository browser.