Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/FloatExpressionTests.cs

Last change on this file was 14908, checked in by pkimmesw, 8 years ago

#2665 Removed "this" qualifier

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