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.Globalization;
|
---|
24 | using System.IO;
|
---|
25 | using HeuristicLab.Problems.Instances;
|
---|
26 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
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 | NumberFormatInfo numberFormat;
|
---|
36 | DateTimeFormatInfo dateFormatInfo;
|
---|
37 | char separator;
|
---|
38 | WriteToFile(tempFileName,
|
---|
39 | @"0.00, 0.00, 0.00, 3.14
|
---|
40 | 0.00, 0.00, 0.00, 0.00
|
---|
41 | 0.00, 0.00, 0.00, 0.00
|
---|
42 | 0.00, 0.00, 0.00, 0.00
|
---|
43 | 0.00, 0.00, 0.00, 0.00
|
---|
44 | 0.00, 0.00, 0.00, 0.00");
|
---|
45 | TableFileParser parser = new TableFileParser();
|
---|
46 | try {
|
---|
47 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
48 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
49 | Assert.AreEqual(6, parser.Rows);
|
---|
50 | Assert.AreEqual(4, parser.Columns);
|
---|
51 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
52 | }
|
---|
53 | finally {
|
---|
54 | File.Delete(tempFileName);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | [TestMethod]
|
---|
58 | public void ParseCSVWithNames() {
|
---|
59 | string tempFileName = Path.GetTempFileName();
|
---|
60 | NumberFormatInfo numberFormat;
|
---|
61 | DateTimeFormatInfo dateFormatInfo;
|
---|
62 | char separator;
|
---|
63 | WriteToFile(tempFileName,
|
---|
64 | @"x01, x02, x03, x04
|
---|
65 | 0.00, 0.00, 0.00, 3.14
|
---|
66 | 0.00, 0.00, 0.00, 0.00
|
---|
67 | 0.00, 0.00, 0.00, 0.00
|
---|
68 | 0.00, 0.00, 0.00, 0.00
|
---|
69 | 0.00, 0.00, 0.00, 0.00
|
---|
70 | 0.00, 0.00, 0.00, 0.00");
|
---|
71 | TableFileParser parser = new TableFileParser();
|
---|
72 | try {
|
---|
73 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
74 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
75 | Assert.AreEqual(6, parser.Rows);
|
---|
76 | Assert.AreEqual(4, parser.Columns);
|
---|
77 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
78 | }
|
---|
79 | finally {
|
---|
80 | File.Delete(tempFileName);
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | [TestMethod]
|
---|
85 | public void ParseGermanCSV() {
|
---|
86 | string tempFileName = Path.GetTempFileName();
|
---|
87 | NumberFormatInfo numberFormat;
|
---|
88 | DateTimeFormatInfo dateFormatInfo;
|
---|
89 | char separator;
|
---|
90 | WriteToFile(tempFileName,
|
---|
91 | @"0,00; 0,00; 0,00; 3,14
|
---|
92 | 0,00; 0,00; 0,00; 0,00
|
---|
93 | 0,00; 0,00; 0,00; 0,00
|
---|
94 | 0,00; 0,00; 0,00; 0,00
|
---|
95 | 0,00; 0,00; 0,00; 0,00
|
---|
96 | 0,00; 0,00; 0,00; 0,00");
|
---|
97 | TableFileParser parser = new TableFileParser();
|
---|
98 | try {
|
---|
99 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
100 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
101 | Assert.AreEqual(6, parser.Rows);
|
---|
102 | Assert.AreEqual(4, parser.Columns);
|
---|
103 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
104 | }
|
---|
105 | finally {
|
---|
106 | File.Delete(tempFileName);
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | [TestMethod]
|
---|
111 | public void ParseGermanCSVWithNames() {
|
---|
112 | string tempFileName = Path.GetTempFileName();
|
---|
113 | NumberFormatInfo numberFormat;
|
---|
114 | DateTimeFormatInfo dateFormatInfo;
|
---|
115 | char separator;
|
---|
116 | WriteToFile(tempFileName,
|
---|
117 | @"x01; x02; x03; x04
|
---|
118 | 0,00; 0,00; 0,00; 3,14
|
---|
119 | 0,00; 0,00; 0,00; 0,00
|
---|
120 | 0,00; 0,00; 0,00; 0,00
|
---|
121 | 0,00; 0,00; 0,00; 0,00
|
---|
122 | 0,00; 0,00; 0,00; 0,00
|
---|
123 | 0,00; 0,00; 0,00; 0,00");
|
---|
124 | TableFileParser parser = new TableFileParser();
|
---|
125 | try {
|
---|
126 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
127 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
128 | Assert.AreEqual(6, parser.Rows);
|
---|
129 | Assert.AreEqual(4, parser.Columns);
|
---|
130 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
131 | }
|
---|
132 | finally {
|
---|
133 | File.Delete(tempFileName);
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | [TestMethod]
|
---|
138 | public void ParseGermanCSVWithoutCommas() {
|
---|
139 | string tempFileName = Path.GetTempFileName();
|
---|
140 | NumberFormatInfo numberFormat;
|
---|
141 | DateTimeFormatInfo dateFormatInfo;
|
---|
142 | char separator;
|
---|
143 | WriteToFile(tempFileName,
|
---|
144 | @"0; 0; 0; 3
|
---|
145 | 0; 0; 0; 0
|
---|
146 | 0; 0; 0; 0
|
---|
147 | 0; 0; 0; 0
|
---|
148 | 0; 0; 0; 0
|
---|
149 | 0; 0; 0; 0");
|
---|
150 | TableFileParser parser = new TableFileParser();
|
---|
151 | try {
|
---|
152 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
153 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
154 | Assert.AreEqual(6, parser.Rows);
|
---|
155 | Assert.AreEqual(4, parser.Columns);
|
---|
156 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
157 | }
|
---|
158 | finally {
|
---|
159 | File.Delete(tempFileName);
|
---|
160 | }
|
---|
161 | }
|
---|
162 | [TestMethod]
|
---|
163 | public void ParseGermanCSVWithoutCommasWithNames() {
|
---|
164 | string tempFileName = Path.GetTempFileName();
|
---|
165 | NumberFormatInfo numberFormat;
|
---|
166 | DateTimeFormatInfo dateFormatInfo;
|
---|
167 | char separator;
|
---|
168 | WriteToFile(tempFileName,
|
---|
169 | @"x01; x02; x03; x04
|
---|
170 | 0; 0; 0; 3
|
---|
171 | 0; 0; 0; 0
|
---|
172 | 0; 0; 0; 0
|
---|
173 | 0; 0; 0; 0
|
---|
174 | 0; 0; 0; 0
|
---|
175 | 0; 0; 0; 0");
|
---|
176 | TableFileParser parser = new TableFileParser();
|
---|
177 | try {
|
---|
178 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
179 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
180 | Assert.AreEqual(6, parser.Rows);
|
---|
181 | Assert.AreEqual(4, parser.Columns);
|
---|
182 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
183 | }
|
---|
184 | finally {
|
---|
185 | File.Delete(tempFileName);
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | [TestMethod]
|
---|
190 | public void ParseEnglishCSVWithoutCommas() {
|
---|
191 | string tempFileName = Path.GetTempFileName();
|
---|
192 | NumberFormatInfo numberFormat;
|
---|
193 | DateTimeFormatInfo dateFormatInfo;
|
---|
194 | char separator;
|
---|
195 | WriteToFile(tempFileName,
|
---|
196 | @"0, 0, 0, 3
|
---|
197 | 0, 0, 0, 0
|
---|
198 | 0, 0, 0, 0
|
---|
199 | 0, 0, 0, 0
|
---|
200 | 0, 0, 0, 0
|
---|
201 | 0, 0, 0, 0");
|
---|
202 | TableFileParser parser = new TableFileParser();
|
---|
203 | try {
|
---|
204 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
205 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
206 | Assert.AreEqual(6, parser.Rows);
|
---|
207 | Assert.AreEqual(4, parser.Columns);
|
---|
208 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
209 | }
|
---|
210 | finally {
|
---|
211 | File.Delete(tempFileName);
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | [TestMethod]
|
---|
216 | public void ParseEnglishCSVWithoutCommasWithoutSpace() {
|
---|
217 | string tempFileName = Path.GetTempFileName();
|
---|
218 | NumberFormatInfo numberFormat;
|
---|
219 | DateTimeFormatInfo dateFormatInfo;
|
---|
220 | char separator;
|
---|
221 | WriteToFile(tempFileName,
|
---|
222 | @"0,0,0,3
|
---|
223 | 0,0,0,0
|
---|
224 | 0,0,0,0
|
---|
225 | 0,0,0,0
|
---|
226 | 0,0,0,0
|
---|
227 | 0,0,0,0");
|
---|
228 | TableFileParser parser = new TableFileParser();
|
---|
229 | try {
|
---|
230 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
231 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
232 | Assert.AreEqual(6, parser.Rows);
|
---|
233 | Assert.AreEqual(4, parser.Columns);
|
---|
234 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
235 | }
|
---|
236 | finally {
|
---|
237 | File.Delete(tempFileName);
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | [TestMethod]
|
---|
242 | public void ParseEnglishCSVWithoutCommasWithNames() {
|
---|
243 | string tempFileName = Path.GetTempFileName();
|
---|
244 | NumberFormatInfo numberFormat;
|
---|
245 | DateTimeFormatInfo dateFormatInfo;
|
---|
246 | char separator;
|
---|
247 | WriteToFile(tempFileName,
|
---|
248 | @"x01, x02, x03, x04
|
---|
249 | 0, 0, 0, 3
|
---|
250 | 0, 0, 0, 0
|
---|
251 | 0, 0, 0, 0
|
---|
252 | 0, 0, 0, 0
|
---|
253 | 0, 0, 0, 0
|
---|
254 | 0, 0, 0, 0");
|
---|
255 | TableFileParser parser = new TableFileParser();
|
---|
256 | try {
|
---|
257 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
258 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
259 | Assert.AreEqual(6, parser.Rows);
|
---|
260 | Assert.AreEqual(4, parser.Columns);
|
---|
261 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
262 | }
|
---|
263 | finally {
|
---|
264 | File.Delete(tempFileName);
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | [TestMethod]
|
---|
269 | public void ParseEnglishCSVWithoutCommasWithoutSpacesWithNames() {
|
---|
270 | string tempFileName = Path.GetTempFileName();
|
---|
271 | NumberFormatInfo numberFormat;
|
---|
272 | DateTimeFormatInfo dateFormatInfo;
|
---|
273 | char separator;
|
---|
274 | WriteToFile(tempFileName,
|
---|
275 | @"x01,x02,x03,x04
|
---|
276 | 0,0,0,3
|
---|
277 | 0,0,0,0
|
---|
278 | 0,0,0,0
|
---|
279 | 0,0,0,0
|
---|
280 | 0,0,0,0
|
---|
281 | 0,0,0,0");
|
---|
282 | TableFileParser parser = new TableFileParser();
|
---|
283 | try {
|
---|
284 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
285 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
286 | Assert.AreEqual(6, parser.Rows);
|
---|
287 | Assert.AreEqual(4, parser.Columns);
|
---|
288 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
289 | }
|
---|
290 | finally {
|
---|
291 | File.Delete(tempFileName);
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 |
|
---|
296 | [TestMethod]
|
---|
297 | public void ParseGermanTabSeparated() {
|
---|
298 | string tempFileName = Path.GetTempFileName();
|
---|
299 | NumberFormatInfo numberFormat;
|
---|
300 | DateTimeFormatInfo dateFormatInfo;
|
---|
301 | char separator;
|
---|
302 | WriteToFile(tempFileName,
|
---|
303 | "0,00\t 0,00\t 0,00\t 3,14" + Environment.NewLine +
|
---|
304 | "0,00\t 0,00\t 0,00\t 0,00" + 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");
|
---|
309 | TableFileParser parser = new TableFileParser();
|
---|
310 | try {
|
---|
311 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
312 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
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 |
|
---|
322 | [TestMethod]
|
---|
323 | public void ParseGermanTabSeparatedWithNames() {
|
---|
324 | string tempFileName = Path.GetTempFileName();
|
---|
325 | NumberFormatInfo numberFormat;
|
---|
326 | DateTimeFormatInfo dateFormatInfo;
|
---|
327 | char separator;
|
---|
328 | WriteToFile(tempFileName,
|
---|
329 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
330 | "0,00\t 0,00\t 0,00\t 3,14" + 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" + Environment.NewLine +
|
---|
333 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
334 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
335 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
336 | TableFileParser parser = new TableFileParser();
|
---|
337 | try {
|
---|
338 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
339 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
340 | Assert.AreEqual(6, parser.Rows);
|
---|
341 | Assert.AreEqual(4, parser.Columns);
|
---|
342 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
343 | }
|
---|
344 | finally {
|
---|
345 | File.Delete(tempFileName);
|
---|
346 | }
|
---|
347 | }
|
---|
348 |
|
---|
349 | [TestMethod]
|
---|
350 | public void ParseEnglishTabSeparated() {
|
---|
351 | string tempFileName = Path.GetTempFileName();
|
---|
352 | NumberFormatInfo numberFormat;
|
---|
353 | DateTimeFormatInfo dateFormatInfo;
|
---|
354 | char separator;
|
---|
355 | WriteToFile(tempFileName,
|
---|
356 | "0.00\t 0.00\t 0.00\t 3.14" + Environment.NewLine +
|
---|
357 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
358 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
359 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
360 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
361 | "0.00\t 0.00\t 0.00\t 0.00");
|
---|
362 | TableFileParser parser = new TableFileParser();
|
---|
363 | try {
|
---|
364 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
365 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
366 | Assert.AreEqual(6, parser.Rows);
|
---|
367 | Assert.AreEqual(4, parser.Columns);
|
---|
368 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
369 | }
|
---|
370 | finally {
|
---|
371 | File.Delete(tempFileName);
|
---|
372 | }
|
---|
373 | }
|
---|
374 | [TestMethod]
|
---|
375 | public void ParseEnglishTabSeparatedWithNames() {
|
---|
376 | string tempFileName = Path.GetTempFileName();
|
---|
377 | NumberFormatInfo numberFormat;
|
---|
378 | DateTimeFormatInfo dateFormatInfo;
|
---|
379 | char separator;
|
---|
380 | WriteToFile(tempFileName,
|
---|
381 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
382 | "0.00\t 0.00\t 0.00\t 3.14" + Environment.NewLine +
|
---|
383 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
384 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
385 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
386 | "0.00\t 0.00\t 0.00\t 0.00" + Environment.NewLine +
|
---|
387 | "0.00\t 0.00\t 0.00\t 0.00");
|
---|
388 | TableFileParser parser = new TableFileParser();
|
---|
389 | try {
|
---|
390 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
391 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
392 | Assert.AreEqual(6, parser.Rows);
|
---|
393 | Assert.AreEqual(4, parser.Columns);
|
---|
394 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
395 | }
|
---|
396 | finally {
|
---|
397 | File.Delete(tempFileName);
|
---|
398 | }
|
---|
399 | }
|
---|
400 |
|
---|
401 | [TestMethod]
|
---|
402 | public void ParseTabSeparatedWithoutCommas() {
|
---|
403 | string tempFileName = Path.GetTempFileName();
|
---|
404 | NumberFormatInfo numberFormat;
|
---|
405 | DateTimeFormatInfo dateFormatInfo;
|
---|
406 | char separator;
|
---|
407 | WriteToFile(tempFileName,
|
---|
408 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
409 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
410 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
411 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
412 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
413 | "0\t 0\t 0\t 0");
|
---|
414 | TableFileParser parser = new TableFileParser();
|
---|
415 | try {
|
---|
416 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
417 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
418 | Assert.AreEqual(6, parser.Rows);
|
---|
419 | Assert.AreEqual(4, parser.Columns);
|
---|
420 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
421 | }
|
---|
422 | finally {
|
---|
423 | File.Delete(tempFileName);
|
---|
424 | }
|
---|
425 | }
|
---|
426 | [TestMethod]
|
---|
427 | public void ParseTabSeparatedWithoutCommasWithNames() {
|
---|
428 | string tempFileName = Path.GetTempFileName();
|
---|
429 | NumberFormatInfo numberFormat;
|
---|
430 | DateTimeFormatInfo dateFormatInfo;
|
---|
431 | char separator;
|
---|
432 | WriteToFile(tempFileName,
|
---|
433 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
434 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
435 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
436 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
437 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
438 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
439 | "0\t 0\t 0\t 0");
|
---|
440 | TableFileParser parser = new TableFileParser();
|
---|
441 | try {
|
---|
442 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
443 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
444 | Assert.AreEqual(6, parser.Rows);
|
---|
445 | Assert.AreEqual(4, parser.Columns);
|
---|
446 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
447 | }
|
---|
448 | finally {
|
---|
449 | File.Delete(tempFileName);
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 | [TestMethod]
|
---|
454 | public void ParseWithEmtpyLines() {
|
---|
455 | string tempFileName = Path.GetTempFileName();
|
---|
456 | NumberFormatInfo numberFormat;
|
---|
457 | DateTimeFormatInfo dateFormatInfo;
|
---|
458 | char separator;
|
---|
459 | WriteToFile(tempFileName,
|
---|
460 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
461 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
462 | Environment.NewLine +
|
---|
463 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
464 | " " + Environment.NewLine +
|
---|
465 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
466 | "0\t 0\t 0\t 0" + Environment.NewLine + Environment.NewLine);
|
---|
467 | TableFileParser parser = new TableFileParser();
|
---|
468 | try {
|
---|
469 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
470 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
471 | Assert.AreEqual(4, parser.Rows);
|
---|
472 | Assert.AreEqual(4, parser.Columns);
|
---|
473 | }
|
---|
474 | finally {
|
---|
475 | File.Delete(tempFileName);
|
---|
476 | }
|
---|
477 | }
|
---|
478 |
|
---|
479 | [TestMethod]
|
---|
480 | public void ParseGermanSpaceSeparated() {
|
---|
481 | string tempFileName = Path.GetTempFileName();
|
---|
482 | NumberFormatInfo numberFormat;
|
---|
483 | DateTimeFormatInfo dateFormatInfo;
|
---|
484 | char separator;
|
---|
485 | WriteToFile(tempFileName,
|
---|
486 | @"0,00 0,00 0,00 3,14
|
---|
487 | 0,00 0,00 0,00 0,00
|
---|
488 | 0,00 0,00 0,00 0,00
|
---|
489 | 0,00 0,00 0,00 0,00
|
---|
490 | 0,00 0,00 0,00 0,00
|
---|
491 | 0,00 0,00 0,00 0,00");
|
---|
492 | TableFileParser parser = new TableFileParser();
|
---|
493 | try {
|
---|
494 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
495 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
496 | Assert.AreEqual(6, parser.Rows);
|
---|
497 | Assert.AreEqual(4, parser.Columns);
|
---|
498 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
499 | }
|
---|
500 | finally {
|
---|
501 | File.Delete(tempFileName);
|
---|
502 | }
|
---|
503 | }
|
---|
504 | [TestMethod]
|
---|
505 | public void ParseGermanSpaceSeparatedWithNames() {
|
---|
506 | string tempFileName = Path.GetTempFileName();
|
---|
507 | NumberFormatInfo numberFormat;
|
---|
508 | DateTimeFormatInfo dateFormatInfo;
|
---|
509 | char separator;
|
---|
510 | WriteToFile(tempFileName,
|
---|
511 | @"x01 x02 x03 x04
|
---|
512 | 0,00 0,00 0,00 3,14
|
---|
513 | 0,00 0,00 0,00 0,00
|
---|
514 | 0,00 0,00 0,00 0,00
|
---|
515 | 0,00 0,00 0,00 0,00
|
---|
516 | 0,00 0,00 0,00 0,00
|
---|
517 | 0,00 0,00 0,00 0,00");
|
---|
518 | TableFileParser parser = new TableFileParser();
|
---|
519 | try {
|
---|
520 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
521 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
522 | Assert.AreEqual(6, parser.Rows);
|
---|
523 | Assert.AreEqual(4, parser.Columns);
|
---|
524 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
525 | }
|
---|
526 | finally {
|
---|
527 | File.Delete(tempFileName);
|
---|
528 | }
|
---|
529 | }
|
---|
530 |
|
---|
531 | [TestMethod]
|
---|
532 | public void ParseEnglishSpaceSeparated() {
|
---|
533 | string tempFileName = Path.GetTempFileName();
|
---|
534 | NumberFormatInfo numberFormat;
|
---|
535 | DateTimeFormatInfo dateFormatInfo;
|
---|
536 | char separator;
|
---|
537 | WriteToFile(tempFileName,
|
---|
538 | @"0.00 0.00 0.00 3.14
|
---|
539 | 0.00 0.00 0.00 0.00
|
---|
540 | 0.00 0.00 0.00 0.00
|
---|
541 | 0.00 0.00 0.00 0.00
|
---|
542 | 0.00 0.00 0.00 0.00
|
---|
543 | 0.00 0.00 0.00 0.00");
|
---|
544 | TableFileParser parser = new TableFileParser();
|
---|
545 | try {
|
---|
546 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
547 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
548 | Assert.AreEqual(6, parser.Rows);
|
---|
549 | Assert.AreEqual(4, parser.Columns);
|
---|
550 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
551 | }
|
---|
552 | finally {
|
---|
553 | File.Delete(tempFileName);
|
---|
554 | }
|
---|
555 | }
|
---|
556 | [TestMethod]
|
---|
557 | public void ParseEnglishSpaceSeparatedWithNames() {
|
---|
558 | string tempFileName = Path.GetTempFileName();
|
---|
559 | NumberFormatInfo numberFormat;
|
---|
560 | DateTimeFormatInfo dateFormatInfo;
|
---|
561 | char separator;
|
---|
562 | WriteToFile(tempFileName,
|
---|
563 | @"x01 x02 x03 x04
|
---|
564 | 0.00 0.00 0.00 3.14
|
---|
565 | 0.00 0.00 0.00 0.00
|
---|
566 | 0.00 0.00 0.00 0.00
|
---|
567 | 0.00 0.00 0.00 0.00
|
---|
568 | 0.00 0.00 0.00 0.00
|
---|
569 | 0.00 0.00 0.00 0.00");
|
---|
570 | TableFileParser parser = new TableFileParser();
|
---|
571 | try {
|
---|
572 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
573 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
574 | Assert.AreEqual(6, parser.Rows);
|
---|
575 | Assert.AreEqual(4, parser.Columns);
|
---|
576 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
577 | }
|
---|
578 | finally {
|
---|
579 | File.Delete(tempFileName);
|
---|
580 | }
|
---|
581 | }
|
---|
582 |
|
---|
583 | [TestMethod]
|
---|
584 | public void ParseSpaceSeparatedWithoutCommas() {
|
---|
585 | string tempFileName = Path.GetTempFileName();
|
---|
586 | NumberFormatInfo numberFormat;
|
---|
587 | DateTimeFormatInfo dateFormatInfo;
|
---|
588 | char separator;
|
---|
589 | WriteToFile(tempFileName,
|
---|
590 | @"0 0 0 3
|
---|
591 | 0 0 0 0
|
---|
592 | 0 0 0 0
|
---|
593 | 0 0 0 0
|
---|
594 | 0 0 0 0
|
---|
595 | 0 0 0 0");
|
---|
596 | TableFileParser parser = new TableFileParser();
|
---|
597 | try {
|
---|
598 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
599 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
600 | Assert.AreEqual(6, parser.Rows);
|
---|
601 | Assert.AreEqual(4, parser.Columns);
|
---|
602 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
603 | }
|
---|
604 | finally {
|
---|
605 | File.Delete(tempFileName);
|
---|
606 | }
|
---|
607 | }
|
---|
608 | [TestMethod]
|
---|
609 | public void ParseSpaceSeparatedWithoutCommasWithNames() {
|
---|
610 | string tempFileName = Path.GetTempFileName();
|
---|
611 | NumberFormatInfo numberFormat;
|
---|
612 | DateTimeFormatInfo dateFormatInfo;
|
---|
613 | char separator;
|
---|
614 | WriteToFile(tempFileName,
|
---|
615 | @"x01 x02 x03 x04
|
---|
616 | 0 0 0 3
|
---|
617 | 0 0 0 0
|
---|
618 | 0 0 0 0
|
---|
619 | 0 0 0 0
|
---|
620 | 0 0 0 0
|
---|
621 | 0 0 0 0");
|
---|
622 | TableFileParser parser = new TableFileParser();
|
---|
623 | try {
|
---|
624 | TableFileParser.DetermineFileFormat(tempFileName, out numberFormat, out dateFormatInfo, out separator);
|
---|
625 | parser.Parse(tempFileName, numberFormat, dateFormatInfo, separator);
|
---|
626 | Assert.AreEqual(6, parser.Rows);
|
---|
627 | Assert.AreEqual(4, parser.Columns);
|
---|
628 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
629 | }
|
---|
630 | finally {
|
---|
631 | File.Delete(tempFileName);
|
---|
632 | }
|
---|
633 | }
|
---|
634 |
|
---|
635 | private void WriteToFile(string fileName, string content) {
|
---|
636 | using (StreamWriter writer = new StreamWriter(fileName)) {
|
---|
637 | writer.Write(content);
|
---|
638 | }
|
---|
639 | }
|
---|
640 | }
|
---|
641 | }
|
---|