1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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.Instances.DataAnalysis;
|
---|
25 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Problems.DataAnalysis_3_4.Tests {
|
---|
28 |
|
---|
29 | [TestClass()]
|
---|
30 | public class TableFileParserTest {
|
---|
31 |
|
---|
32 | [TestMethod]
|
---|
33 | public void ParseCSV() {
|
---|
34 | string tempFileName = Path.GetTempFileName();
|
---|
35 | WriteToFile(tempFileName,
|
---|
36 | @"0.00, 0.00, 0.00, 3.14
|
---|
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 | 0.00, 0.00, 0.00, 0.00");
|
---|
42 | TableFileParser parser = new TableFileParser();
|
---|
43 | try {
|
---|
44 | parser.Parse(tempFileName);
|
---|
45 | Assert.AreEqual(6, parser.Rows);
|
---|
46 | Assert.AreEqual(4, parser.Columns);
|
---|
47 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
48 | }
|
---|
49 | finally {
|
---|
50 | File.Delete(tempFileName);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | [TestMethod]
|
---|
54 | public void ParseCSVWithNames() {
|
---|
55 | string tempFileName = Path.GetTempFileName();
|
---|
56 | WriteToFile(tempFileName,
|
---|
57 | @"x01, x02, x03, x04
|
---|
58 | 0.00, 0.00, 0.00, 3.14
|
---|
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 | 0.00, 0.00, 0.00, 0.00");
|
---|
64 | TableFileParser parser = new TableFileParser();
|
---|
65 | try {
|
---|
66 | parser.Parse(tempFileName);
|
---|
67 | Assert.AreEqual(6, parser.Rows);
|
---|
68 | Assert.AreEqual(4, parser.Columns);
|
---|
69 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
70 | }
|
---|
71 | finally {
|
---|
72 | File.Delete(tempFileName);
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | [TestMethod]
|
---|
77 | public void ParseGermanCSV() {
|
---|
78 | string tempFileName = Path.GetTempFileName();
|
---|
79 | WriteToFile(tempFileName,
|
---|
80 | @"0,00; 0,00; 0,00; 3,14
|
---|
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 | 0,00; 0,00; 0,00; 0,00");
|
---|
86 | TableFileParser parser = new TableFileParser();
|
---|
87 | try {
|
---|
88 | parser.Parse(tempFileName);
|
---|
89 | Assert.AreEqual(6, parser.Rows);
|
---|
90 | Assert.AreEqual(4, parser.Columns);
|
---|
91 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
92 | }
|
---|
93 | finally {
|
---|
94 | File.Delete(tempFileName);
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | [TestMethod]
|
---|
99 | public void ParseGermanCSVWithNames() {
|
---|
100 | string tempFileName = Path.GetTempFileName();
|
---|
101 | WriteToFile(tempFileName,
|
---|
102 | @"x01; x02; x03; x04
|
---|
103 | 0,00; 0,00; 0,00; 3,14
|
---|
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 | 0,00; 0,00; 0,00; 0,00");
|
---|
109 | TableFileParser parser = new TableFileParser();
|
---|
110 | try {
|
---|
111 | parser.Parse(tempFileName);
|
---|
112 | Assert.AreEqual(6, parser.Rows);
|
---|
113 | Assert.AreEqual(4, parser.Columns);
|
---|
114 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
115 | }
|
---|
116 | finally {
|
---|
117 | File.Delete(tempFileName);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | [TestMethod]
|
---|
122 | public void ParseGermanCSVWithoutCommas() {
|
---|
123 | string tempFileName = Path.GetTempFileName();
|
---|
124 | WriteToFile(tempFileName,
|
---|
125 | @"0; 0; 0; 3
|
---|
126 | 0; 0; 0; 0
|
---|
127 | 0; 0; 0; 0
|
---|
128 | 0; 0; 0; 0
|
---|
129 | 0; 0; 0; 0
|
---|
130 | 0; 0; 0; 0");
|
---|
131 | TableFileParser parser = new TableFileParser();
|
---|
132 | try {
|
---|
133 | parser.Parse(tempFileName);
|
---|
134 | Assert.AreEqual(6, parser.Rows);
|
---|
135 | Assert.AreEqual(4, parser.Columns);
|
---|
136 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
137 | }
|
---|
138 | finally {
|
---|
139 | File.Delete(tempFileName);
|
---|
140 | }
|
---|
141 | }
|
---|
142 | [TestMethod]
|
---|
143 | public void ParseGermanCSVWithoutCommasWithNames() {
|
---|
144 | string tempFileName = Path.GetTempFileName();
|
---|
145 | WriteToFile(tempFileName,
|
---|
146 | @"x01; x02; x03; x04
|
---|
147 | 0; 0; 0; 3
|
---|
148 | 0; 0; 0; 0
|
---|
149 | 0; 0; 0; 0
|
---|
150 | 0; 0; 0; 0
|
---|
151 | 0; 0; 0; 0
|
---|
152 | 0; 0; 0; 0");
|
---|
153 | TableFileParser parser = new TableFileParser();
|
---|
154 | try {
|
---|
155 | parser.Parse(tempFileName);
|
---|
156 | Assert.AreEqual(6, parser.Rows);
|
---|
157 | Assert.AreEqual(4, parser.Columns);
|
---|
158 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
159 | }
|
---|
160 | finally {
|
---|
161 | File.Delete(tempFileName);
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | [TestMethod]
|
---|
166 | public void ParseEnglishCSVWithoutCommas() {
|
---|
167 | string tempFileName = Path.GetTempFileName();
|
---|
168 | WriteToFile(tempFileName,
|
---|
169 | @"0, 0, 0, 3
|
---|
170 | 0, 0, 0, 0
|
---|
171 | 0, 0, 0, 0
|
---|
172 | 0, 0, 0, 0
|
---|
173 | 0, 0, 0, 0
|
---|
174 | 0, 0, 0, 0");
|
---|
175 | TableFileParser parser = new TableFileParser();
|
---|
176 | try {
|
---|
177 | parser.Parse(tempFileName);
|
---|
178 | Assert.AreEqual(6, parser.Rows);
|
---|
179 | Assert.AreEqual(4, parser.Columns);
|
---|
180 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
181 | }
|
---|
182 | finally {
|
---|
183 | File.Delete(tempFileName);
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | [TestMethod]
|
---|
188 | public void ParseEnglishCSVWithoutCommasWithoutSpace() {
|
---|
189 | string tempFileName = Path.GetTempFileName();
|
---|
190 | WriteToFile(tempFileName,
|
---|
191 | @"0,0,0,3
|
---|
192 | 0,0,0,0
|
---|
193 | 0,0,0,0
|
---|
194 | 0,0,0,0
|
---|
195 | 0,0,0,0
|
---|
196 | 0,0,0,0");
|
---|
197 | TableFileParser parser = new TableFileParser();
|
---|
198 | try {
|
---|
199 | parser.Parse(tempFileName);
|
---|
200 | Assert.AreEqual(6, parser.Rows);
|
---|
201 | Assert.AreEqual(4, parser.Columns);
|
---|
202 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
203 | }
|
---|
204 | finally {
|
---|
205 | File.Delete(tempFileName);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | [TestMethod]
|
---|
210 | public void ParseEnglishCSVWithoutCommasWithNames() {
|
---|
211 | string tempFileName = Path.GetTempFileName();
|
---|
212 | WriteToFile(tempFileName,
|
---|
213 | @"x01, x02, x03, x04
|
---|
214 | 0, 0, 0, 3
|
---|
215 | 0, 0, 0, 0
|
---|
216 | 0, 0, 0, 0
|
---|
217 | 0, 0, 0, 0
|
---|
218 | 0, 0, 0, 0
|
---|
219 | 0, 0, 0, 0");
|
---|
220 | TableFileParser parser = new TableFileParser();
|
---|
221 | try {
|
---|
222 | parser.Parse(tempFileName);
|
---|
223 | Assert.AreEqual(6, parser.Rows);
|
---|
224 | Assert.AreEqual(4, parser.Columns);
|
---|
225 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
226 | }
|
---|
227 | finally {
|
---|
228 | File.Delete(tempFileName);
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | [TestMethod]
|
---|
233 | public void ParseEnglishCSVWithoutCommasWithoutSpacesWithNames() {
|
---|
234 | string tempFileName = Path.GetTempFileName();
|
---|
235 | WriteToFile(tempFileName,
|
---|
236 | @"x01,x02,x03,x04
|
---|
237 | 0,0,0,3
|
---|
238 | 0,0,0,0
|
---|
239 | 0,0,0,0
|
---|
240 | 0,0,0,0
|
---|
241 | 0,0,0,0
|
---|
242 | 0,0,0,0");
|
---|
243 | TableFileParser parser = new TableFileParser();
|
---|
244 | try {
|
---|
245 | parser.Parse(tempFileName);
|
---|
246 | Assert.AreEqual(6, parser.Rows);
|
---|
247 | Assert.AreEqual(4, parser.Columns);
|
---|
248 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
249 | }
|
---|
250 | finally {
|
---|
251 | File.Delete(tempFileName);
|
---|
252 | }
|
---|
253 | }
|
---|
254 |
|
---|
255 |
|
---|
256 | [TestMethod]
|
---|
257 | public void ParseGermanTabSeparated() {
|
---|
258 | string tempFileName = Path.GetTempFileName();
|
---|
259 | WriteToFile(tempFileName,
|
---|
260 | "0,00\t 0,00\t 0,00\t 3,14" + 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" + Environment.NewLine +
|
---|
265 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
266 | TableFileParser parser = new TableFileParser();
|
---|
267 | try {
|
---|
268 | parser.Parse(tempFileName);
|
---|
269 | Assert.AreEqual(6, parser.Rows);
|
---|
270 | Assert.AreEqual(4, parser.Columns);
|
---|
271 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
272 | }
|
---|
273 | finally {
|
---|
274 | File.Delete(tempFileName);
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | [TestMethod]
|
---|
279 | public void ParseGermanTabSeparatedWithNames() {
|
---|
280 | string tempFileName = Path.GetTempFileName();
|
---|
281 | WriteToFile(tempFileName,
|
---|
282 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
283 | "0,00\t 0,00\t 0,00\t 3,14" + 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" + Environment.NewLine +
|
---|
288 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
289 | TableFileParser parser = new TableFileParser();
|
---|
290 | try {
|
---|
291 | parser.Parse(tempFileName);
|
---|
292 | Assert.AreEqual(6, parser.Rows);
|
---|
293 | Assert.AreEqual(4, parser.Columns);
|
---|
294 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
295 | }
|
---|
296 | finally {
|
---|
297 | File.Delete(tempFileName);
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 | [TestMethod]
|
---|
302 | public void ParseEnglishTabSeparated() {
|
---|
303 | string tempFileName = Path.GetTempFileName();
|
---|
304 | WriteToFile(tempFileName,
|
---|
305 | "0.00\t 0.00\t 0.00\t 3.14" + 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" + Environment.NewLine +
|
---|
310 | "0.00\t 0.00\t 0.00\t 0.00");
|
---|
311 | TableFileParser parser = new TableFileParser();
|
---|
312 | try {
|
---|
313 | parser.Parse(tempFileName);
|
---|
314 | Assert.AreEqual(6, parser.Rows);
|
---|
315 | Assert.AreEqual(4, parser.Columns);
|
---|
316 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
317 | }
|
---|
318 | finally {
|
---|
319 | File.Delete(tempFileName);
|
---|
320 | }
|
---|
321 | }
|
---|
322 | [TestMethod]
|
---|
323 | public void ParseEnglishTabSeparatedWithNames() {
|
---|
324 | string tempFileName = Path.GetTempFileName();
|
---|
325 | WriteToFile(tempFileName,
|
---|
326 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
327 | "0.00\t 0.00\t 0.00\t 3.14" + 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" + Environment.NewLine +
|
---|
332 | "0.00\t 0.00\t 0.00\t 0.00");
|
---|
333 | TableFileParser parser = new TableFileParser();
|
---|
334 | try {
|
---|
335 | parser.Parse(tempFileName);
|
---|
336 | Assert.AreEqual(6, parser.Rows);
|
---|
337 | Assert.AreEqual(4, parser.Columns);
|
---|
338 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
339 | }
|
---|
340 | finally {
|
---|
341 | File.Delete(tempFileName);
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | [TestMethod]
|
---|
346 | public void ParseTabSeparatedWithoutCommas() {
|
---|
347 | string tempFileName = Path.GetTempFileName();
|
---|
348 | WriteToFile(tempFileName,
|
---|
349 | "0\t 0\t 0\t 3" + 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" + Environment.NewLine +
|
---|
354 | "0\t 0\t 0\t 0");
|
---|
355 | TableFileParser parser = new TableFileParser();
|
---|
356 | try {
|
---|
357 | parser.Parse(tempFileName);
|
---|
358 | Assert.AreEqual(6, parser.Rows);
|
---|
359 | Assert.AreEqual(4, parser.Columns);
|
---|
360 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
361 | }
|
---|
362 | finally {
|
---|
363 | File.Delete(tempFileName);
|
---|
364 | }
|
---|
365 | }
|
---|
366 | [TestMethod]
|
---|
367 | public void ParseTabSeparatedWithoutCommasWithNames() {
|
---|
368 | string tempFileName = Path.GetTempFileName();
|
---|
369 | WriteToFile(tempFileName,
|
---|
370 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
371 | "0\t 0\t 0\t 3" + 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" + Environment.NewLine +
|
---|
376 | "0\t 0\t 0\t 0");
|
---|
377 | TableFileParser parser = new TableFileParser();
|
---|
378 | try {
|
---|
379 | parser.Parse(tempFileName);
|
---|
380 | Assert.AreEqual(6, parser.Rows);
|
---|
381 | Assert.AreEqual(4, parser.Columns);
|
---|
382 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
383 | }
|
---|
384 | finally {
|
---|
385 | File.Delete(tempFileName);
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | [TestMethod]
|
---|
390 | public void ParseWithEmtpyLines() {
|
---|
391 | string tempFileName = Path.GetTempFileName();
|
---|
392 | WriteToFile(tempFileName,
|
---|
393 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
394 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
395 | Environment.NewLine +
|
---|
396 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
397 | " " + Environment.NewLine +
|
---|
398 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
399 | "0\t 0\t 0\t 0" + Environment.NewLine + Environment.NewLine);
|
---|
400 | TableFileParser parser = new TableFileParser();
|
---|
401 | try {
|
---|
402 | parser.Parse(tempFileName);
|
---|
403 | Assert.AreEqual(4, parser.Rows);
|
---|
404 | Assert.AreEqual(4, parser.Columns);
|
---|
405 | }
|
---|
406 | finally {
|
---|
407 | File.Delete(tempFileName);
|
---|
408 | }
|
---|
409 | }
|
---|
410 |
|
---|
411 | [TestMethod]
|
---|
412 | public void ParseGermanSpaceSeparated() {
|
---|
413 | string tempFileName = Path.GetTempFileName();
|
---|
414 | WriteToFile(tempFileName,
|
---|
415 | @"0,00 0,00 0,00 3,14
|
---|
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 | 0,00 0,00 0,00 0,00");
|
---|
421 | TableFileParser parser = new TableFileParser();
|
---|
422 | try {
|
---|
423 | parser.Parse(tempFileName);
|
---|
424 | Assert.AreEqual(6, parser.Rows);
|
---|
425 | Assert.AreEqual(4, parser.Columns);
|
---|
426 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
427 | }
|
---|
428 | finally {
|
---|
429 | File.Delete(tempFileName);
|
---|
430 | }
|
---|
431 | }
|
---|
432 | [TestMethod]
|
---|
433 | public void ParseGermanSpaceSeparatedWithNames() {
|
---|
434 | string tempFileName = Path.GetTempFileName();
|
---|
435 | WriteToFile(tempFileName,
|
---|
436 | @"x01 x02 x03 x04
|
---|
437 | 0,00 0,00 0,00 3,14
|
---|
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 | 0,00 0,00 0,00 0,00");
|
---|
443 | TableFileParser parser = new TableFileParser();
|
---|
444 | try {
|
---|
445 | parser.Parse(tempFileName);
|
---|
446 | Assert.AreEqual(6, parser.Rows);
|
---|
447 | Assert.AreEqual(4, parser.Columns);
|
---|
448 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
449 | }
|
---|
450 | finally {
|
---|
451 | File.Delete(tempFileName);
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | [TestMethod]
|
---|
456 | public void ParseEnglishSpaceSeparated() {
|
---|
457 | string tempFileName = Path.GetTempFileName();
|
---|
458 | WriteToFile(tempFileName,
|
---|
459 | @"0.00 0.00 0.00 3.14
|
---|
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 | 0.00 0.00 0.00 0.00");
|
---|
465 | TableFileParser parser = new TableFileParser();
|
---|
466 | try {
|
---|
467 | parser.Parse(tempFileName);
|
---|
468 | Assert.AreEqual(6, parser.Rows);
|
---|
469 | Assert.AreEqual(4, parser.Columns);
|
---|
470 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
471 | }
|
---|
472 | finally {
|
---|
473 | File.Delete(tempFileName);
|
---|
474 | }
|
---|
475 | }
|
---|
476 | [TestMethod]
|
---|
477 | public void ParseEnglishSpaceSeparatedWithNames() {
|
---|
478 | string tempFileName = Path.GetTempFileName();
|
---|
479 | WriteToFile(tempFileName,
|
---|
480 | @"x01 x02 x03 x04
|
---|
481 | 0.00 0.00 0.00 3.14
|
---|
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 | 0.00 0.00 0.00 0.00");
|
---|
487 | TableFileParser parser = new TableFileParser();
|
---|
488 | try {
|
---|
489 | parser.Parse(tempFileName);
|
---|
490 | Assert.AreEqual(6, parser.Rows);
|
---|
491 | Assert.AreEqual(4, parser.Columns);
|
---|
492 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
493 | }
|
---|
494 | finally {
|
---|
495 | File.Delete(tempFileName);
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | [TestMethod]
|
---|
500 | public void ParseSpaceSeparatedWithoutCommas() {
|
---|
501 | string tempFileName = Path.GetTempFileName();
|
---|
502 | WriteToFile(tempFileName,
|
---|
503 | @"0 0 0 3
|
---|
504 | 0 0 0 0
|
---|
505 | 0 0 0 0
|
---|
506 | 0 0 0 0
|
---|
507 | 0 0 0 0
|
---|
508 | 0 0 0 0");
|
---|
509 | TableFileParser parser = new TableFileParser();
|
---|
510 | try {
|
---|
511 | parser.Parse(tempFileName);
|
---|
512 | Assert.AreEqual(6, parser.Rows);
|
---|
513 | Assert.AreEqual(4, parser.Columns);
|
---|
514 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
515 | }
|
---|
516 | finally {
|
---|
517 | File.Delete(tempFileName);
|
---|
518 | }
|
---|
519 | }
|
---|
520 | [TestMethod]
|
---|
521 | public void ParseSpaceSeparatedWithoutCommasWithNames() {
|
---|
522 | string tempFileName = Path.GetTempFileName();
|
---|
523 | WriteToFile(tempFileName,
|
---|
524 | @"x01 x02 x03 x04
|
---|
525 | 0 0 0 3
|
---|
526 | 0 0 0 0
|
---|
527 | 0 0 0 0
|
---|
528 | 0 0 0 0
|
---|
529 | 0 0 0 0
|
---|
530 | 0 0 0 0");
|
---|
531 | TableFileParser parser = new TableFileParser();
|
---|
532 | try {
|
---|
533 | parser.Parse(tempFileName);
|
---|
534 | Assert.AreEqual(6, parser.Rows);
|
---|
535 | Assert.AreEqual(4, parser.Columns);
|
---|
536 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
537 | }
|
---|
538 | finally {
|
---|
539 | File.Delete(tempFileName);
|
---|
540 | }
|
---|
541 | }
|
---|
542 |
|
---|
543 | private void WriteToFile(string fileName, string content) {
|
---|
544 | using (StreamWriter writer = new StreamWriter(fileName)) {
|
---|
545 | writer.Write(content);
|
---|
546 | }
|
---|
547 | }
|
---|
548 | }
|
---|
549 | }
|
---|