Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

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