1 | namespace HeuristicLab.Tests.Benchmark {
|
---|
2 |
|
---|
3 | using HeuristicLab.BenchmarkSuite;
|
---|
4 | using HeuristicLab.BenchmarkSuite.Problems;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
|
---|
7 | using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
|
---|
8 | using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions;
|
---|
9 | using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
|
---|
10 | using HeuristicLab.Problems.ProgramSynthesis.Push.Parser;
|
---|
11 | using HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite;
|
---|
12 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
13 | using HeuristicLab.Random;
|
---|
14 |
|
---|
15 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
16 |
|
---|
17 | [TestClass]
|
---|
18 | public class SolutionTests {
|
---|
19 |
|
---|
20 | private IRandom random;
|
---|
21 |
|
---|
22 | [TestInitialize]
|
---|
23 | public void BeforeTest() {
|
---|
24 | random = new MersenneTwister(1337);
|
---|
25 | }
|
---|
26 |
|
---|
27 | private void TestProgram(PushProgram program, IBenchmarkSuiteDataDescriptor descriptor, string floatStringFormat = "R") {
|
---|
28 | var data = descriptor.CreateProblemData();
|
---|
29 | var config = new PushConfiguration {
|
---|
30 | EvalPushLimit = data.EvalLimit,
|
---|
31 | MaxPointsInProgram = data.MaxSize,
|
---|
32 | ErcOptions = data.ErcOptions,
|
---|
33 | FloatStringFormat = floatStringFormat
|
---|
34 | };
|
---|
35 |
|
---|
36 | config.SetEnabledStacks((StackTypes)data.EnabledDataTypes);
|
---|
37 | data.InitInExpressions(config);
|
---|
38 |
|
---|
39 | var evaluator = new PushBenchmarkSuiteEvaluator(data);
|
---|
40 | var pool = new PushInterpreterPool(config);
|
---|
41 | var result = evaluator.EvaluateTraining(pool, program, random);
|
---|
42 |
|
---|
43 | Assert.AreEqual(0, result.AvgQuality);
|
---|
44 | }
|
---|
45 |
|
---|
46 | [TestMethod]
|
---|
47 | [TestProperty("Time", "Short")]
|
---|
48 | [TestCategory("ProblemTest")]
|
---|
49 | public void Checksum() {
|
---|
50 | TestProgram(
|
---|
51 | PushParser.ParseProgram("( IN1 0 STRING.ITERATE ( INTEGER.FROMCHAR INTEGER.+ ) 64 INTEGER.% \' \' INTEGER.FROMCHAR INTEGER.+ \"Check sum is \" PRINT.PRINTSTRING CHAR.FROMINTEGER PRINT.PRINTCHAR )"),
|
---|
52 | new Checksum());
|
---|
53 | }
|
---|
54 |
|
---|
55 | [TestMethod]
|
---|
56 | [TestProperty("Time", "Short")]
|
---|
57 | [TestCategory("ProblemTest")]
|
---|
58 | public void CollatzNumbers() {
|
---|
59 | TestProgram(
|
---|
60 | PushParser.ParseProgram("( IN1 INTEGER.DUP 1 INTEGER.= BOOLEAN.NOT EXEC.WHILE ( INTEGER.DUP INTEGER.DUP 2 INTEGER.% 0 INTEGER.= EXEC.IF ( 2 INTEGER./ ) ( 3 INTEGER.* 1 INTEGER.+ ) INTEGER.DUP 1 INTEGER.= BOOLEAN.NOT ) INTEGER.POP INTEGER.STACKDEPTH )"),
|
---|
61 | new CollatzNumbers());
|
---|
62 | }
|
---|
63 |
|
---|
64 | [TestMethod]
|
---|
65 | [TestProperty("Time", "Short")]
|
---|
66 | [TestCategory("ProblemTest")]
|
---|
67 | public void CompareStringLengths() {
|
---|
68 | TestProgram(
|
---|
69 | PushParser.ParseProgram("IN1 IN2 IN3 STRING.LENGTH STRING.LENGTH INTEGER.DUP STRING.LENGTH INTEGER.> INTEGER.> BOOLEAN.AND"),
|
---|
70 | new CompareStringLengths());
|
---|
71 | }
|
---|
72 |
|
---|
73 | [TestMethod]
|
---|
74 | [TestProperty("Time", "Short")]
|
---|
75 | [TestCategory("ProblemTest")]
|
---|
76 | public void CountOdds() {
|
---|
77 | TestProgram(
|
---|
78 | PushParser.ParseProgram("( IN1 0 INTEGER[].ITERATE ( 2 INTEGER.% INTEGER.DUP 1 INTEGER.= -1 INTEGER.= BOOLEAN.OR EXEC.WHEN INTEGER.INC ) )"),
|
---|
79 | new CountOdds());
|
---|
80 | }
|
---|
81 |
|
---|
82 | [TestMethod]
|
---|
83 | [TestProperty("Time", "Short")]
|
---|
84 | [TestCategory("ProblemTest")]
|
---|
85 | public void Digits() {
|
---|
86 | TestProgram(
|
---|
87 | PushParser.ParseProgram("( IN1 INTEGER.DUP STRING.FROMINTEGER 0 INTEGER.< BOOLEAN.DUP EXEC.WHEN ( STRING.REST STRING.DUP STRING.FIRST STRING.SWAP STRING.REST ) STRING.REVERSE STRING.ITERATE ( PRINT.NEWLINE PRINT.PRINTCHAR ) EXEC.WHEN ( PRINT.NEWLINE \'-\' PRINT.PRINTCHAR PRINT.PRINTSTRING ) )"),
|
---|
88 | new Digits());
|
---|
89 | }
|
---|
90 |
|
---|
91 | [TestMethod]
|
---|
92 | [TestProperty("Time", "Short")]
|
---|
93 | [TestCategory("ProblemTest")]
|
---|
94 | public void DoubleLetters() {
|
---|
95 | TestProgram(
|
---|
96 | PushParser.ParseProgram(
|
---|
97 | @"IN1
|
---|
98 | STRING.ITERATE (
|
---|
99 | 3 EXEC.DO*COUNT CHAR.DUP
|
---|
100 | CHAR.ISLETTER EXEC.WHEN PRINT.PRINTCHAR
|
---|
101 | '!' CHAR.= EXEC.WHEN ( CHAR.DUP PRINT.PRINTCHAR PRINT.PRINTCHAR )
|
---|
102 | PRINT.PRINTCHAR
|
---|
103 | )"),
|
---|
104 | new DoubleLetters());
|
---|
105 | }
|
---|
106 |
|
---|
107 | [TestMethod]
|
---|
108 | [TestProperty("Time", "Short")]
|
---|
109 | [TestCategory("ProblemTest")]
|
---|
110 | public void EvenSquares() {
|
---|
111 | TestProgram(
|
---|
112 | PushParser.ParseProgram(
|
---|
113 | @"IN1 INTEGER.DUP EXEC.DO*COUNT (
|
---|
114 | INTEGER.DUP 0 INTEGER.>
|
---|
115 | EXEC.WHEN (
|
---|
116 | INTEGER.DUP 2 INTEGER.*
|
---|
117 | INTEGER.DUP INTEGER.DUP INTEGER.*
|
---|
118 | INTEGER.DUP 4 INTEGER.YANKDUP INTEGER.<
|
---|
119 | EXEC.IF (
|
---|
120 | PRINT.PRINTINTEGER
|
---|
121 | PRINT.NEWLINE
|
---|
122 | )
|
---|
123 | EXEC.FLUSH
|
---|
124 | INTEGER.POP
|
---|
125 | )
|
---|
126 | INTEGER.POP
|
---|
127 | )"),
|
---|
128 | new EvenSquares());
|
---|
129 | }
|
---|
130 |
|
---|
131 | [TestMethod]
|
---|
132 | [TestProperty("Time", "Short")]
|
---|
133 | [TestCategory("ProblemTest")]
|
---|
134 | public void ForLoopIndex() {
|
---|
135 | TestProgram(
|
---|
136 | PushParser.ParseProgram(
|
---|
137 | @"( IN1 IN2 IN3 STRING.FROMINTEGER INTEGER.SWAP true EXEC.WHILE ( INTEGER.DUP PRINT.NEWLINE PRINT.PRINTINTEGER STRING.DUP INTEGER.FROMSTRING INTEGER.+ INTEGER.DUP 2 INTEGER.YANKDUP INTEGER.< ) )"),
|
---|
138 | new ForLoopIndex());
|
---|
139 | }
|
---|
140 |
|
---|
141 | [TestMethod]
|
---|
142 | [TestProperty("Time", "Short")]
|
---|
143 | [TestCategory("ProblemTest")]
|
---|
144 | public void Grades() {
|
---|
145 | TestProgram(
|
---|
146 | PushParser.ParseProgram("( IN1 IN2 IN3 IN4 IN5 \"Student has a \" PRINT.PRINTSTRING INTEGER.DUP INTEGER.ROT INTEGER.> EXEC.WHEN ( \"F\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) INTEGER.DUP INTEGER.ROT INTEGER.> EXEC.WHEN ( \"D\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) INTEGER.DUP INTEGER.ROT INTEGER.> EXEC.WHEN ( \"C\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) INTEGER.DUP INTEGER.ROT INTEGER.> EXEC.WHEN ( \"B\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING EXEC.FLUSH ) \"A\" \" grade.\" STRING.CONCAT PRINT.PRINTSTRING )"),
|
---|
147 | new Grades());
|
---|
148 | }
|
---|
149 |
|
---|
150 | [TestMethod]
|
---|
151 | [TestProperty("Time", "Short")]
|
---|
152 | [TestCategory("ProblemTest")]
|
---|
153 | public void LastIndexOfZero() {
|
---|
154 | TestProgram(
|
---|
155 | PushParser.ParseProgram("( IN1 INTEGER[].DUP INTEGER[].LENGTH INTEGER[].REVERSE 0 INTEGER[].INDEXOF INTEGER.- INTEGER.DEC )"),
|
---|
156 | new LastIndexOfZero());
|
---|
157 | }
|
---|
158 |
|
---|
159 | [TestMethod]
|
---|
160 | [TestProperty("Time", "Short")]
|
---|
161 | [TestCategory("ProblemTest")]
|
---|
162 | public void Median() {
|
---|
163 | TestProgram(
|
---|
164 | PushParser.ParseProgram("( IN1 IN2 IN3 INTEGER.ROT INTEGER.DUP 2 INTEGER.YANKDUP INTEGER.MAX 3 INTEGER.YANKDUP INTEGER.MIN INTEGER.ROT INTEGER.MIN INTEGER.MAX PRINT.PRINTINTEGER )"),
|
---|
165 | new Median());
|
---|
166 | }
|
---|
167 |
|
---|
168 | [TestMethod]
|
---|
169 | [TestProperty("Time", "Short")]
|
---|
170 | [TestCategory("ProblemTest")]
|
---|
171 | public void MirrorImage() {
|
---|
172 | TestProgram(
|
---|
173 | PushParser.ParseProgram(
|
---|
174 | @"( IN1 IN2
|
---|
175 | INTEGER[].PUSHALL INTEGER[].ITERATE (
|
---|
176 | INTEGER.= BOOLEAN.NOT EXEC.WHEN ( false EXEC.FLUSH )
|
---|
177 | )
|
---|
178 | true
|
---|
179 | )"),
|
---|
180 | new MirrorImage());
|
---|
181 | }
|
---|
182 |
|
---|
183 | [TestMethod]
|
---|
184 | [TestProperty("Time", "Short")]
|
---|
185 | [TestCategory("ProblemTest")]
|
---|
186 | public void NegativeToZero() {
|
---|
187 | TestProgram(
|
---|
188 | PushParser.ParseProgram("( IN1 INTEGER[].DUP INTEGER[].LENGTH INTEGER.DEC EXEC.DO*COUNT ( INTEGER.DUP INTEGER[].DUP INTEGER[].NTH 0 INTEGER.< EXEC.WHEN ( 0 INTEGER[].SET ) ) )"),
|
---|
189 | new NegativeToZero());
|
---|
190 | }
|
---|
191 |
|
---|
192 | [TestMethod]
|
---|
193 | [TestProperty("Time", "Short")]
|
---|
194 | [TestCategory("ProblemTest")]
|
---|
195 | public void NumberIo() {
|
---|
196 | TestProgram(
|
---|
197 | PushParser.ParseProgram("IN1 IN2 FLOAT.FROMINTEGER FLOAT.+ PRINT.PRINTFLOAT"),
|
---|
198 | new NumberIO());
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | [TestMethod]
|
---|
203 | [TestProperty("Time", "Short")]
|
---|
204 | [TestCategory("ProblemTest")]
|
---|
205 | public void PigLatin() {
|
---|
206 | TestProgram(
|
---|
207 | PushParser.ParseProgram("@( IN1 STRING.SPLIT STRING.STACKDEPTH 0 INTEGER.= EXEC.WHEN EXEC.FLUSH STRING.STACKDEPTH EXEC.DO*TIMES ( STRING.DUP STRING.FIRST CHAR.ALLFROMSTRING CHAR.DUP \"aeiou\" STRING.CONTAINSCHAR EXEC.IF ( CHAR.POP ) ( STRING.REST STRING.CONJCHAR ) \"ay\" STRING.CONCAT STRING.STACKDEPTH 1 INTEGER.> EXEC.WHEN ( ' ' STRING.CONJCHAR ) PRINT.PRINTSTRING ) )"),
|
---|
208 | new PigLatin());
|
---|
209 | }
|
---|
210 |
|
---|
211 | [TestMethod]
|
---|
212 | [TestProperty("Time", "Short")]
|
---|
213 | [TestCategory("ProblemTest")]
|
---|
214 | public void ReplaceSpaceWithNewLine() {
|
---|
215 |
|
---|
216 | TestProgram(
|
---|
217 | PushParser.ParseProgram("IN1 STRING.DUP 0 STRING.ITERATE ( CHAR.DUP ' ' CHAR.= EXEC.IF ( CHAR.POP '\n' ) INTEGER.INC PRINT.PRINTCHAR )"),
|
---|
218 | new ReplaceSpaceWithNewline());
|
---|
219 | }
|
---|
220 |
|
---|
221 | [TestMethod]
|
---|
222 | [TestProperty("Time", "Short")]
|
---|
223 | [TestCategory("ProblemTest")]
|
---|
224 | public void ScrabbleScore() {
|
---|
225 | TestProgram(
|
---|
226 | PushParser.ParseProgram("( IN1 STRING.ITERATE ( INTEGER.FROMCHAR INTEGER.DUP INTEGER.DUP 96 INTEGER.> 123 INTEGER.< BOOLEAN.AND EXEC.WHEN ( 32 INTEGER.- ) 65 INTEGER.- INTEGER.DUP INTEGER.DUP 0 INTEGER.>= 26 INTEGER.< BOOLEAN.AND EXEC.IF ( [1 3 3 2 1 4 2 4 1 8 5 1 3 1 1 3 10 1 1 1 1 4 4 8 4 10] INTEGER[].NTH INTEGER.+ ) ( INTEGER.POP ) ) )"),
|
---|
227 | new ScrabbleScore());
|
---|
228 | }
|
---|
229 |
|
---|
230 | [TestMethod]
|
---|
231 | [TestProperty("Time", "Short")]
|
---|
232 | [TestCategory("ProblemTest")]
|
---|
233 | public void Smallest() {
|
---|
234 | TestProgram(
|
---|
235 | PushParser.ParseProgram("( IN1 IN2 IN3 IN4 3 EXEC.DO*TIMES INTEGER.MIN )"),
|
---|
236 | new Smallest());
|
---|
237 | }
|
---|
238 |
|
---|
239 | [TestMethod]
|
---|
240 | [TestProperty("Time", "Short")]
|
---|
241 | [TestCategory("ProblemTest")]
|
---|
242 | public void SmallOrLarge() {
|
---|
243 | TestProgram(
|
---|
244 | PushParser.ParseProgram(
|
---|
245 | @"IN1
|
---|
246 | INTEGER.DUP 1000 INTEGER.< 2000 INTEGER.>=
|
---|
247 | EXEC.WHEN ""large""
|
---|
248 | EXEC.WHEN ""small""
|
---|
249 | STRING.EMPTY
|
---|
250 | EXEC.WHEN """"
|
---|
251 | PRINT.PRINTSTRING"),
|
---|
252 | new SmallOrLarge());
|
---|
253 | }
|
---|
254 |
|
---|
255 | [TestMethod]
|
---|
256 | [TestProperty("Time", "Short")]
|
---|
257 | [TestCategory("ProblemTest")]
|
---|
258 | public void StringDifferences() {
|
---|
259 | TestProgram(
|
---|
260 | PushParser.ParseProgram(
|
---|
261 | @"IN1 IN2
|
---|
262 | CHAR.ALLFROMSTRING 0 STRING.ITERATE (
|
---|
263 | CHAR.DUP 2 CHAR.YANKDUP CHAR.= BOOLEAN.NOT EXEC.IF (
|
---|
264 | INTEGER.DUP PRINT.PRINTINTEGER
|
---|
265 | ' ' PRINT.PRINTCHAR PRINT.PRINTCHAR
|
---|
266 | ' ' PRINT.PRINTCHAR PRINT.PRINTCHAR
|
---|
267 | PRINT.NEWLINE
|
---|
268 | )
|
---|
269 | ( CHAR.POP CHAR.POP )
|
---|
270 | INTEGER.INC )"),
|
---|
271 | new StringDifferences());
|
---|
272 | }
|
---|
273 |
|
---|
274 | [TestMethod]
|
---|
275 | [TestProperty("Time", "Short")]
|
---|
276 | [TestCategory("ProblemTest")]
|
---|
277 | public void StringLengthsBackwards() {
|
---|
278 | TestProgram(
|
---|
279 | PushParser.ParseProgram(@"IN1 STRING[].ITERATE ( STRING.LENGTH PRINT.NEWLINE PRINT.PRINTINTEGER )"),
|
---|
280 | new StringLengthsBackwards());
|
---|
281 | }
|
---|
282 |
|
---|
283 | [TestMethod]
|
---|
284 | [TestProperty("Time", "Short")]
|
---|
285 | [TestCategory("ProblemTest")]
|
---|
286 | public void SumOfSquares() {
|
---|
287 | TestProgram(
|
---|
288 | PushParser.ParseProgram(@"( IN1 EXEC.DO*COUNT ( INTEGER.DUP INTEGER.* INTEGER.+ ) )"),
|
---|
289 | new SumOfSquares());
|
---|
290 | }
|
---|
291 |
|
---|
292 | [TestMethod]
|
---|
293 | [TestProperty("Time", "Short")]
|
---|
294 | [TestCategory("ProblemTest")]
|
---|
295 | public void SuperAnagrams() {
|
---|
296 | TestProgram(
|
---|
297 | PushParser.ParseProgram(@"( IN1 IN2 STRING.SWAP STRING.DUP STRING.ITERATE ( CHAR.DUP STRING.DUP STRING.OCCURRENCESOFCHAR 1 STRING.YANKDUP STRING.OCCURRENCESOFCHAR INTEGER.> EXEC.WHEN ( false EXEC.FLUSH ) ) true )"),
|
---|
298 | new SuperAnagrams());
|
---|
299 | }
|
---|
300 |
|
---|
301 | [TestMethod]
|
---|
302 | [TestProperty("Time", "Short")]
|
---|
303 | [TestCategory("ProblemTest")]
|
---|
304 | public void Syllables() {
|
---|
305 | TestProgram(
|
---|
306 | PushParser.ParseProgram("( IN1 \"aeiouy\" 0 STRING.ITERATE ( STRING.DUP STRING.OCCURRENCESOFCHAR INTEGER.+ ) \"The number of syllables is \" PRINT.PRINTSTRING PRINT.PRINTINTEGER )"),
|
---|
307 | new Syllables());
|
---|
308 | }
|
---|
309 |
|
---|
310 | [TestMethod]
|
---|
311 | [TestProperty("Time", "Short")]
|
---|
312 | [TestCategory("ProblemTest")]
|
---|
313 | public void VectorAverage() {
|
---|
314 | TestProgram(
|
---|
315 | PushParser.ParseProgram("( IN1 FLOAT[].DUP FLOAT[].LENGTH FLOAT[].ITERATE FLOAT.+ FLOAT.FROMINTEGER FLOAT./ )"),
|
---|
316 | new VectorAverage());
|
---|
317 | }
|
---|
318 |
|
---|
319 | [TestMethod]
|
---|
320 | [TestProperty("Time", "Short")]
|
---|
321 | [TestCategory("ProblemTest")]
|
---|
322 | public void VectorSummed() {
|
---|
323 | TestProgram(
|
---|
324 | PushParser.ParseProgram(@"( IN1 IN2 INTEGER[].PUSHALL INTEGER[].DUP INTEGER[].LENGTH INTEGER.DEC EXEC.DO*COUNT ( INTEGER.DUP INTEGER[].DUP INTEGER[].NTH INTEGER.SWAP INTEGER.ROT INTEGER.+ INTEGER[].SET ) )"),
|
---|
325 | new VectorSummed());
|
---|
326 | }
|
---|
327 |
|
---|
328 | [TestMethod]
|
---|
329 | [TestProperty("Time", "Short")]
|
---|
330 | [TestCategory("ProblemTest")]
|
---|
331 | public void WallisPi() {
|
---|
332 | TestProgram(
|
---|
333 | PushParser.ParseProgram(@"( IN1 2 3 INTEGER.ROT INTEGER.ROT EXEC.DO*TIMES ( 2 EXEC.DO*TIMES ( 1 INTEGER.YANKDUP 1 INTEGER.YANKDUP ) FLOAT.FROMINTEGER FLOAT.FROMINTEGER FLOAT.SWAP FLOAT./ FLOAT.* INTEGER.< EXEC.IF ( INTEGER.SWAP 2 INTEGER.+ INTEGER.SWAP ) ( 2 INTEGER.+ ) ) )"),
|
---|
334 | new WallisPi());
|
---|
335 | }
|
---|
336 |
|
---|
337 | [TestMethod]
|
---|
338 | [TestProperty("Time", "Short")]
|
---|
339 | [TestCategory("ProblemTest")]
|
---|
340 | public void WordStats() {
|
---|
341 | TestProgram(
|
---|
342 | PushParser.ParseProgram("( IN1 STRING.DUP STRING.SPLIT STRING.STACKDEPTH 1 INTEGER.= BOOLEAN.NOT EXEC.WHEN ( true EXEC.WHILE ( STRING.LENGTH INTEGER.MAX STRING.STACKDEPTH 1 INTEGER.= BOOLEAN.NOT ) [0] 2 INTEGER.- INTEGER.DUP 0 INTEGER.>= EXEC.WHEN ( INTEGER.INC EXEC.DO*TIMES ( 0 INTEGER[].CONJ ) ) STRING.DUP STRING.SPLIT STRING.STACKDEPTH 1 INTEGER.> EXEC.WHILE ( STRING.LENGTH INTEGER.DEC INTEGER.DUP INTEGER[].DUP INTEGER[].NTH INTEGER.INC INTEGER[].SET STRING.STACKDEPTH 1 INTEGER.> ) INTEGER[].DUP INTEGER[].LENGTH INTEGER.DEC EXEC.DO*COUNT ( PRINT.NEWLINE \"words of length \" PRINT.PRINTSTRING INTEGER.DUP INTEGER.INC PRINT.PRINTINTEGER \": \" PRINT.PRINTSTRING INTEGER[].DUP INTEGER[].NTH PRINT.PRINTINTEGER ) \'.\' STRING.DUP STRING.OCCURRENCESOFCHAR \'!\' STRING.DUP STRING.OCCURRENCESOFCHAR INTEGER.+ \'?\' STRING.DUP STRING.OCCURRENCESOFCHAR INTEGER.+ INTEGER.DUP PRINT.NEWLINE \"number of sentences: \" PRINT.PRINTSTRING PRINT.PRINTINTEGER STRING.SPLIT STRING.STACKDEPTH FLOAT.FROMINTEGER FLOAT.FROMINTEGER FLOAT./ PRINT.NEWLINE \"average sentence length: \" PRINT.PRINTSTRING PRINT.PRINTFLOAT ) )"),
|
---|
343 | new WordStats(),
|
---|
344 | "0.0#########");
|
---|
345 | }
|
---|
346 |
|
---|
347 | [TestMethod]
|
---|
348 | [TestProperty("Time", "Short")]
|
---|
349 | [TestCategory("ProblemTest")]
|
---|
350 | public void XWordLines() {
|
---|
351 | TestProgram(
|
---|
352 | PushParser.ParseProgram(@"( IN1 IN2 STRING.SPLIT STRING.EMPTY BOOLEAN.NOT INTEGER.DUP 1 INTEGER.= EXEC.IF ( EXEC.WHILE ( PRINT.NEWLINE PRINT.PRINTSTRING STRING.EMPTY BOOLEAN.NOT ) ) ( 2 INTEGER.- EXEC.WHILE ( STRING.STACKDEPTH 2 INTEGER.- 1 INTEGER.YANKDUP INTEGER.MIN INTEGER.DUP 0 INTEGER.>= EXEC.IF ( INTEGER.INC EXEC.DO*TIMES ( ' ' STRING.CONJCHAR STRING.SWAP STRING.CONCAT ) PRINT.NEWLINE PRINT.PRINTSTRING STRING.EMPTY BOOLEAN.NOT ) ( PRINT.NEWLINE PRINT.PRINTSTRING STRING.EMPTY BOOLEAN.NOT ) ) ) )"),
|
---|
353 | new XWordLines());
|
---|
354 | }
|
---|
355 | }
|
---|
356 | }
|
---|