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 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 | interpreter.CodeStack.Push(second, first);
|
---|
36 | interpreter.Run(new CodeAppendExpression());
|
---|
37 |
|
---|
38 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
39 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
52 | interpreter.Run(new CodeAppendExpression());
|
---|
53 |
|
---|
54 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
55 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
68 | interpreter.Run(new CodeAppendExpression());
|
---|
69 |
|
---|
70 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
71 | 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 | interpreter.CodeStack.Push(list);
|
---|
83 | interpreter.Run(new CodeDuplicateExpression());
|
---|
84 |
|
---|
85 | Assert.AreEqual(Stack.Count, 2);
|
---|
86 | Assert.AreEqual(Stack[0], list);
|
---|
87 | Assert.AreEqual(Stack[1], result);
|
---|
88 |
|
---|
89 | 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 | interpreter.CodeStack.Push(first);
|
---|
100 | interpreter.Run(new CodeAtomExpression());
|
---|
101 |
|
---|
102 | Assert.AreEqual(false, interpreter.BooleanStack.Top);
|
---|
103 | 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 | interpreter.CodeStack.Push(first);
|
---|
114 | interpreter.Run(new CodeAtomExpression());
|
---|
115 |
|
---|
116 | Assert.AreEqual(true, interpreter.BooleanStack.Top);
|
---|
117 | 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 | interpreter.CodeStack.Push(first);
|
---|
128 | interpreter.Run(new CodeAtomExpression());
|
---|
129 |
|
---|
130 | Assert.AreEqual(true, interpreter.BooleanStack.Top);
|
---|
131 | 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 | interpreter.CodeStack.Push(first);
|
---|
143 | interpreter.Run(new CodeCarExpression());
|
---|
144 |
|
---|
145 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
146 | 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 | interpreter.CodeStack.Push(first);
|
---|
158 | interpreter.Run(new CodeCarExpression());
|
---|
159 |
|
---|
160 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
161 | 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 | interpreter.CodeStack.Push(first);
|
---|
173 | interpreter.Run(new CodeCdrExpression());
|
---|
174 |
|
---|
175 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
176 | 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 | interpreter.CodeStack.Push(first);
|
---|
188 | interpreter.Run(new CodeCdrExpression());
|
---|
189 |
|
---|
190 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
191 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
204 | interpreter.Run(new CodeConsExpression());
|
---|
205 |
|
---|
206 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
207 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
219 | interpreter.Run(new CodeContainsExpression());
|
---|
220 |
|
---|
221 | Assert.AreEqual(true, interpreter.BooleanStack.Top);
|
---|
222 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
234 | interpreter.Run(new CodeContainsExpression());
|
---|
235 |
|
---|
236 | Assert.AreEqual(false, interpreter.BooleanStack.Top);
|
---|
237 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
250 | interpreter.Run(new CodeContainerExpression());
|
---|
251 |
|
---|
252 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
253 | 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 | interpreter.CustomExpressions.Add("Test", code);
|
---|
264 | interpreter.NameStack.Push("Test");
|
---|
265 |
|
---|
266 | interpreter.Run(new CodeDefinitionExpression());
|
---|
267 |
|
---|
268 | Assert.AreEqual(code, interpreter.CodeStack.Top);
|
---|
269 | 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 | interpreter.CustomExpressions.Add("Test1", code);
|
---|
281 | interpreter.NameStack.Push("Test2");
|
---|
282 | interpreter.Run(program);
|
---|
283 |
|
---|
284 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
296 | interpreter.Run(new CodeDiscrepancyExpression());
|
---|
297 |
|
---|
298 | Assert.AreEqual(2, interpreter.IntegerStack.Top);
|
---|
299 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
311 | interpreter.Run(new CodeDiscrepancyExpression());
|
---|
312 |
|
---|
313 | Assert.AreEqual(0, interpreter.IntegerStack.Top);
|
---|
314 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
326 | interpreter.Run(new CodeDiscrepancyExpression());
|
---|
327 |
|
---|
328 | Assert.AreEqual(3, interpreter.IntegerStack.Top);
|
---|
329 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
341 | interpreter.Run(new CodeDiscrepancyExpression());
|
---|
342 |
|
---|
343 | Assert.AreEqual(5, interpreter.IntegerStack.Top);
|
---|
344 | 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 | interpreter.CodeStack.Push(prog);
|
---|
355 | interpreter.Run(new CodeDoExpression());
|
---|
356 |
|
---|
357 | Assert.AreEqual(10, interpreter.IntegerStack.Top);
|
---|
358 | 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 | interpreter.CodeStack.Push(prog);
|
---|
369 | interpreter.Run(new CodeDoXExpression());
|
---|
370 |
|
---|
371 | Assert.AreEqual(10, interpreter.IntegerStack.Top);
|
---|
372 | 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 | interpreter.IntegerStack.Push(3);
|
---|
383 | interpreter.CodeStack.Push(prog);
|
---|
384 | interpreter.Run(new CodeDoCountExpression());
|
---|
385 |
|
---|
386 | Assert.AreEqual(6, interpreter.IntegerStack.Top);
|
---|
387 | 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 | interpreter.IntegerStack.Push(-1);
|
---|
398 | interpreter.CodeStack.Push(prog);
|
---|
399 | interpreter.Run(new CodeDoCountExpression());
|
---|
400 |
|
---|
401 | Assert.AreEqual(-1, interpreter.IntegerStack.Top);
|
---|
402 | 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 | interpreter.IntegerStack.Push(3, 5);
|
---|
413 | interpreter.CodeStack.Push(prog);
|
---|
414 | interpreter.Run(new CodeDoRangeExpression());
|
---|
415 |
|
---|
416 | Assert.AreEqual(12, interpreter.IntegerStack.Top);
|
---|
417 | 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 | interpreter.IntegerStack.Push(3, 3);
|
---|
428 | interpreter.CodeStack.Push(prog);
|
---|
429 | interpreter.Run(new CodeDoRangeExpression());
|
---|
430 |
|
---|
431 | Assert.AreEqual(3, interpreter.IntegerStack.Top);
|
---|
432 | 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 | interpreter.IntegerStack.Push(-3, -5);
|
---|
443 | interpreter.CodeStack.Push(prog);
|
---|
444 | interpreter.Run(new CodeDoRangeExpression());
|
---|
445 |
|
---|
446 | Assert.AreEqual(-12, interpreter.IntegerStack.Top);
|
---|
447 | 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 | interpreter.IntegerStack.Push(2, 3);
|
---|
458 | interpreter.CodeStack.Push(prog);
|
---|
459 | interpreter.Run(new CodeDoTimesExpression());
|
---|
460 |
|
---|
461 | Assert.AreEqual(32, interpreter.IntegerStack.Top);
|
---|
462 | 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 | interpreter.IntegerStack.Push(2, -3);
|
---|
473 | interpreter.CodeStack.Push(prog);
|
---|
474 | interpreter.Run(new CodeDoTimesExpression());
|
---|
475 |
|
---|
476 | Assert.AreEqual(-3, interpreter.IntegerStack.Top);
|
---|
477 | TestStackCounts(codeStack: 1, integerStack: 2);
|
---|
478 | }
|
---|
479 |
|
---|
480 | [TestMethod]
|
---|
481 | [TestProperty("Time", "Short")]
|
---|
482 | [TestCategory("ExpressionTest")]
|
---|
483 | [TestCategory("CodeExpressionTest")]
|
---|
484 | public void TestNestedDoRange() {
|
---|
485 | 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, interpreter.IntegerStack.Top);
|
---|
489 | TestStackCounts(integerStack: 1);
|
---|
490 | }
|
---|
491 |
|
---|
492 | [TestMethod]
|
---|
493 | [TestProperty("Time", "Short")]
|
---|
494 | [TestCategory("ExpressionTest")]
|
---|
495 | [TestCategory("CodeExpressionTest")]
|
---|
496 | public void TestNestedDoCount() {
|
---|
497 | 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, interpreter.IntegerStack.Top);
|
---|
501 | TestStackCounts(integerStack: 1);
|
---|
502 | }
|
---|
503 |
|
---|
504 | [TestMethod]
|
---|
505 | [TestProperty("Time", "Short")]
|
---|
506 | [TestCategory("ExpressionTest")]
|
---|
507 | [TestCategory("CodeExpressionTest")]
|
---|
508 | public void TestNestedDoTimes() {
|
---|
509 | interpreter.Run(
|
---|
510 | "( 3 CODE.QUOTE ( 2 3 CODE.QUOTE ( 2 INTEGER.* ) CODE.DO*TIMES INTEGER.+ ) CODE.DO*TIMES )");
|
---|
511 |
|
---|
512 | Assert.AreEqual(128, interpreter.IntegerStack.Top);
|
---|
513 | 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 | interpreter.IntegerStack.Push(5);
|
---|
525 | interpreter.CodeStack.Push(prog);
|
---|
526 | interpreter.Run(new CodeExtractExpression());
|
---|
527 |
|
---|
528 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
529 | 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 | interpreter.IntegerStack.Push(3);
|
---|
541 | interpreter.CodeStack.Push(prog);
|
---|
542 | interpreter.Run(new CodeExtractExpression());
|
---|
543 |
|
---|
544 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
545 | 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 | interpreter.IntegerStack.Push(6);
|
---|
557 | interpreter.CodeStack.Push(prog);
|
---|
558 | interpreter.Run(new CodeExtractExpression());
|
---|
559 |
|
---|
560 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
561 | 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 | interpreter.IntegerStack.Push(8);
|
---|
573 | interpreter.CodeStack.Push(prog);
|
---|
574 | interpreter.Run(new CodeExtractExpression());
|
---|
575 |
|
---|
576 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
577 | 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 | interpreter.IntegerStack.Push(7);
|
---|
589 | interpreter.CodeStack.Push(prog);
|
---|
590 | interpreter.Run(new CodeExtractExpression());
|
---|
591 |
|
---|
592 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
593 | 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 | interpreter.BooleanStack.Push(false);
|
---|
603 | interpreter.Run(new CodeFromBooleanExpression());
|
---|
604 |
|
---|
605 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
606 | 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 | interpreter.FloatStack.Push(4.1);
|
---|
616 | interpreter.Run(new CodeFromFloatExpression());
|
---|
617 |
|
---|
618 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
619 | 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 | interpreter.IntegerStack.Push(4);
|
---|
629 | interpreter.Run(new CodeFromIntegerExpression());
|
---|
630 |
|
---|
631 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
632 | 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 | interpreter.NameStack.Push("A");
|
---|
642 | interpreter.Run(new CodeFromNameExpression());
|
---|
643 |
|
---|
644 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
645 | 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 | interpreter.BooleanStack.Push(true);
|
---|
657 | interpreter.CodeStack.Push(second, first);
|
---|
658 | interpreter.Run(new CodeIfExpression());
|
---|
659 |
|
---|
660 | Assert.AreEqual("WAHR", interpreter.NameStack.Top);
|
---|
661 | 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 | interpreter.BooleanStack.Push(false);
|
---|
673 | interpreter.CodeStack.Push(second, first);
|
---|
674 | interpreter.Run(new CodeIfExpression());
|
---|
675 |
|
---|
676 | Assert.AreEqual("FALSCH", interpreter.NameStack.Top);
|
---|
677 | 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 | interpreter.IntegerStack.Push(2);
|
---|
690 | interpreter.CodeStack.Push(second, first);
|
---|
691 | interpreter.Run(new CodeInsertExpression());
|
---|
692 |
|
---|
693 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
694 | 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 | interpreter.IntegerStack.Push(-2);
|
---|
707 | interpreter.CodeStack.Push(second, first);
|
---|
708 | interpreter.Run(new CodeInsertExpression());
|
---|
709 |
|
---|
710 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
711 | 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 | interpreter.IntegerStack.Push(10);
|
---|
724 | interpreter.CodeStack.Push(second, first);
|
---|
725 | interpreter.Run(new CodeInsertExpression());
|
---|
726 |
|
---|
727 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
728 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
741 | interpreter.Run(new CodeListExpression());
|
---|
742 |
|
---|
743 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
744 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
756 | interpreter.Run(new CodeMemberExpression());
|
---|
757 |
|
---|
758 | Assert.AreEqual(true, interpreter.BooleanStack.Top);
|
---|
759 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
771 | interpreter.Run(new CodeMemberExpression());
|
---|
772 |
|
---|
773 | Assert.AreEqual(false, interpreter.BooleanStack.Top);
|
---|
774 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
786 | interpreter.Run(new CodeMemberExpression());
|
---|
787 |
|
---|
788 | Assert.AreEqual(true, interpreter.BooleanStack.Top);
|
---|
789 | TestStackCounts(booleanStack: 1);
|
---|
790 | }
|
---|
791 |
|
---|
792 | [TestMethod]
|
---|
793 | [TestProperty("Time", "Short")]
|
---|
794 | [TestCategory("ExpressionTest")]
|
---|
795 | [TestCategory("CodeExpressionTest")]
|
---|
796 | public void TestNoop() {
|
---|
797 | interpreter.Run(new CodeNoopExpression());
|
---|
798 |
|
---|
799 | 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 | interpreter.IntegerStack.Push(3);
|
---|
811 | interpreter.CodeStack.Push(prog);
|
---|
812 | interpreter.Run(new CodeNthExpression());
|
---|
813 |
|
---|
814 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
815 | 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 | interpreter.IntegerStack.Push(3);
|
---|
827 | interpreter.CodeStack.Push(prog);
|
---|
828 | interpreter.Run(new CodeNthExpression());
|
---|
829 |
|
---|
830 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
831 | 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 | interpreter.IntegerStack.Push(3);
|
---|
843 | interpreter.CodeStack.Push(prog);
|
---|
844 | interpreter.Run(new CodeNthExpression());
|
---|
845 |
|
---|
846 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
847 | 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 | interpreter.IntegerStack.Push(13);
|
---|
859 | interpreter.CodeStack.Push(prog);
|
---|
860 | interpreter.Run(new CodeNthExpression());
|
---|
861 |
|
---|
862 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
863 | 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 | interpreter.IntegerStack.Push(-3);
|
---|
875 | interpreter.CodeStack.Push(prog);
|
---|
876 | interpreter.Run(new CodeNthExpression());
|
---|
877 |
|
---|
878 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
879 | 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 | interpreter.IntegerStack.Push(2);
|
---|
891 | interpreter.CodeStack.Push(prog);
|
---|
892 | interpreter.Run(new CodeNthCdrExpression());
|
---|
893 |
|
---|
894 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
895 | 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 | interpreter.IntegerStack.Push(10);
|
---|
907 | interpreter.CodeStack.Push(prog);
|
---|
908 | interpreter.Run(new CodeNthCdrExpression());
|
---|
909 |
|
---|
910 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
911 | 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 | interpreter.IntegerStack.Push(-2);
|
---|
923 | interpreter.CodeStack.Push(prog);
|
---|
924 | interpreter.Run(new CodeNthCdrExpression());
|
---|
925 |
|
---|
926 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
927 | 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 | interpreter.IntegerStack.Push(3);
|
---|
939 | interpreter.CodeStack.Push(prog);
|
---|
940 | interpreter.Run(new CodeNthCdrExpression());
|
---|
941 |
|
---|
942 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
943 | 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 | interpreter.IntegerStack.Push(3);
|
---|
955 | interpreter.CodeStack.Push(prog);
|
---|
956 | interpreter.Run(new CodeNthCdrExpression());
|
---|
957 |
|
---|
958 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
959 | 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 | interpreter.CodeStack.Push(prog);
|
---|
970 | interpreter.Run(new CodeNullExpression());
|
---|
971 |
|
---|
972 | Assert.AreEqual(true, interpreter.BooleanStack.Top);
|
---|
973 | 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 | interpreter.CodeStack.Push(prog);
|
---|
984 | interpreter.Run(new CodeNullExpression());
|
---|
985 |
|
---|
986 | Assert.AreEqual(false, interpreter.BooleanStack.Top);
|
---|
987 | 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 | interpreter.CodeStack.Push(second, first);
|
---|
999 | interpreter.Run(new CodePositionExpression());
|
---|
1000 |
|
---|
1001 | Assert.AreEqual(2, interpreter.IntegerStack.Top);
|
---|
1002 | 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 | interpreter.Run("( CODE.QUOTE A )");
|
---|
1013 |
|
---|
1014 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
1015 | 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 | interpreter.CodeStack.Push(prog);
|
---|
1026 | interpreter.Run(new CodeSizeExpression());
|
---|
1027 |
|
---|
1028 | Assert.AreEqual(4, interpreter.IntegerStack.Top);
|
---|
1029 | 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 | interpreter.CodeStack.Push(third, second, first);
|
---|
1043 | interpreter.Run(new CodeSubstitutionExpression());
|
---|
1044 |
|
---|
1045 | Assert.AreEqual(result, interpreter.CodeStack.Top);
|
---|
1046 | 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 | TestStackCounts(codeStack: null);
|
---|
1063 | }
|
---|
1064 | }
|
---|
1065 | } |
---|