Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/FloatExpressionTests.cs @ 14906

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

#2665 Formatted solution using hl dev settings

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