1 | using System.Linq;
|
---|
2 | using HeuristicLab.Problems.ProgramSynthesis;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.Tests.Interpreter.Expressions {
|
---|
5 |
|
---|
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
7 |
|
---|
8 | [TestClass]
|
---|
9 | public class StringExpressionTests : CommonTests<string> {
|
---|
10 | protected override string TypeName { get { return "STRING"; } }
|
---|
11 |
|
---|
12 | protected override IPushStack<string> Stack { get { return interpreter.StringStack; } }
|
---|
13 |
|
---|
14 | protected override string[] GetValues(int count) {
|
---|
15 | return Enumerable
|
---|
16 | .Range(0, count)
|
---|
17 | .Select(_ => interpreter.Configuration.ErcOptions.StringErcOptions.GetErcValue(interpreter.Random))
|
---|
18 | .ToArray();
|
---|
19 | }
|
---|
20 |
|
---|
21 | protected override void CheckOtherStacksAreEmpty() {
|
---|
22 | TestStackCounts(stringStack: null);
|
---|
23 | }
|
---|
24 |
|
---|
25 | [TestMethod]
|
---|
26 | [TestProperty("Time", "Short")]
|
---|
27 | [TestCategory("ExpressionTest")]
|
---|
28 | [TestCategory("StringExpressionTest")]
|
---|
29 | public void TestFromInteger() {
|
---|
30 | interpreter.IntegerStack.Push(123, -123);
|
---|
31 | interpreter.Run(new StringFromIntegerExpression());
|
---|
32 | interpreter.Run(new StringFromIntegerExpression());
|
---|
33 | interpreter.Run(new StringFromIntegerExpression());
|
---|
34 |
|
---|
35 | Assert.AreEqual("123", interpreter.StringStack[0]);
|
---|
36 | Assert.AreEqual("-123", interpreter.StringStack[1]);
|
---|
37 | TestStackCounts(stringStack: 2);
|
---|
38 | }
|
---|
39 |
|
---|
40 | [TestMethod]
|
---|
41 | [TestProperty("Time", "Short")]
|
---|
42 | [TestCategory("ExpressionTest")]
|
---|
43 | [TestCategory("StringExpressionTest")]
|
---|
44 | public void TestFromFloat() {
|
---|
45 | interpreter.FloatStack.Push(123.45, -123.45);
|
---|
46 | interpreter.Run(new StringFromFloatExpression());
|
---|
47 | interpreter.Run(new StringFromFloatExpression());
|
---|
48 | interpreter.Run(new StringFromFloatExpression());
|
---|
49 |
|
---|
50 | Assert.AreEqual("123.45", interpreter.StringStack[0]);
|
---|
51 | Assert.AreEqual("-123.45", interpreter.StringStack[1]);
|
---|
52 | TestStackCounts(stringStack: 2);
|
---|
53 | }
|
---|
54 |
|
---|
55 | [TestMethod]
|
---|
56 | [TestProperty("Time", "Short")]
|
---|
57 | [TestCategory("ExpressionTest")]
|
---|
58 | [TestCategory("StringExpressionTest")]
|
---|
59 | public void TestFromBoolean() {
|
---|
60 | interpreter.BooleanStack.Push(true, false);
|
---|
61 | interpreter.Run(new StringFromBooleanExpression());
|
---|
62 | interpreter.Run(new StringFromBooleanExpression());
|
---|
63 |
|
---|
64 | Assert.AreEqual("True", interpreter.StringStack[0]);
|
---|
65 | Assert.AreEqual("False", interpreter.StringStack[1]);
|
---|
66 | TestStackCounts(stringStack: 2);
|
---|
67 | }
|
---|
68 |
|
---|
69 | [TestMethod]
|
---|
70 | [TestProperty("Time", "Short")]
|
---|
71 | [TestCategory("ExpressionTest")]
|
---|
72 | [TestCategory("StringExpressionTest")]
|
---|
73 | public void TestFromChar() {
|
---|
74 | interpreter.CharStack.Push(' ', 'a');
|
---|
75 | interpreter.Run(new StringFromCharExpression());
|
---|
76 | interpreter.Run(new StringFromCharExpression());
|
---|
77 |
|
---|
78 | Assert.AreEqual(" ", interpreter.StringStack[0]);
|
---|
79 | Assert.AreEqual("a", interpreter.StringStack[1]);
|
---|
80 | TestStackCounts(stringStack: 2);
|
---|
81 | }
|
---|
82 |
|
---|
83 | [TestMethod]
|
---|
84 | [TestProperty("Time", "Short")]
|
---|
85 | [TestCategory("ExpressionTest")]
|
---|
86 | [TestCategory("StringExpressionTest")]
|
---|
87 | public void TestConcat() {
|
---|
88 | interpreter.StringStack.Push("test", "123");
|
---|
89 | interpreter.Run(new StringConcatExpression());
|
---|
90 |
|
---|
91 | Assert.AreEqual("test123", interpreter.StringStack[0]);
|
---|
92 | TestStackCounts(stringStack: 1);
|
---|
93 | }
|
---|
94 |
|
---|
95 | [TestMethod]
|
---|
96 | [TestProperty("Time", "Short")]
|
---|
97 | [TestCategory("ExpressionTest")]
|
---|
98 | [TestCategory("StringExpressionTest")]
|
---|
99 | public void TestConjChar() {
|
---|
100 | interpreter.CharStack.Push('3', '2', '1');
|
---|
101 | interpreter.StringStack.Push("test");
|
---|
102 |
|
---|
103 | interpreter.Run(new StringConjCharExpression());
|
---|
104 | interpreter.Run(new StringConjCharExpression());
|
---|
105 | interpreter.Run(new StringConjCharExpression());
|
---|
106 |
|
---|
107 | Assert.AreEqual("test123", interpreter.StringStack[0]);
|
---|
108 | TestStackCounts(stringStack: 1);
|
---|
109 | }
|
---|
110 |
|
---|
111 | [TestMethod]
|
---|
112 | [TestProperty("Time", "Short")]
|
---|
113 | [TestCategory("ExpressionTest")]
|
---|
114 | [TestCategory("StringExpressionTest")]
|
---|
115 | public void TestTake() {
|
---|
116 | interpreter.IntegerStack.Push(3, -3, 7, 0);
|
---|
117 |
|
---|
118 | interpreter.StringStack.Push("test");
|
---|
119 | interpreter.Run(new StringTakeExpression());
|
---|
120 | Assert.AreEqual("", interpreter.StringStack[0]);
|
---|
121 |
|
---|
122 | interpreter.StringStack.Push("test");
|
---|
123 | interpreter.Run(new StringTakeExpression());
|
---|
124 | Assert.AreEqual("tes", interpreter.StringStack[0]);
|
---|
125 |
|
---|
126 | interpreter.StringStack.Push("test");
|
---|
127 | interpreter.Run(new StringTakeExpression());
|
---|
128 | Assert.AreEqual("tes", interpreter.StringStack[0]);
|
---|
129 |
|
---|
130 | interpreter.StringStack.Push("test");
|
---|
131 | interpreter.Run(new StringTakeExpression());
|
---|
132 | Assert.AreEqual("tes", interpreter.StringStack[0]);
|
---|
133 |
|
---|
134 | TestStackCounts(stringStack: 4);
|
---|
135 | }
|
---|
136 |
|
---|
137 | [TestMethod]
|
---|
138 | [TestProperty("Time", "Short")]
|
---|
139 | [TestCategory("ExpressionTest")]
|
---|
140 | [TestCategory("StringExpressionTest")]
|
---|
141 | public void TestFirst() {
|
---|
142 | interpreter.StringStack.Push("test");
|
---|
143 |
|
---|
144 | interpreter.Run(new StringFirstExpression());
|
---|
145 |
|
---|
146 | Assert.AreEqual("t", interpreter.StringStack[0]);
|
---|
147 | TestStackCounts(stringStack: 1);
|
---|
148 | }
|
---|
149 |
|
---|
150 | [TestMethod]
|
---|
151 | [TestProperty("Time", "Short")]
|
---|
152 | [TestCategory("ExpressionTest")]
|
---|
153 | [TestCategory("StringExpressionTest")]
|
---|
154 | public void TestLast() {
|
---|
155 | interpreter.StringStack.Push("test");
|
---|
156 | interpreter.Run(new StringLastExpression());
|
---|
157 |
|
---|
158 | Assert.AreEqual("t", interpreter.StringStack[0]);
|
---|
159 | TestStackCounts(stringStack: 1);
|
---|
160 | }
|
---|
161 |
|
---|
162 | [TestMethod]
|
---|
163 | [TestProperty("Time", "Short")]
|
---|
164 | [TestCategory("ExpressionTest")]
|
---|
165 | [TestCategory("StringExpressionTest")]
|
---|
166 | public void TestNth() {
|
---|
167 | interpreter.IntegerStack.Push(2, -2, 6);
|
---|
168 |
|
---|
169 | interpreter.StringStack.Push("test");
|
---|
170 | interpreter.Run(new StringNthExpression());
|
---|
171 | Assert.AreEqual("s", interpreter.StringStack[0]);
|
---|
172 |
|
---|
173 | interpreter.StringStack.Push("test");
|
---|
174 | interpreter.Run(new StringNthExpression());
|
---|
175 | Assert.AreEqual("s", interpreter.StringStack[0]);
|
---|
176 |
|
---|
177 | interpreter.StringStack.Push("test");
|
---|
178 | interpreter.Run(new StringNthExpression());
|
---|
179 | Assert.AreEqual("s", interpreter.StringStack[0]);
|
---|
180 |
|
---|
181 | TestStackCounts(stringStack: 3);
|
---|
182 | }
|
---|
183 |
|
---|
184 | [TestMethod]
|
---|
185 | [TestProperty("Time", "Short")]
|
---|
186 | [TestCategory("ExpressionTest")]
|
---|
187 | [TestCategory("StringExpressionTest")]
|
---|
188 | public void TestRest() {
|
---|
189 | interpreter.StringStack.Push("test");
|
---|
190 | interpreter.Run(new StringRestExpression());
|
---|
191 |
|
---|
192 | Assert.AreEqual("est", interpreter.StringStack[0]);
|
---|
193 | TestStackCounts(stringStack: 1);
|
---|
194 | }
|
---|
195 |
|
---|
196 | [TestMethod]
|
---|
197 | [TestProperty("Time", "Short")]
|
---|
198 | [TestCategory("ExpressionTest")]
|
---|
199 | [TestCategory("StringExpressionTest")]
|
---|
200 | public void TestButLast() {
|
---|
201 | interpreter.StringStack.Push("test");
|
---|
202 | interpreter.Run(new StringButLastExpression());
|
---|
203 |
|
---|
204 | Assert.AreEqual("tes", interpreter.StringStack[0]);
|
---|
205 | TestStackCounts(stringStack: 1);
|
---|
206 | }
|
---|
207 |
|
---|
208 | [TestMethod]
|
---|
209 | [TestProperty("Time", "Short")]
|
---|
210 | [TestCategory("ExpressionTest")]
|
---|
211 | [TestCategory("StringExpressionTest")]
|
---|
212 | public void TestLength() {
|
---|
213 | interpreter.StringStack.Push("test");
|
---|
214 | interpreter.Run(new StringLengthExpression());
|
---|
215 |
|
---|
216 | Assert.AreEqual(4, interpreter.IntegerStack.Top);
|
---|
217 | TestStackCounts(stringStack: 0, integerStack: 1);
|
---|
218 | }
|
---|
219 |
|
---|
220 | [TestMethod]
|
---|
221 | [TestProperty("Time", "Short")]
|
---|
222 | [TestCategory("ExpressionTest")]
|
---|
223 | [TestCategory("StringExpressionTest")]
|
---|
224 | public void TestReverse() {
|
---|
225 | interpreter.StringStack.Push("test");
|
---|
226 | interpreter.Run(new StringReverseExpression());
|
---|
227 |
|
---|
228 | Assert.AreEqual("tset", interpreter.StringStack[0]);
|
---|
229 | TestStackCounts(stringStack: 1);
|
---|
230 | }
|
---|
231 |
|
---|
232 | [TestMethod]
|
---|
233 | [TestProperty("Time", "Short")]
|
---|
234 | [TestCategory("ExpressionTest")]
|
---|
235 | [TestCategory("StringExpressionTest")]
|
---|
236 | public void TestParseToChars() {
|
---|
237 | interpreter.StringStack.Push("test");
|
---|
238 | interpreter.Run(new StringParseToCharsExpression());
|
---|
239 |
|
---|
240 | Assert.AreEqual("t", interpreter.StringStack[0]);
|
---|
241 | Assert.AreEqual("s", interpreter.StringStack[1]);
|
---|
242 | Assert.AreEqual("e", interpreter.StringStack[2]);
|
---|
243 | Assert.AreEqual("t", interpreter.StringStack[3]);
|
---|
244 | TestStackCounts(stringStack: 4);
|
---|
245 | }
|
---|
246 |
|
---|
247 | [TestMethod]
|
---|
248 | [TestProperty("Time", "Short")]
|
---|
249 | [TestCategory("ExpressionTest")]
|
---|
250 | [TestCategory("StringExpressionTest")]
|
---|
251 | public void TestSplit() {
|
---|
252 | interpreter.StringStack.Push("test1 test2");
|
---|
253 | interpreter.Run(new StringSplitExpression());
|
---|
254 |
|
---|
255 | Assert.AreEqual("test1", interpreter.StringStack[0]);
|
---|
256 | Assert.AreEqual("test2", interpreter.StringStack[1]);
|
---|
257 | TestStackCounts(stringStack: 2);
|
---|
258 | }
|
---|
259 |
|
---|
260 | [TestMethod]
|
---|
261 | [TestProperty("Time", "Short")]
|
---|
262 | [TestCategory("ExpressionTest")]
|
---|
263 | [TestCategory("StringExpressionTest")]
|
---|
264 | public void TestEmptyString() {
|
---|
265 | interpreter.StringStack.Push("test1", "");
|
---|
266 | interpreter.Run(new StringEmptyStringExpression());
|
---|
267 | interpreter.Run(new StringEmptyStringExpression());
|
---|
268 |
|
---|
269 | Assert.AreEqual(false, interpreter.BooleanStack[0]);
|
---|
270 | Assert.AreEqual(true, interpreter.BooleanStack[1]);
|
---|
271 | TestStackCounts(stringStack: 0, booleanStack: 2);
|
---|
272 | }
|
---|
273 |
|
---|
274 | [TestMethod]
|
---|
275 | [TestProperty("Time", "Short")]
|
---|
276 | [TestCategory("ExpressionTest")]
|
---|
277 | [TestCategory("StringExpressionTest")]
|
---|
278 | public void TestContains() {
|
---|
279 | interpreter.StringStack.Push(new[] { "test1", "est", "test", "abc", "test", "" });
|
---|
280 | interpreter.Run(new StringContainsExpression());
|
---|
281 | interpreter.Run(new StringContainsExpression());
|
---|
282 | interpreter.Run(new StringContainsExpression());
|
---|
283 |
|
---|
284 | Assert.AreEqual(true, interpreter.BooleanStack[0]);
|
---|
285 | Assert.AreEqual(false, interpreter.BooleanStack[1]);
|
---|
286 | Assert.AreEqual(true, interpreter.BooleanStack[2]);
|
---|
287 | TestStackCounts(stringStack: 0, booleanStack: 3);
|
---|
288 | }
|
---|
289 |
|
---|
290 | [TestMethod]
|
---|
291 | [TestProperty("Time", "Short")]
|
---|
292 | [TestCategory("ExpressionTest")]
|
---|
293 | [TestCategory("StringExpressionTest")]
|
---|
294 | public void TestContainsChar() {
|
---|
295 | interpreter.CharStack.Push('e', 'a');
|
---|
296 | interpreter.StringStack.Push("test", "test");
|
---|
297 | interpreter.Run(new StringContainsCharExpression());
|
---|
298 | interpreter.Run(new StringContainsCharExpression());
|
---|
299 |
|
---|
300 | Assert.AreEqual(true, interpreter.BooleanStack[0]);
|
---|
301 | Assert.AreEqual(false, interpreter.BooleanStack[1]);
|
---|
302 | TestStackCounts(stringStack: 0, charStack: 0, booleanStack: 2);
|
---|
303 | }
|
---|
304 |
|
---|
305 | [TestMethod]
|
---|
306 | [TestProperty("Time", "Short")]
|
---|
307 | [TestCategory("ExpressionTest")]
|
---|
308 | [TestCategory("StringExpressionTest")]
|
---|
309 | public void TestIndexOfChar() {
|
---|
310 | interpreter.CharStack.Push('e', 'a');
|
---|
311 | interpreter.StringStack.Push("test", "test");
|
---|
312 | interpreter.Run(new StringIndexOfCharExpression());
|
---|
313 | interpreter.Run(new StringIndexOfCharExpression());
|
---|
314 |
|
---|
315 | Assert.AreEqual(1, interpreter.IntegerStack[0]);
|
---|
316 | Assert.AreEqual(-1, interpreter.IntegerStack[1]);
|
---|
317 | TestStackCounts(stringStack: 0, charStack: 0, integerStack: 2);
|
---|
318 | }
|
---|
319 |
|
---|
320 | [TestMethod]
|
---|
321 | [TestProperty("Time", "Short")]
|
---|
322 | [TestCategory("ExpressionTest")]
|
---|
323 | [TestCategory("StringExpressionTest")]
|
---|
324 | public void TestOccurrencesOfChar() {
|
---|
325 | interpreter.CharStack.Push('t', 'a');
|
---|
326 | interpreter.StringStack.Push("test", "test");
|
---|
327 | interpreter.Run(new StringOccurrencesOfCharExpression());
|
---|
328 | interpreter.Run(new StringOccurrencesOfCharExpression());
|
---|
329 |
|
---|
330 | Assert.AreEqual(2, interpreter.IntegerStack[0]);
|
---|
331 | Assert.AreEqual(0, interpreter.IntegerStack[1]);
|
---|
332 | TestStackCounts(stringStack: 0, charStack: 0, integerStack: 2);
|
---|
333 | }
|
---|
334 |
|
---|
335 | [TestMethod]
|
---|
336 | [TestProperty("Time", "Short")]
|
---|
337 | [TestCategory("ExpressionTest")]
|
---|
338 | [TestCategory("StringExpressionTest")]
|
---|
339 | public void TestReplace() {
|
---|
340 | interpreter.StringStack.Push("test", "es", "12");
|
---|
341 | interpreter.Run(new StringReplaceExpression());
|
---|
342 | Assert.AreEqual("t12t", interpreter.StringStack[0]);
|
---|
343 |
|
---|
344 | interpreter.StringStack.Push("test test", "es", "12");
|
---|
345 | interpreter.Run(new StringReplaceExpression());
|
---|
346 | Assert.AreEqual("t12t t12t", interpreter.StringStack[0]);
|
---|
347 |
|
---|
348 | interpreter.StringStack.Push("test", "ab", "12");
|
---|
349 | interpreter.Run(new StringReplaceExpression());
|
---|
350 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
351 |
|
---|
352 | interpreter.StringStack.Push("test", "", "12");
|
---|
353 | interpreter.Run(new StringReplaceExpression());
|
---|
354 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
355 |
|
---|
356 | interpreter.StringStack.Push("test", "ab", "");
|
---|
357 | interpreter.Run(new StringReplaceExpression());
|
---|
358 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
359 |
|
---|
360 | interpreter.StringStack.Push("test", "es", "");
|
---|
361 | interpreter.Run(new StringReplaceExpression());
|
---|
362 | Assert.AreEqual("tt", interpreter.StringStack[0]);
|
---|
363 |
|
---|
364 | TestStackCounts(stringStack: 6);
|
---|
365 | }
|
---|
366 |
|
---|
367 | [TestMethod]
|
---|
368 | [TestProperty("Time", "Short")]
|
---|
369 | [TestCategory("ExpressionTest")]
|
---|
370 | [TestCategory("StringExpressionTest")]
|
---|
371 | public void TestReplaceFirst() {
|
---|
372 | interpreter.StringStack.Push("test", "es", "12");
|
---|
373 | interpreter.Run(new StringReplaceFirstExpression());
|
---|
374 | Assert.AreEqual("t12t", interpreter.StringStack[0]);
|
---|
375 |
|
---|
376 | interpreter.StringStack.Push("test test", "es", "12");
|
---|
377 | interpreter.Run(new StringReplaceFirstExpression());
|
---|
378 | Assert.AreEqual("t12t test", interpreter.StringStack[0]);
|
---|
379 |
|
---|
380 | interpreter.StringStack.Push("test", "ab", "12");
|
---|
381 | interpreter.Run(new StringReplaceFirstExpression());
|
---|
382 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
383 |
|
---|
384 | interpreter.StringStack.Push("test", "", "12");
|
---|
385 | interpreter.Run(new StringReplaceFirstExpression());
|
---|
386 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
387 |
|
---|
388 | interpreter.StringStack.Push("test", "ab", "");
|
---|
389 | interpreter.Run(new StringReplaceFirstExpression());
|
---|
390 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
391 |
|
---|
392 | interpreter.StringStack.Push("test", "es", "");
|
---|
393 | interpreter.Run(new StringReplaceFirstExpression());
|
---|
394 | Assert.AreEqual("tt", interpreter.StringStack[0]);
|
---|
395 |
|
---|
396 | TestStackCounts(stringStack: 6);
|
---|
397 | }
|
---|
398 |
|
---|
399 | [TestMethod]
|
---|
400 | [TestProperty("Time", "Short")]
|
---|
401 | [TestCategory("ExpressionTest")]
|
---|
402 | [TestCategory("StringExpressionTest")]
|
---|
403 | public void TestReplaceChar() {
|
---|
404 | interpreter.StringStack.Push("test");
|
---|
405 | interpreter.CharStack.Push('t', 'T');
|
---|
406 | interpreter.Run(new StringReplaceCharExpression());
|
---|
407 | Assert.AreEqual("TesT", interpreter.StringStack[0]);
|
---|
408 |
|
---|
409 | interpreter.StringStack.Push("test");
|
---|
410 | interpreter.CharStack.Push('a', 'T');
|
---|
411 | interpreter.Run(new StringReplaceCharExpression());
|
---|
412 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
413 |
|
---|
414 | interpreter.StringStack.Push("");
|
---|
415 | interpreter.CharStack.Push('t', 'T');
|
---|
416 | interpreter.Run(new StringReplaceCharExpression());
|
---|
417 | Assert.AreEqual("", interpreter.StringStack[0]);
|
---|
418 |
|
---|
419 | TestStackCounts(stringStack: 3);
|
---|
420 | }
|
---|
421 |
|
---|
422 | [TestMethod]
|
---|
423 | [TestProperty("Time", "Short")]
|
---|
424 | [TestCategory("ExpressionTest")]
|
---|
425 | [TestCategory("StringExpressionTest")]
|
---|
426 | public void TestReplaceFirstChar() {
|
---|
427 | interpreter.StringStack.Push("test");
|
---|
428 | interpreter.CharStack.Push('t', 'T');
|
---|
429 | interpreter.Run(new StringReplaceFirstCharExpression());
|
---|
430 | Assert.AreEqual("Test", interpreter.StringStack[0]);
|
---|
431 |
|
---|
432 | interpreter.StringStack.Push("test");
|
---|
433 | interpreter.CharStack.Push('a', 'T');
|
---|
434 | interpreter.Run(new StringReplaceFirstCharExpression());
|
---|
435 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
436 |
|
---|
437 | interpreter.StringStack.Push("");
|
---|
438 | interpreter.CharStack.Push('t', 'T');
|
---|
439 | interpreter.Run(new StringReplaceFirstCharExpression());
|
---|
440 | Assert.AreEqual("", interpreter.StringStack[0]);
|
---|
441 |
|
---|
442 | TestStackCounts(stringStack: 3);
|
---|
443 | }
|
---|
444 |
|
---|
445 | [TestMethod]
|
---|
446 | [TestProperty("Time", "Short")]
|
---|
447 | [TestCategory("ExpressionTest")]
|
---|
448 | [TestCategory("StringExpressionTest")]
|
---|
449 | public void TestRemoveChar() {
|
---|
450 | interpreter.StringStack.Push("test");
|
---|
451 | interpreter.CharStack.Push('t');
|
---|
452 | interpreter.Run(new StringRemoveCharExpression());
|
---|
453 | Assert.AreEqual("es", interpreter.StringStack[0]);
|
---|
454 |
|
---|
455 | interpreter.StringStack.Push("test");
|
---|
456 | interpreter.CharStack.Push('a');
|
---|
457 | interpreter.Run(new StringRemoveCharExpression());
|
---|
458 | Assert.AreEqual("test", interpreter.StringStack[0]);
|
---|
459 |
|
---|
460 | interpreter.StringStack.Push("");
|
---|
461 | interpreter.CharStack.Push('t');
|
---|
462 | interpreter.Run(new StringRemoveCharExpression());
|
---|
463 | Assert.AreEqual("", interpreter.StringStack[0]);
|
---|
464 |
|
---|
465 | TestStackCounts(stringStack: 3);
|
---|
466 | }
|
---|
467 |
|
---|
468 | [TestMethod]
|
---|
469 | [TestProperty("Time", "Short")]
|
---|
470 | [TestCategory("ExpressionTest")]
|
---|
471 | [TestCategory("StringExpressionTest")]
|
---|
472 | public void TestSetChar() {
|
---|
473 | interpreter.StringStack.Push("test");
|
---|
474 | interpreter.CharStack.Push('x');
|
---|
475 | interpreter.IntegerStack.Push(2);
|
---|
476 | interpreter.Run(new StringSetCharExpression());
|
---|
477 | Assert.AreEqual("text", interpreter.StringStack[0]);
|
---|
478 |
|
---|
479 | interpreter.StringStack.Push("test");
|
---|
480 | interpreter.CharStack.Push('x');
|
---|
481 | interpreter.IntegerStack.Push(-2);
|
---|
482 | interpreter.Run(new StringSetCharExpression());
|
---|
483 | Assert.AreEqual("text", interpreter.StringStack[0]);
|
---|
484 |
|
---|
485 | interpreter.StringStack.Push("test");
|
---|
486 | interpreter.CharStack.Push('x');
|
---|
487 | interpreter.IntegerStack.Push(6);
|
---|
488 | interpreter.Run(new StringSetCharExpression());
|
---|
489 | Assert.AreEqual("text", interpreter.StringStack[0]);
|
---|
490 |
|
---|
491 | interpreter.StringStack.Push("");
|
---|
492 | interpreter.CharStack.Push('x');
|
---|
493 | interpreter.IntegerStack.Push(2);
|
---|
494 | interpreter.Run(new StringSetCharExpression());
|
---|
495 | Assert.AreEqual("", interpreter.StringStack[0]);
|
---|
496 |
|
---|
497 | interpreter.StringStack.Push("s");
|
---|
498 | interpreter.CharStack.Push('x');
|
---|
499 | interpreter.IntegerStack.Push(2);
|
---|
500 | interpreter.Run(new StringSetCharExpression());
|
---|
501 | Assert.AreEqual("x", interpreter.StringStack[0]);
|
---|
502 |
|
---|
503 | TestStackCounts(stringStack: 5);
|
---|
504 | }
|
---|
505 |
|
---|
506 |
|
---|
507 | [TestMethod]
|
---|
508 | [TestProperty("Time", "Short")]
|
---|
509 | [TestCategory("ExpressionTest")]
|
---|
510 | [TestCategory("StringExpressionTest")]
|
---|
511 | public void TestIterate() {
|
---|
512 | interpreter.StringStack.Push("test");
|
---|
513 | interpreter.IntegerStack.Push(0);
|
---|
514 | interpreter.Run(new PushProgram(new Expression[] {
|
---|
515 | new IntegerIncExpression(),
|
---|
516 | new StringIterateExpression(),
|
---|
517 | }));
|
---|
518 |
|
---|
519 | Assert.AreEqual(4, interpreter.IntegerStack[0]);
|
---|
520 | TestStackCounts(integerStack: 1, charStack: 4);
|
---|
521 | }
|
---|
522 | }
|
---|
523 | }
|
---|