Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/IntegerExpressionTests.cs @ 16958

Last change on this file since 16958 was 15017, checked in by pkimmesw, 8 years ago

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

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