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