1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.IO;
|
---|
24 | using HeuristicLab.Problems.DataAnalysis;
|
---|
25 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
26 | namespace HeuristicLab.Problems.DataAnalysis_3_4.Tests {
|
---|
27 |
|
---|
28 | [TestClass()]
|
---|
29 | public class TableFileParserTest {
|
---|
30 |
|
---|
31 | [TestMethod]
|
---|
32 | public void ParseCSV() {
|
---|
33 | string tempFileName = Path.GetTempFileName();
|
---|
34 | WriteToFile(tempFileName,
|
---|
35 | @"0.00, 0.00, 0.00, 3.14
|
---|
36 | 0.00, 0.00, 0.00, 0.00
|
---|
37 | 0.00, 0.00, 0.00, 0.00
|
---|
38 | 0.00, 0.00, 0.00, 0.00
|
---|
39 | 0.00, 0.00, 0.00, 0.00
|
---|
40 | 0.00, 0.00, 0.00, 0.00");
|
---|
41 | TableFileParser parser = new TableFileParser();
|
---|
42 | try {
|
---|
43 | parser.Parse(tempFileName);
|
---|
44 | Assert.AreEqual(6, parser.Rows);
|
---|
45 | Assert.AreEqual(4, parser.Columns);
|
---|
46 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
47 | }
|
---|
48 | finally {
|
---|
49 | File.Delete(tempFileName);
|
---|
50 | }
|
---|
51 | }
|
---|
52 | [TestMethod]
|
---|
53 | public void ParseCSVWithNames() {
|
---|
54 | string tempFileName = Path.GetTempFileName();
|
---|
55 | WriteToFile(tempFileName,
|
---|
56 | @"x01, x02, x03, x04
|
---|
57 | 0.00, 0.00, 0.00, 3.14
|
---|
58 | 0.00, 0.00, 0.00, 0.00
|
---|
59 | 0.00, 0.00, 0.00, 0.00
|
---|
60 | 0.00, 0.00, 0.00, 0.00
|
---|
61 | 0.00, 0.00, 0.00, 0.00
|
---|
62 | 0.00, 0.00, 0.00, 0.00");
|
---|
63 | TableFileParser parser = new TableFileParser();
|
---|
64 | try {
|
---|
65 | parser.Parse(tempFileName);
|
---|
66 | Assert.AreEqual(6, parser.Rows);
|
---|
67 | Assert.AreEqual(4, parser.Columns);
|
---|
68 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
69 | }
|
---|
70 | finally {
|
---|
71 | File.Delete(tempFileName);
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | [TestMethod]
|
---|
76 | public void ParseGermanCSV() {
|
---|
77 | string tempFileName = Path.GetTempFileName();
|
---|
78 | WriteToFile(tempFileName,
|
---|
79 | @"0,00; 0,00; 0,00; 3,14
|
---|
80 | 0,00; 0,00; 0,00; 0,00
|
---|
81 | 0,00; 0,00; 0,00; 0,00
|
---|
82 | 0,00; 0,00; 0,00; 0,00
|
---|
83 | 0,00; 0,00; 0,00; 0,00
|
---|
84 | 0,00; 0,00; 0,00; 0,00");
|
---|
85 | TableFileParser parser = new TableFileParser();
|
---|
86 | try {
|
---|
87 | parser.Parse(tempFileName);
|
---|
88 | Assert.AreEqual(6, parser.Rows);
|
---|
89 | Assert.AreEqual(4, parser.Columns);
|
---|
90 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
91 | }
|
---|
92 | finally {
|
---|
93 | File.Delete(tempFileName);
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | [TestMethod]
|
---|
98 | public void ParseGermanCSVWithNames() {
|
---|
99 | string tempFileName = Path.GetTempFileName();
|
---|
100 | WriteToFile(tempFileName,
|
---|
101 | @"x01; x02; x03; x04
|
---|
102 | 0,00; 0,00; 0,00; 3,14
|
---|
103 | 0,00; 0,00; 0,00; 0,00
|
---|
104 | 0,00; 0,00; 0,00; 0,00
|
---|
105 | 0,00; 0,00; 0,00; 0,00
|
---|
106 | 0,00; 0,00; 0,00; 0,00
|
---|
107 | 0,00; 0,00; 0,00; 0,00");
|
---|
108 | TableFileParser parser = new TableFileParser();
|
---|
109 | try {
|
---|
110 | parser.Parse(tempFileName);
|
---|
111 | Assert.AreEqual(6, parser.Rows);
|
---|
112 | Assert.AreEqual(4, parser.Columns);
|
---|
113 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
114 | }
|
---|
115 | finally {
|
---|
116 | File.Delete(tempFileName);
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | [TestMethod]
|
---|
121 | public void ParseGermanCSVWithoutCommas() {
|
---|
122 | string tempFileName = Path.GetTempFileName();
|
---|
123 | WriteToFile(tempFileName,
|
---|
124 | @"0; 0; 0; 3
|
---|
125 | 0; 0; 0; 0
|
---|
126 | 0; 0; 0; 0
|
---|
127 | 0; 0; 0; 0
|
---|
128 | 0; 0; 0; 0
|
---|
129 | 0; 0; 0; 0");
|
---|
130 | TableFileParser parser = new TableFileParser();
|
---|
131 | try {
|
---|
132 | parser.Parse(tempFileName);
|
---|
133 | Assert.AreEqual(6, parser.Rows);
|
---|
134 | Assert.AreEqual(4, parser.Columns);
|
---|
135 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
136 | }
|
---|
137 | finally {
|
---|
138 | File.Delete(tempFileName);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | [TestMethod]
|
---|
142 | public void ParseGermanCSVWithoutCommasWithNames() {
|
---|
143 | string tempFileName = Path.GetTempFileName();
|
---|
144 | WriteToFile(tempFileName,
|
---|
145 | @"x01; x02; x03; x04
|
---|
146 | 0; 0; 0; 3
|
---|
147 | 0; 0; 0; 0
|
---|
148 | 0; 0; 0; 0
|
---|
149 | 0; 0; 0; 0
|
---|
150 | 0; 0; 0; 0
|
---|
151 | 0; 0; 0; 0");
|
---|
152 | TableFileParser parser = new TableFileParser();
|
---|
153 | try {
|
---|
154 | parser.Parse(tempFileName);
|
---|
155 | Assert.AreEqual(6, parser.Rows);
|
---|
156 | Assert.AreEqual(4, parser.Columns);
|
---|
157 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
158 | }
|
---|
159 | finally {
|
---|
160 | File.Delete(tempFileName);
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | [TestMethod]
|
---|
165 | public void ParseEnglishCSVWithoutCommas() {
|
---|
166 | string tempFileName = Path.GetTempFileName();
|
---|
167 | WriteToFile(tempFileName,
|
---|
168 | @"0, 0, 0, 3
|
---|
169 | 0, 0, 0, 0
|
---|
170 | 0, 0, 0, 0
|
---|
171 | 0, 0, 0, 0
|
---|
172 | 0, 0, 0, 0
|
---|
173 | 0, 0, 0, 0");
|
---|
174 | TableFileParser parser = new TableFileParser();
|
---|
175 | try {
|
---|
176 | parser.Parse(tempFileName);
|
---|
177 | Assert.AreEqual(6, parser.Rows);
|
---|
178 | Assert.AreEqual(4, parser.Columns);
|
---|
179 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
180 | }
|
---|
181 | finally {
|
---|
182 | File.Delete(tempFileName);
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | [TestMethod]
|
---|
187 | public void ParseEnglishCSVWithoutCommasWithoutSpace() {
|
---|
188 | string tempFileName = Path.GetTempFileName();
|
---|
189 | WriteToFile(tempFileName,
|
---|
190 | @"0,0,0,3
|
---|
191 | 0,0,0,0
|
---|
192 | 0,0,0,0
|
---|
193 | 0,0,0,0
|
---|
194 | 0,0,0,0
|
---|
195 | 0,0,0,0");
|
---|
196 | TableFileParser parser = new TableFileParser();
|
---|
197 | try {
|
---|
198 | parser.Parse(tempFileName);
|
---|
199 | Assert.AreEqual(6, parser.Rows);
|
---|
200 | Assert.AreEqual(4, parser.Columns);
|
---|
201 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
202 | }
|
---|
203 | finally {
|
---|
204 | File.Delete(tempFileName);
|
---|
205 | }
|
---|
206 | }
|
---|
207 |
|
---|
208 | [TestMethod]
|
---|
209 | public void ParseEnglishCSVWithoutCommasWithNames() {
|
---|
210 | string tempFileName = Path.GetTempFileName();
|
---|
211 | WriteToFile(tempFileName,
|
---|
212 | @"x01, x02, x03, x04
|
---|
213 | 0, 0, 0, 3
|
---|
214 | 0, 0, 0, 0
|
---|
215 | 0, 0, 0, 0
|
---|
216 | 0, 0, 0, 0
|
---|
217 | 0, 0, 0, 0
|
---|
218 | 0, 0, 0, 0");
|
---|
219 | TableFileParser parser = new TableFileParser();
|
---|
220 | try {
|
---|
221 | parser.Parse(tempFileName);
|
---|
222 | Assert.AreEqual(6, parser.Rows);
|
---|
223 | Assert.AreEqual(4, parser.Columns);
|
---|
224 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
225 | }
|
---|
226 | finally {
|
---|
227 | File.Delete(tempFileName);
|
---|
228 | }
|
---|
229 | }
|
---|
230 |
|
---|
231 | [TestMethod]
|
---|
232 | public void ParseEnglishCSVWithoutCommasWithoutSpacesWithNames() {
|
---|
233 | string tempFileName = Path.GetTempFileName();
|
---|
234 | WriteToFile(tempFileName,
|
---|
235 | @"x01,x02,x03,x04
|
---|
236 | 0,0,0,3
|
---|
237 | 0,0,0,0
|
---|
238 | 0,0,0,0
|
---|
239 | 0,0,0,0
|
---|
240 | 0,0,0,0
|
---|
241 | 0,0,0,0");
|
---|
242 | TableFileParser parser = new TableFileParser();
|
---|
243 | try {
|
---|
244 | parser.Parse(tempFileName);
|
---|
245 | Assert.AreEqual(6, parser.Rows);
|
---|
246 | Assert.AreEqual(4, parser.Columns);
|
---|
247 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
248 | }
|
---|
249 | finally {
|
---|
250 | File.Delete(tempFileName);
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 |
|
---|
255 | [TestMethod]
|
---|
256 | public void ParseGermanTabSeparated() {
|
---|
257 | string tempFileName = Path.GetTempFileName();
|
---|
258 | WriteToFile(tempFileName,
|
---|
259 | "0,00\t 0,00\t 0,00\t 3,14" + Environment.NewLine +
|
---|
260 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
261 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
262 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
263 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
264 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
265 | TableFileParser parser = new TableFileParser();
|
---|
266 | try {
|
---|
267 | parser.Parse(tempFileName);
|
---|
268 | Assert.AreEqual(6, parser.Rows);
|
---|
269 | Assert.AreEqual(4, parser.Columns);
|
---|
270 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
271 | }
|
---|
272 | finally {
|
---|
273 | File.Delete(tempFileName);
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 | [TestMethod]
|
---|
278 | public void ParseGermanTabSeparatedWithNames() {
|
---|
279 | string tempFileName = Path.GetTempFileName();
|
---|
280 | WriteToFile(tempFileName,
|
---|
281 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
282 | "0,00\t 0,00\t 0,00\t 3,14" + Environment.NewLine +
|
---|
283 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
284 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
285 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
286 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
287 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
288 | TableFileParser parser = new TableFileParser();
|
---|
289 | try {
|
---|
290 | parser.Parse(tempFileName);
|
---|
291 | Assert.AreEqual(6, parser.Rows);
|
---|
292 | Assert.AreEqual(4, parser.Columns);
|
---|
293 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
294 | }
|
---|
295 | finally {
|
---|
296 | File.Delete(tempFileName);
|
---|
297 | }
|
---|
298 | }
|
---|
299 |
|
---|
300 | [TestMethod]
|
---|
301 | public void ParseEnglishTabSeparated() {
|
---|
302 | string tempFileName = Path.GetTempFileName();
|
---|
303 | WriteToFile(tempFileName,
|
---|
304 | "0.00\t 0.00\t 0.00\t 3.14" + Environment.NewLine +
|
---|
305 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
306 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
307 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
308 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
309 | "0.00\t 0.00\t 0.00\t 0.00");
|
---|
310 | TableFileParser parser = new TableFileParser();
|
---|
311 | try {
|
---|
312 | parser.Parse(tempFileName);
|
---|
313 | Assert.AreEqual(6, parser.Rows);
|
---|
314 | Assert.AreEqual(4, parser.Columns);
|
---|
315 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
316 | }
|
---|
317 | finally {
|
---|
318 | File.Delete(tempFileName);
|
---|
319 | }
|
---|
320 | }
|
---|
321 | [TestMethod]
|
---|
322 | public void ParseEnglishTabSeparatedWithNames() {
|
---|
323 | string tempFileName = Path.GetTempFileName();
|
---|
324 | WriteToFile(tempFileName,
|
---|
325 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
326 | "0.00\t 0.00\t 0.00\t 3.14" + Environment.NewLine +
|
---|
327 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
328 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
329 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
330 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
331 | "0.00\t 0.00\t 0.00\t 0.00");
|
---|
332 | TableFileParser parser = new TableFileParser();
|
---|
333 | try {
|
---|
334 | parser.Parse(tempFileName);
|
---|
335 | Assert.AreEqual(6, parser.Rows);
|
---|
336 | Assert.AreEqual(4, parser.Columns);
|
---|
337 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
338 | }
|
---|
339 | finally {
|
---|
340 | File.Delete(tempFileName);
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 | [TestMethod]
|
---|
345 | public void ParseTabSeparatedWithoutCommas() {
|
---|
346 | string tempFileName = Path.GetTempFileName();
|
---|
347 | WriteToFile(tempFileName,
|
---|
348 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
349 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
350 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
351 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
352 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
353 | "0\t 0\t 0\t 0");
|
---|
354 | TableFileParser parser = new TableFileParser();
|
---|
355 | try {
|
---|
356 | parser.Parse(tempFileName);
|
---|
357 | Assert.AreEqual(6, parser.Rows);
|
---|
358 | Assert.AreEqual(4, parser.Columns);
|
---|
359 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
360 | }
|
---|
361 | finally {
|
---|
362 | File.Delete(tempFileName);
|
---|
363 | }
|
---|
364 | }
|
---|
365 | [TestMethod]
|
---|
366 | public void ParseTabSeparatedWithoutCommasWithNames() {
|
---|
367 | string tempFileName = Path.GetTempFileName();
|
---|
368 | WriteToFile(tempFileName,
|
---|
369 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
370 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
371 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
372 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
373 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
374 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
375 | "0\t 0\t 0\t 0");
|
---|
376 | TableFileParser parser = new TableFileParser();
|
---|
377 | try {
|
---|
378 | parser.Parse(tempFileName);
|
---|
379 | Assert.AreEqual(6, parser.Rows);
|
---|
380 | Assert.AreEqual(4, parser.Columns);
|
---|
381 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
382 | }
|
---|
383 | finally {
|
---|
384 | File.Delete(tempFileName);
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | [TestMethod]
|
---|
389 | public void ParseWithEmtpyLines() {
|
---|
390 | string tempFileName = Path.GetTempFileName();
|
---|
391 | WriteToFile(tempFileName,
|
---|
392 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
393 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
394 | Environment.NewLine +
|
---|
395 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
396 | " " + Environment.NewLine +
|
---|
397 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
398 | "0\t 0\t 0\t 0" + Environment.NewLine + Environment.NewLine);
|
---|
399 | TableFileParser parser = new TableFileParser();
|
---|
400 | try {
|
---|
401 | parser.Parse(tempFileName);
|
---|
402 | Assert.AreEqual(4, parser.Rows);
|
---|
403 | Assert.AreEqual(4, parser.Columns);
|
---|
404 | }
|
---|
405 | finally {
|
---|
406 | File.Delete(tempFileName);
|
---|
407 | }
|
---|
408 | }
|
---|
409 |
|
---|
410 | [TestMethod]
|
---|
411 | public void ParseGermanSpaceSeparated() {
|
---|
412 | string tempFileName = Path.GetTempFileName();
|
---|
413 | WriteToFile(tempFileName,
|
---|
414 | @"0,00 0,00 0,00 3,14
|
---|
415 | 0,00 0,00 0,00 0,00
|
---|
416 | 0,00 0,00 0,00 0,00
|
---|
417 | 0,00 0,00 0,00 0,00
|
---|
418 | 0,00 0,00 0,00 0,00
|
---|
419 | 0,00 0,00 0,00 0,00");
|
---|
420 | TableFileParser parser = new TableFileParser();
|
---|
421 | try {
|
---|
422 | parser.Parse(tempFileName);
|
---|
423 | Assert.AreEqual(6, parser.Rows);
|
---|
424 | Assert.AreEqual(4, parser.Columns);
|
---|
425 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
426 | }
|
---|
427 | finally {
|
---|
428 | File.Delete(tempFileName);
|
---|
429 | }
|
---|
430 | }
|
---|
431 | [TestMethod]
|
---|
432 | public void ParseGermanSpaceSeparatedWithNames() {
|
---|
433 | string tempFileName = Path.GetTempFileName();
|
---|
434 | WriteToFile(tempFileName,
|
---|
435 | @"x01 x02 x03 x04
|
---|
436 | 0,00 0,00 0,00 3,14
|
---|
437 | 0,00 0,00 0,00 0,00
|
---|
438 | 0,00 0,00 0,00 0,00
|
---|
439 | 0,00 0,00 0,00 0,00
|
---|
440 | 0,00 0,00 0,00 0,00
|
---|
441 | 0,00 0,00 0,00 0,00");
|
---|
442 | TableFileParser parser = new TableFileParser();
|
---|
443 | try {
|
---|
444 | parser.Parse(tempFileName);
|
---|
445 | Assert.AreEqual(6, parser.Rows);
|
---|
446 | Assert.AreEqual(4, parser.Columns);
|
---|
447 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
448 | }
|
---|
449 | finally {
|
---|
450 | File.Delete(tempFileName);
|
---|
451 | }
|
---|
452 | }
|
---|
453 |
|
---|
454 | [TestMethod]
|
---|
455 | public void ParseEnglishSpaceSeparated() {
|
---|
456 | string tempFileName = Path.GetTempFileName();
|
---|
457 | WriteToFile(tempFileName,
|
---|
458 | @"0.00 0.00 0.00 3.14
|
---|
459 | 0.00 0.00 0.00 0.00
|
---|
460 | 0.00 0.00 0.00 0.00
|
---|
461 | 0.00 0.00 0.00 0.00
|
---|
462 | 0.00 0.00 0.00 0.00
|
---|
463 | 0.00 0.00 0.00 0.00");
|
---|
464 | TableFileParser parser = new TableFileParser();
|
---|
465 | try {
|
---|
466 | parser.Parse(tempFileName);
|
---|
467 | Assert.AreEqual(6, parser.Rows);
|
---|
468 | Assert.AreEqual(4, parser.Columns);
|
---|
469 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
470 | }
|
---|
471 | finally {
|
---|
472 | File.Delete(tempFileName);
|
---|
473 | }
|
---|
474 | }
|
---|
475 | [TestMethod]
|
---|
476 | public void ParseEnglishSpaceSeparatedWithNames() {
|
---|
477 | string tempFileName = Path.GetTempFileName();
|
---|
478 | WriteToFile(tempFileName,
|
---|
479 | @"x01 x02 x03 x04
|
---|
480 | 0.00 0.00 0.00 3.14
|
---|
481 | 0.00 0.00 0.00 0.00
|
---|
482 | 0.00 0.00 0.00 0.00
|
---|
483 | 0.00 0.00 0.00 0.00
|
---|
484 | 0.00 0.00 0.00 0.00
|
---|
485 | 0.00 0.00 0.00 0.00");
|
---|
486 | TableFileParser parser = new TableFileParser();
|
---|
487 | try {
|
---|
488 | parser.Parse(tempFileName);
|
---|
489 | Assert.AreEqual(6, parser.Rows);
|
---|
490 | Assert.AreEqual(4, parser.Columns);
|
---|
491 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
492 | }
|
---|
493 | finally {
|
---|
494 | File.Delete(tempFileName);
|
---|
495 | }
|
---|
496 | }
|
---|
497 |
|
---|
498 | [TestMethod]
|
---|
499 | public void ParseSpaceSeparatedWithoutCommas() {
|
---|
500 | string tempFileName = Path.GetTempFileName();
|
---|
501 | WriteToFile(tempFileName,
|
---|
502 | @"0 0 0 3
|
---|
503 | 0 0 0 0
|
---|
504 | 0 0 0 0
|
---|
505 | 0 0 0 0
|
---|
506 | 0 0 0 0
|
---|
507 | 0 0 0 0");
|
---|
508 | TableFileParser parser = new TableFileParser();
|
---|
509 | try {
|
---|
510 | parser.Parse(tempFileName);
|
---|
511 | Assert.AreEqual(6, parser.Rows);
|
---|
512 | Assert.AreEqual(4, parser.Columns);
|
---|
513 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
514 | }
|
---|
515 | finally {
|
---|
516 | File.Delete(tempFileName);
|
---|
517 | }
|
---|
518 | }
|
---|
519 | [TestMethod]
|
---|
520 | public void ParseSpaceSeparatedWithoutCommasWithNames() {
|
---|
521 | string tempFileName = Path.GetTempFileName();
|
---|
522 | WriteToFile(tempFileName,
|
---|
523 | @"x01 x02 x03 x04
|
---|
524 | 0 0 0 3
|
---|
525 | 0 0 0 0
|
---|
526 | 0 0 0 0
|
---|
527 | 0 0 0 0
|
---|
528 | 0 0 0 0
|
---|
529 | 0 0 0 0");
|
---|
530 | TableFileParser parser = new TableFileParser();
|
---|
531 | try {
|
---|
532 | parser.Parse(tempFileName);
|
---|
533 | Assert.AreEqual(6, parser.Rows);
|
---|
534 | Assert.AreEqual(4, parser.Columns);
|
---|
535 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
536 | }
|
---|
537 | finally {
|
---|
538 | File.Delete(tempFileName);
|
---|
539 | }
|
---|
540 | }
|
---|
541 |
|
---|
542 | private void WriteToFile(string fileName, string content) {
|
---|
543 | using (StreamWriter writer = new StreamWriter(fileName)) {
|
---|
544 | writer.Write(content);
|
---|
545 | }
|
---|
546 | }
|
---|
547 | }
|
---|
548 | }
|
---|