Free cookie consent management tool by TermsFeed Policy Generator

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