Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/IntegerExpressionTests.cs @ 14834

Last change on this file since 14834 was 14834, checked in by pkimmesw, 7 years ago

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

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