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