1 | namespace HeuristicLab.Tests.Interpreter.Expressions {
|
---|
2 | using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
|
---|
3 | using HeuristicLab.Problems.ProgramSynthesis.Push.Parser;
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
6 |
|
---|
7 |
|
---|
8 | [TestClass]
|
---|
9 | public class CodeExpressionTests : CommonTests<Expression> {
|
---|
10 | protected override string TypeName
|
---|
11 | {
|
---|
12 | get
|
---|
13 | {
|
---|
14 | return "CODE";
|
---|
15 | }
|
---|
16 | }
|
---|
17 |
|
---|
18 | protected override IPushStack<Expression> Stack
|
---|
19 | {
|
---|
20 | get
|
---|
21 | {
|
---|
22 | return this.interpreter.CodeStack;
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | [TestMethod]
|
---|
27 | [TestProperty("Time", "Short")]
|
---|
28 | [TestCategory("ExpressionTest")]
|
---|
29 | [TestCategory("CodeExpressionTest")]
|
---|
30 | public void TestAppendLists() {
|
---|
31 | var first = PushParser.Parse("( A )");
|
---|
32 | var second = PushParser.Parse("( B )");
|
---|
33 | var result = PushParser.Parse("( A B )");
|
---|
34 |
|
---|
35 | this.interpreter.CodeStack.Push(second, first);
|
---|
36 | this.interpreter.Run(new CodeAppendExpression());
|
---|
37 |
|
---|
38 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
39 | this.CheckOtherStacksAreEmpty();
|
---|
40 | }
|
---|
41 |
|
---|
42 | [TestMethod]
|
---|
43 | [TestProperty("Time", "Short")]
|
---|
44 | [TestCategory("ExpressionTest")]
|
---|
45 | [TestCategory("CodeExpressionTest")]
|
---|
46 | public void TestAppendListAndLiteral() {
|
---|
47 | var first = PushParser.Parse("( A )");
|
---|
48 | var second = PushParser.Parse("5");
|
---|
49 | var result = PushParser.Parse("( A 5 )");
|
---|
50 |
|
---|
51 | this.interpreter.CodeStack.Push(second, first);
|
---|
52 | this.interpreter.Run(new CodeAppendExpression());
|
---|
53 |
|
---|
54 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
55 | this.CheckOtherStacksAreEmpty();
|
---|
56 | }
|
---|
57 |
|
---|
58 | [TestMethod]
|
---|
59 | [TestProperty("Time", "Short")]
|
---|
60 | [TestCategory("ExpressionTest")]
|
---|
61 | [TestCategory("CodeExpressionTest")]
|
---|
62 | public void TestAppendLiterals() {
|
---|
63 | var first = PushParser.Parse("4");
|
---|
64 | var second = PushParser.Parse("5");
|
---|
65 | var result = PushParser.Parse("( 4 5 )");
|
---|
66 |
|
---|
67 | this.interpreter.CodeStack.Push(second, first);
|
---|
68 | this.interpreter.Run(new CodeAppendExpression());
|
---|
69 |
|
---|
70 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
71 | this.CheckOtherStacksAreEmpty();
|
---|
72 | }
|
---|
73 |
|
---|
74 | [TestMethod]
|
---|
75 | [TestProperty("Time", "Short")]
|
---|
76 | [TestCategory("ExpressionTest")]
|
---|
77 | [TestCategory("CodeExpressionTest")]
|
---|
78 | public void TestDuplicateList() {
|
---|
79 | var list = PushParser.Parse("( A B C )");
|
---|
80 | var result = PushParser.Parse("( A B C )");
|
---|
81 |
|
---|
82 | this.interpreter.CodeStack.Push(list);
|
---|
83 | this.interpreter.Run(new CodeDuplicateExpression());
|
---|
84 |
|
---|
85 | Assert.AreEqual(this.Stack.Count, 2);
|
---|
86 | Assert.AreEqual(this.Stack[0], list);
|
---|
87 | Assert.AreEqual(this.Stack[1], result);
|
---|
88 |
|
---|
89 | this.CheckOtherStacksAreEmpty();
|
---|
90 | }
|
---|
91 |
|
---|
92 | [TestMethod]
|
---|
93 | [TestProperty("Time", "Short")]
|
---|
94 | [TestCategory("ExpressionTest")]
|
---|
95 | [TestCategory("CodeExpressionTest")]
|
---|
96 | public void TestAtomList() {
|
---|
97 | var first = PushParser.Parse("( A )");
|
---|
98 |
|
---|
99 | this.interpreter.CodeStack.Push(first);
|
---|
100 | this.interpreter.Run(new CodeAtomExpression());
|
---|
101 |
|
---|
102 | Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
|
---|
103 | this.TestStackCounts(booleanStack: 1);
|
---|
104 | }
|
---|
105 |
|
---|
106 | [TestMethod]
|
---|
107 | [TestProperty("Time", "Short")]
|
---|
108 | [TestCategory("ExpressionTest")]
|
---|
109 | [TestCategory("CodeExpressionTest")]
|
---|
110 | public void TestAtomLiteral() {
|
---|
111 | var first = PushParser.Parse("5");
|
---|
112 |
|
---|
113 | this.interpreter.CodeStack.Push(first);
|
---|
114 | this.interpreter.Run(new CodeAtomExpression());
|
---|
115 |
|
---|
116 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
117 | this.TestStackCounts(booleanStack: 1);
|
---|
118 | }
|
---|
119 |
|
---|
120 | [TestMethod]
|
---|
121 | [TestProperty("Time", "Short")]
|
---|
122 | [TestCategory("ExpressionTest")]
|
---|
123 | [TestCategory("CodeExpressionTest")]
|
---|
124 | public void TestAtomSingleInstruction() {
|
---|
125 | var first = PushParser.Parse("INTEGER.+");
|
---|
126 |
|
---|
127 | this.interpreter.CodeStack.Push(first);
|
---|
128 | this.interpreter.Run(new CodeAtomExpression());
|
---|
129 |
|
---|
130 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
131 | this.TestStackCounts(booleanStack: 1);
|
---|
132 | }
|
---|
133 |
|
---|
134 | [TestMethod]
|
---|
135 | [TestProperty("Time", "Short")]
|
---|
136 | [TestCategory("ExpressionTest")]
|
---|
137 | [TestCategory("CodeExpressionTest")]
|
---|
138 | public void TestCarList() {
|
---|
139 | var first = PushParser.Parse("( A B C )");
|
---|
140 | var result = PushParser.Parse("A");
|
---|
141 |
|
---|
142 | this.interpreter.CodeStack.Push(first);
|
---|
143 | this.interpreter.Run(new CodeCarExpression());
|
---|
144 |
|
---|
145 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
146 | this.CheckOtherStacksAreEmpty();
|
---|
147 | }
|
---|
148 |
|
---|
149 | [TestMethod]
|
---|
150 | [TestProperty("Time", "Short")]
|
---|
151 | [TestCategory("ExpressionTest")]
|
---|
152 | [TestCategory("CodeExpressionTest")]
|
---|
153 | public void TestCarNoList() {
|
---|
154 | var first = PushParser.Parse("5");
|
---|
155 | var result = PushParser.Parse("5");
|
---|
156 |
|
---|
157 | this.interpreter.CodeStack.Push(first);
|
---|
158 | this.interpreter.Run(new CodeCarExpression());
|
---|
159 |
|
---|
160 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
161 | this.CheckOtherStacksAreEmpty();
|
---|
162 | }
|
---|
163 |
|
---|
164 | [TestMethod]
|
---|
165 | [TestProperty("Time", "Short")]
|
---|
166 | [TestCategory("ExpressionTest")]
|
---|
167 | [TestCategory("CodeExpressionTest")]
|
---|
168 | public void TestCdrList() {
|
---|
169 | var first = PushParser.Parse("( A B C )");
|
---|
170 | var result = PushParser.Parse("( B C )");
|
---|
171 |
|
---|
172 | this.interpreter.CodeStack.Push(first);
|
---|
173 | this.interpreter.Run(new CodeCdrExpression());
|
---|
174 |
|
---|
175 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
176 | this.CheckOtherStacksAreEmpty();
|
---|
177 | }
|
---|
178 |
|
---|
179 | [TestMethod]
|
---|
180 | [TestProperty("Time", "Short")]
|
---|
181 | [TestCategory("ExpressionTest")]
|
---|
182 | [TestCategory("CodeExpressionTest")]
|
---|
183 | public void TestCdrNoList() {
|
---|
184 | var first = PushParser.Parse("5");
|
---|
185 | var result = PushParser.Parse("( )");
|
---|
186 |
|
---|
187 | this.interpreter.CodeStack.Push(first);
|
---|
188 | this.interpreter.Run(new CodeCdrExpression());
|
---|
189 |
|
---|
190 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
191 | this.CheckOtherStacksAreEmpty();
|
---|
192 | }
|
---|
193 |
|
---|
194 | [TestMethod]
|
---|
195 | [TestProperty("Time", "Short")]
|
---|
196 | [TestCategory("ExpressionTest")]
|
---|
197 | [TestCategory("CodeExpressionTest")]
|
---|
198 | public void TestCons() {
|
---|
199 | var first = PushParser.Parse("( B C )");
|
---|
200 | var second = PushParser.Parse("A");
|
---|
201 | var result = PushParser.Parse("( A B C )");
|
---|
202 |
|
---|
203 | this.interpreter.CodeStack.Push(second, first);
|
---|
204 | this.interpreter.Run(new CodeConsExpression());
|
---|
205 |
|
---|
206 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
207 | this.CheckOtherStacksAreEmpty();
|
---|
208 | }
|
---|
209 |
|
---|
210 | [TestMethod]
|
---|
211 | [TestProperty("Time", "Short")]
|
---|
212 | [TestCategory("ExpressionTest")]
|
---|
213 | [TestCategory("CodeExpressionTest")]
|
---|
214 | public void TestContainsTrue() {
|
---|
215 | var first = PushParser.Parse("A");
|
---|
216 | var second = PushParser.Parse("( A B C )");
|
---|
217 |
|
---|
218 | this.interpreter.CodeStack.Push(second, first);
|
---|
219 | this.interpreter.Run(new CodeContainsExpression());
|
---|
220 |
|
---|
221 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
222 | this.TestStackCounts(booleanStack: 1);
|
---|
223 | }
|
---|
224 |
|
---|
225 | [TestMethod]
|
---|
226 | [TestProperty("Time", "Short")]
|
---|
227 | [TestCategory("ExpressionTest")]
|
---|
228 | [TestCategory("CodeExpressionTest")]
|
---|
229 | public void TestContainsFalse() {
|
---|
230 | var first = PushParser.Parse("D");
|
---|
231 | var second = PushParser.Parse("( A B C )");
|
---|
232 |
|
---|
233 | this.interpreter.CodeStack.Push(second, first);
|
---|
234 | this.interpreter.Run(new CodeContainsExpression());
|
---|
235 |
|
---|
236 | Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
|
---|
237 | this.TestStackCounts(booleanStack: 1);
|
---|
238 | }
|
---|
239 |
|
---|
240 | [TestMethod]
|
---|
241 | [TestProperty("Time", "Short")]
|
---|
242 | [TestCategory("ExpressionTest")]
|
---|
243 | [TestCategory("CodeExpressionTest")]
|
---|
244 | public void TestContainer() {
|
---|
245 | var first = PushParser.Parse("( A )");
|
---|
246 | var second = PushParser.Parse("( B ( C ( A ) ) ( D ( A ) ) )");
|
---|
247 | var result = PushParser.Parse("( C ( A ) )");
|
---|
248 |
|
---|
249 | this.interpreter.CodeStack.Push(second, first);
|
---|
250 | this.interpreter.Run(new CodeContainerExpression());
|
---|
251 |
|
---|
252 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
253 | this.CheckOtherStacksAreEmpty();
|
---|
254 | }
|
---|
255 |
|
---|
256 | [TestMethod]
|
---|
257 | [TestProperty("Time", "Short")]
|
---|
258 | [TestCategory("ExpressionTest")]
|
---|
259 | [TestCategory("CodeExpressionTest")]
|
---|
260 | public void TestDefinition() {
|
---|
261 | var code = PushParser.Parse("( A )");
|
---|
262 |
|
---|
263 | this.interpreter.CustomExpressions.Add("Test", code);
|
---|
264 | this.interpreter.NameStack.Push("Test");
|
---|
265 |
|
---|
266 | this.interpreter.Run(new CodeDefinitionExpression());
|
---|
267 |
|
---|
268 | Assert.AreEqual(code, this.interpreter.CodeStack.Top);
|
---|
269 | this.CheckOtherStacksAreEmpty();
|
---|
270 | }
|
---|
271 |
|
---|
272 | [TestMethod]
|
---|
273 | [TestProperty("Time", "Short")]
|
---|
274 | [TestCategory("ExpressionTest")]
|
---|
275 | [TestCategory("CodeExpressionTest")]
|
---|
276 | public void TestDefinitionWithoutMatchingName() {
|
---|
277 | var code = PushParser.Parse("( A )");
|
---|
278 | var program = new CodeDefinitionExpression();
|
---|
279 |
|
---|
280 | this.interpreter.CustomExpressions.Add("Test1", code);
|
---|
281 | this.interpreter.NameStack.Push("Test2");
|
---|
282 | this.interpreter.Run(program);
|
---|
283 |
|
---|
284 | this.TestStackCounts(nameStack: 1);
|
---|
285 | }
|
---|
286 |
|
---|
287 | [TestMethod]
|
---|
288 | [TestProperty("Time", "Short")]
|
---|
289 | [TestCategory("ExpressionTest")]
|
---|
290 | [TestCategory("CodeExpressionTest")]
|
---|
291 | public void TestDiscrepancy() {
|
---|
292 | var first = PushParser.Parse("( A B )");
|
---|
293 | var second = PushParser.Parse("( B C )");
|
---|
294 |
|
---|
295 | this.interpreter.CodeStack.Push(second, first);
|
---|
296 | this.interpreter.Run(new CodeDiscrepancyExpression());
|
---|
297 |
|
---|
298 | Assert.AreEqual(2, this.interpreter.IntegerStack.Top);
|
---|
299 | this.TestStackCounts(integerStack: 1);
|
---|
300 | }
|
---|
301 |
|
---|
302 | [TestMethod]
|
---|
303 | [TestProperty("Time", "Short")]
|
---|
304 | [TestCategory("ExpressionTest")]
|
---|
305 | [TestCategory("CodeExpressionTest")]
|
---|
306 | public void TestDiscrepancyAllEqual() {
|
---|
307 | var first = PushParser.Parse("( A B )");
|
---|
308 | var second = PushParser.Parse("( B A )");
|
---|
309 |
|
---|
310 | this.interpreter.CodeStack.Push(second, first);
|
---|
311 | this.interpreter.Run(new CodeDiscrepancyExpression());
|
---|
312 |
|
---|
313 | Assert.AreEqual(0, this.interpreter.IntegerStack.Top);
|
---|
314 | this.TestStackCounts(integerStack: 1);
|
---|
315 | }
|
---|
316 |
|
---|
317 | [TestMethod]
|
---|
318 | [TestProperty("Time", "Short")]
|
---|
319 | [TestCategory("ExpressionTest")]
|
---|
320 | [TestCategory("CodeExpressionTest")]
|
---|
321 | public void TestDiscrepancyComplex() {
|
---|
322 | var first = PushParser.Parse("( A A B C D A )");
|
---|
323 | var second = PushParser.Parse("( A A B D E )");
|
---|
324 |
|
---|
325 | this.interpreter.CodeStack.Push(second, first);
|
---|
326 | this.interpreter.Run(new CodeDiscrepancyExpression());
|
---|
327 |
|
---|
328 | Assert.AreEqual(3, this.interpreter.IntegerStack.Top);
|
---|
329 | this.TestStackCounts(integerStack: 1);
|
---|
330 | }
|
---|
331 |
|
---|
332 | [TestMethod]
|
---|
333 | [TestProperty("Time", "Short")]
|
---|
334 | [TestCategory("ExpressionTest")]
|
---|
335 | [TestCategory("CodeExpressionTest")]
|
---|
336 | public void TestDiscrepancWithLists() {
|
---|
337 | var first = PushParser.Parse("( ( A ) A ( B ) C D A )");
|
---|
338 | var second = PushParser.Parse("( A ( A ) B D E )");
|
---|
339 |
|
---|
340 | this.interpreter.CodeStack.Push(second, first);
|
---|
341 | this.interpreter.Run(new CodeDiscrepancyExpression());
|
---|
342 |
|
---|
343 | Assert.AreEqual(5, this.interpreter.IntegerStack.Top);
|
---|
344 | this.TestStackCounts(integerStack: 1);
|
---|
345 | }
|
---|
346 |
|
---|
347 | [TestMethod]
|
---|
348 | [TestProperty("Time", "Short")]
|
---|
349 | [TestCategory("ExpressionTest")]
|
---|
350 | [TestCategory("CodeExpressionTest")]
|
---|
351 | public void TestDo() {
|
---|
352 | var prog = PushParser.Parse("( 10 )");
|
---|
353 |
|
---|
354 | this.interpreter.CodeStack.Push(prog);
|
---|
355 | this.interpreter.Run(new CodeDoExpression());
|
---|
356 |
|
---|
357 | Assert.AreEqual(10, this.interpreter.IntegerStack.Top);
|
---|
358 | this.TestStackCounts(integerStack: 1);
|
---|
359 | }
|
---|
360 |
|
---|
361 | [TestMethod]
|
---|
362 | [TestProperty("Time", "Short")]
|
---|
363 | [TestCategory("ExpressionTest")]
|
---|
364 | [TestCategory("CodeExpressionTest")]
|
---|
365 | public void TestDoX() {
|
---|
366 | var prog = PushParser.Parse("( 10 )");
|
---|
367 |
|
---|
368 | this.interpreter.CodeStack.Push(prog);
|
---|
369 | this.interpreter.Run(new CodeDoXExpression());
|
---|
370 |
|
---|
371 | Assert.AreEqual(10, this.interpreter.IntegerStack.Top);
|
---|
372 | this.TestStackCounts(integerStack: 1);
|
---|
373 | }
|
---|
374 |
|
---|
375 | [TestMethod]
|
---|
376 | [TestProperty("Time", "Short")]
|
---|
377 | [TestCategory("ExpressionTest")]
|
---|
378 | [TestCategory("CodeExpressionTest")]
|
---|
379 | public void TestDoCount() {
|
---|
380 | var prog = PushParser.Parse("INTEGER.+");
|
---|
381 |
|
---|
382 | this.interpreter.IntegerStack.Push(3);
|
---|
383 | this.interpreter.CodeStack.Push(prog);
|
---|
384 | this.interpreter.Run(new CodeDoCountExpression());
|
---|
385 |
|
---|
386 | Assert.AreEqual(6, this.interpreter.IntegerStack.Top);
|
---|
387 | this.TestStackCounts(integerStack: 1);
|
---|
388 | }
|
---|
389 |
|
---|
390 | [TestMethod]
|
---|
391 | [TestProperty("Time", "Short")]
|
---|
392 | [TestCategory("ExpressionTest")]
|
---|
393 | [TestCategory("CodeExpressionTest")]
|
---|
394 | public void TestDoCountWithNegativeCounter() {
|
---|
395 | var prog = PushParser.Parse("INTEGER.+");
|
---|
396 |
|
---|
397 | this.interpreter.IntegerStack.Push(-1);
|
---|
398 | this.interpreter.CodeStack.Push(prog);
|
---|
399 | this.interpreter.Run(new CodeDoCountExpression());
|
---|
400 |
|
---|
401 | Assert.AreEqual(-1, this.interpreter.IntegerStack.Top);
|
---|
402 | this.TestStackCounts(codeStack: 1, integerStack: 1);
|
---|
403 | }
|
---|
404 |
|
---|
405 | [TestMethod]
|
---|
406 | [TestProperty("Time", "Short")]
|
---|
407 | [TestCategory("ExpressionTest")]
|
---|
408 | [TestCategory("CodeExpressionTest")]
|
---|
409 | public void TestDoRange() {
|
---|
410 | var prog = PushParser.Parse("INTEGER.+");
|
---|
411 |
|
---|
412 | this.interpreter.IntegerStack.Push(3, 5);
|
---|
413 | this.interpreter.CodeStack.Push(prog);
|
---|
414 | this.interpreter.Run(new CodeDoRangeExpression());
|
---|
415 |
|
---|
416 | Assert.AreEqual(12, this.interpreter.IntegerStack.Top);
|
---|
417 | this.TestStackCounts(integerStack: 1);
|
---|
418 | }
|
---|
419 |
|
---|
420 | [TestMethod]
|
---|
421 | [TestProperty("Time", "Short")]
|
---|
422 | [TestCategory("ExpressionTest")]
|
---|
423 | [TestCategory("CodeExpressionTest")]
|
---|
424 | public void TestDoRangeWithEqualIndecators() {
|
---|
425 | var prog = PushParser.Parse("INTEGER.+");
|
---|
426 |
|
---|
427 | this.interpreter.IntegerStack.Push(3, 3);
|
---|
428 | this.interpreter.CodeStack.Push(prog);
|
---|
429 | this.interpreter.Run(new CodeDoRangeExpression());
|
---|
430 |
|
---|
431 | Assert.AreEqual(3, this.interpreter.IntegerStack.Top);
|
---|
432 | this.TestStackCounts(codeStack: 1, integerStack: 2);
|
---|
433 | }
|
---|
434 |
|
---|
435 | [TestMethod]
|
---|
436 | [TestProperty("Time", "Short")]
|
---|
437 | [TestCategory("ExpressionTest")]
|
---|
438 | [TestCategory("CodeExpressionTest")]
|
---|
439 | public void TestDoRangeWithNegativeIndecators() {
|
---|
440 | var prog = PushParser.Parse("INTEGER.+");
|
---|
441 |
|
---|
442 | this.interpreter.IntegerStack.Push(-3, -5);
|
---|
443 | this.interpreter.CodeStack.Push(prog);
|
---|
444 | this.interpreter.Run(new CodeDoRangeExpression());
|
---|
445 |
|
---|
446 | Assert.AreEqual(-12, this.interpreter.IntegerStack.Top);
|
---|
447 | this.TestStackCounts(integerStack: 1);
|
---|
448 | }
|
---|
449 |
|
---|
450 | [TestMethod]
|
---|
451 | [TestProperty("Time", "Short")]
|
---|
452 | [TestCategory("ExpressionTest")]
|
---|
453 | [TestCategory("CodeExpressionTest")]
|
---|
454 | public void TestDoTimes() {
|
---|
455 | var prog = PushParser.Parse("( INTEGER.DUP INTEGER.+ )");
|
---|
456 |
|
---|
457 | this.interpreter.IntegerStack.Push(2, 3);
|
---|
458 | this.interpreter.CodeStack.Push(prog);
|
---|
459 | this.interpreter.Run(new CodeDoTimesExpression());
|
---|
460 |
|
---|
461 | Assert.AreEqual(32, this.interpreter.IntegerStack.Top);
|
---|
462 | this.TestStackCounts(integerStack: 1);
|
---|
463 | }
|
---|
464 |
|
---|
465 | [TestMethod]
|
---|
466 | [TestProperty("Time", "Short")]
|
---|
467 | [TestCategory("ExpressionTest")]
|
---|
468 | [TestCategory("CodeExpressionTest")]
|
---|
469 | public void TestDoTimesWithNegativeCounter() {
|
---|
470 | var prog = PushParser.Parse("( INTEGER.DUP INTEGER.+ )");
|
---|
471 |
|
---|
472 | this.interpreter.IntegerStack.Push(2, -3);
|
---|
473 | this.interpreter.CodeStack.Push(prog);
|
---|
474 | this.interpreter.Run(new CodeDoTimesExpression());
|
---|
475 |
|
---|
476 | Assert.AreEqual(-3, this.interpreter.IntegerStack.Top);
|
---|
477 | this.TestStackCounts(codeStack: 1, integerStack: 2);
|
---|
478 | }
|
---|
479 |
|
---|
480 | [TestMethod]
|
---|
481 | [TestProperty("Time", "Short")]
|
---|
482 | [TestCategory("ExpressionTest")]
|
---|
483 | [TestCategory("CodeExpressionTest")]
|
---|
484 | public void TestNestedDoRange() {
|
---|
485 | this.interpreter.Run(
|
---|
486 | "( 0 2 CODE.QUOTE ( 1 INTEGER.+ 0 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*RANGE INTEGER.+ ) CODE.DO*RANGE )");
|
---|
487 |
|
---|
488 | Assert.AreEqual(144, this.interpreter.IntegerStack.Top);
|
---|
489 | this.TestStackCounts(integerStack: 1);
|
---|
490 | }
|
---|
491 |
|
---|
492 | [TestMethod]
|
---|
493 | [TestProperty("Time", "Short")]
|
---|
494 | [TestCategory("ExpressionTest")]
|
---|
495 | [TestCategory("CodeExpressionTest")]
|
---|
496 | public void TestNestedDoCount() {
|
---|
497 | this.interpreter.Run(
|
---|
498 | "( 2 CODE.QUOTE ( 1 INTEGER.+ 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*COUNT INTEGER.+ ) CODE.DO*COUNT )");
|
---|
499 |
|
---|
500 | Assert.AreEqual(144, this.interpreter.IntegerStack.Top);
|
---|
501 | this.TestStackCounts(integerStack: 1);
|
---|
502 | }
|
---|
503 |
|
---|
504 | [TestMethod]
|
---|
505 | [TestProperty("Time", "Short")]
|
---|
506 | [TestCategory("ExpressionTest")]
|
---|
507 | [TestCategory("CodeExpressionTest")]
|
---|
508 | public void TestNestedDoTimes() {
|
---|
509 | this.interpreter.Run(
|
---|
510 | "( 3 CODE.QUOTE ( 2 3 CODE.QUOTE ( 2 INTEGER.* ) CODE.DO*TIMES INTEGER.+ ) CODE.DO*TIMES )");
|
---|
511 |
|
---|
512 | Assert.AreEqual(128, this.interpreter.IntegerStack.Top);
|
---|
513 | this.TestStackCounts(integerStack: 1);
|
---|
514 | }
|
---|
515 |
|
---|
516 | [TestMethod]
|
---|
517 | [TestProperty("Time", "Short")]
|
---|
518 | [TestCategory("ExpressionTest")]
|
---|
519 | [TestCategory("CodeExpressionTest")]
|
---|
520 | public void TestExtract() {
|
---|
521 | var prog = PushParser.Parse("( A ( B C ( D ) E ) F G H I J ( K ) L )");
|
---|
522 | var result = PushParser.Parse("( D )");
|
---|
523 |
|
---|
524 | this.interpreter.IntegerStack.Push(5);
|
---|
525 | this.interpreter.CodeStack.Push(prog);
|
---|
526 | this.interpreter.Run(new CodeExtractExpression());
|
---|
527 |
|
---|
528 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
529 | this.CheckOtherStacksAreEmpty();
|
---|
530 | }
|
---|
531 |
|
---|
532 | [TestMethod]
|
---|
533 | [TestProperty("Time", "Short")]
|
---|
534 | [TestCategory("ExpressionTest")]
|
---|
535 | [TestCategory("CodeExpressionTest")]
|
---|
536 | public void TestExtractInteger() {
|
---|
537 | var prog = PushParser.Parse("( A ( 5 C ( 4.2 ) INTEGER.+ ) FALSE )");
|
---|
538 | var result = PushParser.Parse("5");
|
---|
539 |
|
---|
540 | this.interpreter.IntegerStack.Push(3);
|
---|
541 | this.interpreter.CodeStack.Push(prog);
|
---|
542 | this.interpreter.Run(new CodeExtractExpression());
|
---|
543 |
|
---|
544 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
545 | this.CheckOtherStacksAreEmpty();
|
---|
546 | }
|
---|
547 |
|
---|
548 | [TestMethod]
|
---|
549 | [TestProperty("Time", "Short")]
|
---|
550 | [TestCategory("ExpressionTest")]
|
---|
551 | [TestCategory("CodeExpressionTest")]
|
---|
552 | public void TestExtractFloat() {
|
---|
553 | var prog = PushParser.Parse("( A ( 5 C ( 4.2 ) INTEGER.+ ) FALSE )");
|
---|
554 | var result = PushParser.Parse("4.2");
|
---|
555 |
|
---|
556 | this.interpreter.IntegerStack.Push(6);
|
---|
557 | this.interpreter.CodeStack.Push(prog);
|
---|
558 | this.interpreter.Run(new CodeExtractExpression());
|
---|
559 |
|
---|
560 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
561 | this.CheckOtherStacksAreEmpty();
|
---|
562 | }
|
---|
563 |
|
---|
564 | [TestMethod]
|
---|
565 | [TestProperty("Time", "Short")]
|
---|
566 | [TestCategory("ExpressionTest")]
|
---|
567 | [TestCategory("CodeExpressionTest")]
|
---|
568 | public void TestExtractBoolean() {
|
---|
569 | var prog = PushParser.Parse("( A ( 5 C ( 4.2 ) INTEGER.+ ) FALSE )");
|
---|
570 | var result = PushParser.Parse("FALSE");
|
---|
571 |
|
---|
572 | this.interpreter.IntegerStack.Push(8);
|
---|
573 | this.interpreter.CodeStack.Push(prog);
|
---|
574 | this.interpreter.Run(new CodeExtractExpression());
|
---|
575 |
|
---|
576 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
577 | this.CheckOtherStacksAreEmpty();
|
---|
578 | }
|
---|
579 |
|
---|
580 | [TestMethod]
|
---|
581 | [TestProperty("Time", "Short")]
|
---|
582 | [TestCategory("ExpressionTest")]
|
---|
583 | [TestCategory("CodeExpressionTest")]
|
---|
584 | public void TestExtractInstruction() {
|
---|
585 | var prog = PushParser.Parse("( A ( 5 C ( 4.2 ) INTEGER.+ ) FALSE )");
|
---|
586 | var result = PushParser.Parse("INTEGER.+");
|
---|
587 |
|
---|
588 | this.interpreter.IntegerStack.Push(7);
|
---|
589 | this.interpreter.CodeStack.Push(prog);
|
---|
590 | this.interpreter.Run(new CodeExtractExpression());
|
---|
591 |
|
---|
592 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
593 | this.CheckOtherStacksAreEmpty();
|
---|
594 | }
|
---|
595 |
|
---|
596 | [TestMethod]
|
---|
597 | [TestProperty("Time", "Short")]
|
---|
598 | [TestCategory("ExpressionTest")]
|
---|
599 | [TestCategory("CodeExpressionTest")]
|
---|
600 | public void TestFromBoolean() {
|
---|
601 | var result = PushParser.Parse("FALSE");
|
---|
602 | this.interpreter.BooleanStack.Push(false);
|
---|
603 | this.interpreter.Run(new CodeFromBooleanExpression());
|
---|
604 |
|
---|
605 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
606 | this.CheckOtherStacksAreEmpty();
|
---|
607 | }
|
---|
608 |
|
---|
609 | [TestMethod]
|
---|
610 | [TestProperty("Time", "Short")]
|
---|
611 | [TestCategory("ExpressionTest")]
|
---|
612 | [TestCategory("CodeExpressionTest")]
|
---|
613 | public void TestFromFloat() {
|
---|
614 | var result = PushParser.Parse("4.1");
|
---|
615 | this.interpreter.FloatStack.Push(4.1);
|
---|
616 | this.interpreter.Run(new CodeFromFloatExpression());
|
---|
617 |
|
---|
618 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
619 | this.CheckOtherStacksAreEmpty();
|
---|
620 | }
|
---|
621 |
|
---|
622 | [TestMethod]
|
---|
623 | [TestProperty("Time", "Short")]
|
---|
624 | [TestCategory("ExpressionTest")]
|
---|
625 | [TestCategory("CodeExpressionTest")]
|
---|
626 | public void TestFromInteger() {
|
---|
627 | var result = PushParser.Parse("4");
|
---|
628 | this.interpreter.IntegerStack.Push(4);
|
---|
629 | this.interpreter.Run(new CodeFromIntegerExpression());
|
---|
630 |
|
---|
631 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
632 | this.CheckOtherStacksAreEmpty();
|
---|
633 | }
|
---|
634 |
|
---|
635 | [TestMethod]
|
---|
636 | [TestProperty("Time", "Short")]
|
---|
637 | [TestCategory("ExpressionTest")]
|
---|
638 | [TestCategory("CodeExpressionTest")]
|
---|
639 | public void TestFromName() {
|
---|
640 | var result = PushParser.Parse("A");
|
---|
641 | this.interpreter.NameStack.Push("A");
|
---|
642 | this.interpreter.Run(new CodeFromNameExpression());
|
---|
643 |
|
---|
644 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
645 | this.CheckOtherStacksAreEmpty();
|
---|
646 | }
|
---|
647 |
|
---|
648 | [TestMethod]
|
---|
649 | [TestProperty("Time", "Short")]
|
---|
650 | [TestCategory("ExpressionTest")]
|
---|
651 | [TestCategory("CodeExpressionTest")]
|
---|
652 | public void TestIfTrue() {
|
---|
653 | var first = PushParser.Parse("FALSCH");
|
---|
654 | var second = PushParser.Parse("WAHR");
|
---|
655 |
|
---|
656 | this.interpreter.BooleanStack.Push(true);
|
---|
657 | this.interpreter.CodeStack.Push(second, first);
|
---|
658 | this.interpreter.Run(new CodeIfExpression());
|
---|
659 |
|
---|
660 | Assert.AreEqual("WAHR", this.interpreter.NameStack.Top);
|
---|
661 | this.TestStackCounts(nameStack: 1);
|
---|
662 | }
|
---|
663 |
|
---|
664 | [TestMethod]
|
---|
665 | [TestProperty("Time", "Short")]
|
---|
666 | [TestCategory("ExpressionTest")]
|
---|
667 | [TestCategory("CodeExpressionTest")]
|
---|
668 | public void TestIfFalse() {
|
---|
669 | var first = PushParser.Parse("FALSCH");
|
---|
670 | var second = PushParser.Parse("WAHR");
|
---|
671 |
|
---|
672 | this.interpreter.BooleanStack.Push(false);
|
---|
673 | this.interpreter.CodeStack.Push(second, first);
|
---|
674 | this.interpreter.Run(new CodeIfExpression());
|
---|
675 |
|
---|
676 | Assert.AreEqual("FALSCH", this.interpreter.NameStack.Top);
|
---|
677 | this.TestStackCounts(nameStack: 1);
|
---|
678 | }
|
---|
679 |
|
---|
680 | [TestMethod]
|
---|
681 | [TestProperty("Time", "Short")]
|
---|
682 | [TestCategory("ExpressionTest")]
|
---|
683 | [TestCategory("CodeExpressionTest")]
|
---|
684 | public void TestInsert() {
|
---|
685 | var first = PushParser.Parse("( A ( B ) C D )");
|
---|
686 | var second = PushParser.Parse("( E )");
|
---|
687 | var result = PushParser.Parse("( A ( B ) ( E ) D )");
|
---|
688 |
|
---|
689 | this.interpreter.IntegerStack.Push(2);
|
---|
690 | this.interpreter.CodeStack.Push(second, first);
|
---|
691 | this.interpreter.Run(new CodeInsertExpression());
|
---|
692 |
|
---|
693 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
694 | this.CheckOtherStacksAreEmpty();
|
---|
695 | }
|
---|
696 |
|
---|
697 | [TestMethod]
|
---|
698 | [TestProperty("Time", "Short")]
|
---|
699 | [TestCategory("ExpressionTest")]
|
---|
700 | [TestCategory("CodeExpressionTest")]
|
---|
701 | public void TestInsertWithNegativeN() {
|
---|
702 | var first = PushParser.Parse("( A ( B ) C D )");
|
---|
703 | var second = PushParser.Parse("( E )");
|
---|
704 | var result = PushParser.Parse("( A ( B ) ( E ) D )");
|
---|
705 |
|
---|
706 | this.interpreter.IntegerStack.Push(-2);
|
---|
707 | this.interpreter.CodeStack.Push(second, first);
|
---|
708 | this.interpreter.Run(new CodeInsertExpression());
|
---|
709 |
|
---|
710 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
711 | this.CheckOtherStacksAreEmpty();
|
---|
712 | }
|
---|
713 |
|
---|
714 | [TestMethod]
|
---|
715 | [TestProperty("Time", "Short")]
|
---|
716 | [TestCategory("ExpressionTest")]
|
---|
717 | [TestCategory("CodeExpressionTest")]
|
---|
718 | public void TestInsertWithTooBigN() {
|
---|
719 | var first = PushParser.Parse("( A ( B ) C D )");
|
---|
720 | var second = PushParser.Parse("( E )");
|
---|
721 | var result = PushParser.Parse("( A ( B ) ( E ) D )");
|
---|
722 |
|
---|
723 | this.interpreter.IntegerStack.Push(10);
|
---|
724 | this.interpreter.CodeStack.Push(second, first);
|
---|
725 | this.interpreter.Run(new CodeInsertExpression());
|
---|
726 |
|
---|
727 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
728 | this.CheckOtherStacksAreEmpty();
|
---|
729 | }
|
---|
730 |
|
---|
731 | [TestMethod]
|
---|
732 | [TestProperty("Time", "Short")]
|
---|
733 | [TestCategory("ExpressionTest")]
|
---|
734 | [TestCategory("CodeExpressionTest")]
|
---|
735 | public void TestList() {
|
---|
736 | var first = PushParser.Parse("A");
|
---|
737 | var second = PushParser.Parse("( B )");
|
---|
738 | var result = PushParser.Parse("( A ( B ) )");
|
---|
739 |
|
---|
740 | this.interpreter.CodeStack.Push(second, first);
|
---|
741 | this.interpreter.Run(new CodeListExpression());
|
---|
742 |
|
---|
743 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
744 | this.CheckOtherStacksAreEmpty();
|
---|
745 | }
|
---|
746 |
|
---|
747 | [TestMethod]
|
---|
748 | [TestProperty("Time", "Short")]
|
---|
749 | [TestCategory("ExpressionTest")]
|
---|
750 | [TestCategory("CodeExpressionTest")]
|
---|
751 | public void TestMemberTrue() {
|
---|
752 | var first = PushParser.Parse("( A B ( B ) C ");
|
---|
753 | var second = PushParser.Parse("( B )");
|
---|
754 |
|
---|
755 | this.interpreter.CodeStack.Push(second, first);
|
---|
756 | this.interpreter.Run(new CodeMemberExpression());
|
---|
757 |
|
---|
758 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
759 | this.TestStackCounts(booleanStack: 1);
|
---|
760 | }
|
---|
761 |
|
---|
762 | [TestMethod]
|
---|
763 | [TestProperty("Time", "Short")]
|
---|
764 | [TestCategory("ExpressionTest")]
|
---|
765 | [TestCategory("CodeExpressionTest")]
|
---|
766 | public void TestMemberFalse() {
|
---|
767 | var first = PushParser.Parse("( A B C ");
|
---|
768 | var second = PushParser.Parse("( B )");
|
---|
769 |
|
---|
770 | this.interpreter.CodeStack.Push(second, first);
|
---|
771 | this.interpreter.Run(new CodeMemberExpression());
|
---|
772 |
|
---|
773 | Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
|
---|
774 | this.TestStackCounts(booleanStack: 1);
|
---|
775 | }
|
---|
776 |
|
---|
777 | [TestMethod]
|
---|
778 | [TestProperty("Time", "Short")]
|
---|
779 | [TestCategory("ExpressionTest")]
|
---|
780 | [TestCategory("CodeExpressionTest")]
|
---|
781 | public void TestMemberIfNoList() {
|
---|
782 | var first = PushParser.Parse("B");
|
---|
783 | var second = PushParser.Parse("B");
|
---|
784 |
|
---|
785 | this.interpreter.CodeStack.Push(second, first);
|
---|
786 | this.interpreter.Run(new CodeMemberExpression());
|
---|
787 |
|
---|
788 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
789 | this.TestStackCounts(booleanStack: 1);
|
---|
790 | }
|
---|
791 |
|
---|
792 | [TestMethod]
|
---|
793 | [TestProperty("Time", "Short")]
|
---|
794 | [TestCategory("ExpressionTest")]
|
---|
795 | [TestCategory("CodeExpressionTest")]
|
---|
796 | public void TestNoop() {
|
---|
797 | this.interpreter.Run(new CodeNoopExpression());
|
---|
798 |
|
---|
799 | this.CheckOtherStacksAreEmpty();
|
---|
800 | }
|
---|
801 |
|
---|
802 | [TestMethod]
|
---|
803 | [TestProperty("Time", "Short")]
|
---|
804 | [TestCategory("ExpressionTest")]
|
---|
805 | [TestCategory("CodeExpressionTest")]
|
---|
806 | public void TestNthIfNoList() {
|
---|
807 | var prog = PushParser.Parse("A");
|
---|
808 | var result = PushParser.Parse("A");
|
---|
809 |
|
---|
810 | this.interpreter.IntegerStack.Push(3);
|
---|
811 | this.interpreter.CodeStack.Push(prog);
|
---|
812 | this.interpreter.Run(new CodeNthExpression());
|
---|
813 |
|
---|
814 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
815 | this.CheckOtherStacksAreEmpty();
|
---|
816 | }
|
---|
817 |
|
---|
818 | [TestMethod]
|
---|
819 | [TestProperty("Time", "Short")]
|
---|
820 | [TestCategory("ExpressionTest")]
|
---|
821 | [TestCategory("CodeExpressionTest")]
|
---|
822 | public void TestNthIfEmpty() {
|
---|
823 | var prog = PushParser.Parse("( )");
|
---|
824 | var result = PushParser.Parse("( )");
|
---|
825 |
|
---|
826 | this.interpreter.IntegerStack.Push(3);
|
---|
827 | this.interpreter.CodeStack.Push(prog);
|
---|
828 | this.interpreter.Run(new CodeNthExpression());
|
---|
829 |
|
---|
830 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
831 | this.CheckOtherStacksAreEmpty();
|
---|
832 | }
|
---|
833 |
|
---|
834 | [TestMethod]
|
---|
835 | [TestProperty("Time", "Short")]
|
---|
836 | [TestCategory("ExpressionTest")]
|
---|
837 | [TestCategory("CodeExpressionTest")]
|
---|
838 | public void TestNth() {
|
---|
839 | var prog = PushParser.Parse("( A B C D E )");
|
---|
840 | var result = PushParser.Parse("D");
|
---|
841 |
|
---|
842 | this.interpreter.IntegerStack.Push(3);
|
---|
843 | this.interpreter.CodeStack.Push(prog);
|
---|
844 | this.interpreter.Run(new CodeNthExpression());
|
---|
845 |
|
---|
846 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
847 | this.CheckOtherStacksAreEmpty();
|
---|
848 | }
|
---|
849 |
|
---|
850 | [TestMethod]
|
---|
851 | [TestProperty("Time", "Short")]
|
---|
852 | [TestCategory("ExpressionTest")]
|
---|
853 | [TestCategory("CodeExpressionTest")]
|
---|
854 | public void TestNthWithTooBigN() {
|
---|
855 | var prog = PushParser.Parse("( A B C D E )");
|
---|
856 | var result = PushParser.Parse("D");
|
---|
857 |
|
---|
858 | this.interpreter.IntegerStack.Push(13);
|
---|
859 | this.interpreter.CodeStack.Push(prog);
|
---|
860 | this.interpreter.Run(new CodeNthExpression());
|
---|
861 |
|
---|
862 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
863 | this.CheckOtherStacksAreEmpty();
|
---|
864 | }
|
---|
865 |
|
---|
866 | [TestMethod]
|
---|
867 | [TestProperty("Time", "Short")]
|
---|
868 | [TestCategory("ExpressionTest")]
|
---|
869 | [TestCategory("CodeExpressionTest")]
|
---|
870 | public void TestNthWithNegativeN() {
|
---|
871 | var prog = PushParser.Parse("( A B C D E )");
|
---|
872 | var result = PushParser.Parse("D");
|
---|
873 |
|
---|
874 | this.interpreter.IntegerStack.Push(-3);
|
---|
875 | this.interpreter.CodeStack.Push(prog);
|
---|
876 | this.interpreter.Run(new CodeNthExpression());
|
---|
877 |
|
---|
878 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
879 | this.CheckOtherStacksAreEmpty();
|
---|
880 | }
|
---|
881 |
|
---|
882 | [TestMethod]
|
---|
883 | [TestProperty("Time", "Short")]
|
---|
884 | [TestCategory("ExpressionTest")]
|
---|
885 | [TestCategory("CodeExpressionTest")]
|
---|
886 | public void TestNthCdr() {
|
---|
887 | var prog = PushParser.Parse("( A B C D E )");
|
---|
888 | var result = PushParser.Parse("D");
|
---|
889 |
|
---|
890 | this.interpreter.IntegerStack.Push(2);
|
---|
891 | this.interpreter.CodeStack.Push(prog);
|
---|
892 | this.interpreter.Run(new CodeNthCdrExpression());
|
---|
893 |
|
---|
894 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
895 | this.CheckOtherStacksAreEmpty();
|
---|
896 | }
|
---|
897 |
|
---|
898 | [TestMethod]
|
---|
899 | [TestProperty("Time", "Short")]
|
---|
900 | [TestCategory("ExpressionTest")]
|
---|
901 | [TestCategory("CodeExpressionTest")]
|
---|
902 | public void TestNthCdrWithTooBigN() {
|
---|
903 | var prog = PushParser.Parse("( A B C D E )");
|
---|
904 | var result = PushParser.Parse("D");
|
---|
905 |
|
---|
906 | this.interpreter.IntegerStack.Push(10);
|
---|
907 | this.interpreter.CodeStack.Push(prog);
|
---|
908 | this.interpreter.Run(new CodeNthCdrExpression());
|
---|
909 |
|
---|
910 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
911 | this.CheckOtherStacksAreEmpty();
|
---|
912 | }
|
---|
913 |
|
---|
914 | [TestMethod]
|
---|
915 | [TestProperty("Time", "Short")]
|
---|
916 | [TestCategory("ExpressionTest")]
|
---|
917 | [TestCategory("CodeExpressionTest")]
|
---|
918 | public void TestNthCdrWithNegativeN() {
|
---|
919 | var prog = PushParser.Parse("( A B C D E )");
|
---|
920 | var result = PushParser.Parse("D");
|
---|
921 |
|
---|
922 | this.interpreter.IntegerStack.Push(-2);
|
---|
923 | this.interpreter.CodeStack.Push(prog);
|
---|
924 | this.interpreter.Run(new CodeNthCdrExpression());
|
---|
925 |
|
---|
926 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
927 | this.CheckOtherStacksAreEmpty();
|
---|
928 | }
|
---|
929 |
|
---|
930 | [TestMethod]
|
---|
931 | [TestProperty("Time", "Short")]
|
---|
932 | [TestCategory("ExpressionTest")]
|
---|
933 | [TestCategory("CodeExpressionTest")]
|
---|
934 | public void TestNthCdrIfEmpty() {
|
---|
935 | var prog = PushParser.Parse("( )");
|
---|
936 | var result = PushParser.Parse("( )");
|
---|
937 |
|
---|
938 | this.interpreter.IntegerStack.Push(3);
|
---|
939 | this.interpreter.CodeStack.Push(prog);
|
---|
940 | this.interpreter.Run(new CodeNthCdrExpression());
|
---|
941 |
|
---|
942 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
943 | this.CheckOtherStacksAreEmpty();
|
---|
944 | }
|
---|
945 |
|
---|
946 | [TestMethod]
|
---|
947 | [TestProperty("Time", "Short")]
|
---|
948 | [TestCategory("ExpressionTest")]
|
---|
949 | [TestCategory("CodeExpressionTest")]
|
---|
950 | public void TestNthCdrIfNoList() {
|
---|
951 | var prog = PushParser.Parse("A");
|
---|
952 | var result = PushParser.Parse("A");
|
---|
953 |
|
---|
954 | this.interpreter.IntegerStack.Push(3);
|
---|
955 | this.interpreter.CodeStack.Push(prog);
|
---|
956 | this.interpreter.Run(new CodeNthCdrExpression());
|
---|
957 |
|
---|
958 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
959 | this.CheckOtherStacksAreEmpty();
|
---|
960 | }
|
---|
961 |
|
---|
962 | [TestMethod]
|
---|
963 | [TestProperty("Time", "Short")]
|
---|
964 | [TestCategory("ExpressionTest")]
|
---|
965 | [TestCategory("CodeExpressionTest")]
|
---|
966 | public void TestNullTrue() {
|
---|
967 | var prog = PushParser.Parse("( )");
|
---|
968 |
|
---|
969 | this.interpreter.CodeStack.Push(prog);
|
---|
970 | this.interpreter.Run(new CodeNullExpression());
|
---|
971 |
|
---|
972 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
973 | this.TestStackCounts(booleanStack: 1);
|
---|
974 | }
|
---|
975 |
|
---|
976 | [TestMethod]
|
---|
977 | [TestProperty("Time", "Short")]
|
---|
978 | [TestCategory("ExpressionTest")]
|
---|
979 | [TestCategory("CodeExpressionTest")]
|
---|
980 | public void TestNullFalse() {
|
---|
981 | var prog = PushParser.Parse("A");
|
---|
982 |
|
---|
983 | this.interpreter.CodeStack.Push(prog);
|
---|
984 | this.interpreter.Run(new CodeNullExpression());
|
---|
985 |
|
---|
986 | Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
|
---|
987 | this.TestStackCounts(booleanStack: 1);
|
---|
988 | }
|
---|
989 |
|
---|
990 | [TestMethod]
|
---|
991 | [TestProperty("Time", "Short")]
|
---|
992 | [TestCategory("ExpressionTest")]
|
---|
993 | [TestCategory("CodeExpressionTest")]
|
---|
994 | public void TestPosition() {
|
---|
995 | var first = PushParser.Parse("( A B C D )");
|
---|
996 | var second = PushParser.Parse("C");
|
---|
997 |
|
---|
998 | this.interpreter.CodeStack.Push(second, first);
|
---|
999 | this.interpreter.Run(new CodePositionExpression());
|
---|
1000 |
|
---|
1001 | Assert.AreEqual(2, this.interpreter.IntegerStack.Top);
|
---|
1002 | this.TestStackCounts(integerStack: 1);
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | [TestMethod]
|
---|
1006 | [TestProperty("Time", "Short")]
|
---|
1007 | [TestCategory("ExpressionTest")]
|
---|
1008 | [TestCategory("CodeExpressionTest")]
|
---|
1009 | public void TestQuote() {
|
---|
1010 | var result = PushParser.Parse("A");
|
---|
1011 |
|
---|
1012 | this.interpreter.Run("( CODE.QUOTE A )");
|
---|
1013 |
|
---|
1014 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
1015 | this.CheckOtherStacksAreEmpty();
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | [TestMethod]
|
---|
1019 | [TestProperty("Time", "Short")]
|
---|
1020 | [TestCategory("ExpressionTest")]
|
---|
1021 | [TestCategory("CodeExpressionTest")]
|
---|
1022 | public void TestSize() {
|
---|
1023 | var prog = PushParser.Parse("( A ( B ( C ) ) ( D ) INTEGER.+ )");
|
---|
1024 |
|
---|
1025 | this.interpreter.CodeStack.Push(prog);
|
---|
1026 | this.interpreter.Run(new CodeSizeExpression());
|
---|
1027 |
|
---|
1028 | Assert.AreEqual(4, this.interpreter.IntegerStack.Top);
|
---|
1029 | this.TestStackCounts(integerStack: 1);
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | [TestMethod]
|
---|
1033 | [TestProperty("Time", "Short")]
|
---|
1034 | [TestCategory("ExpressionTest")]
|
---|
1035 | [TestCategory("CodeExpressionTest")]
|
---|
1036 | public void TestSubstitude() {
|
---|
1037 | var first = PushParser.Parse("( A B C D A B C D )");
|
---|
1038 | var second = PushParser.Parse("E");
|
---|
1039 | var third = PushParser.Parse("A");
|
---|
1040 | var result = PushParser.Parse("( E B C D E B C D )");
|
---|
1041 |
|
---|
1042 | this.interpreter.CodeStack.Push(third, second, first);
|
---|
1043 | this.interpreter.Run(new CodeSubstitutionExpression());
|
---|
1044 |
|
---|
1045 | Assert.AreEqual(result, this.interpreter.CodeStack.Top);
|
---|
1046 | this.CheckOtherStacksAreEmpty();
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | protected override Expression[] GetValues(int count) {
|
---|
1050 | var values = new Expression[count];
|
---|
1051 |
|
---|
1052 | for (var i = 0; i < count; i++) values[i] = new CodeNoopExpression();
|
---|
1053 |
|
---|
1054 | return values;
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | protected override Expression[] Get2Different() {
|
---|
1058 | return new Expression[] { new CodeNoopExpression(), new CodeNullExpression() };
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | protected override void CheckOtherStacksAreEmpty() {
|
---|
1062 | this.TestStackCounts(codeStack: null);
|
---|
1063 | }
|
---|
1064 | }
|
---|
1065 | } |
---|