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