[5574] | 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;
|
---|
[6760] | 25 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
[5574] | 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);
|
---|
[6760] | 46 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
[5574] | 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);
|
---|
[6760] | 68 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
[5574] | 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);
|
---|
[6760] | 90 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
[5574] | 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);
|
---|
[6760] | 113 | Assert.AreEqual(parser.Values[3][0], 3.14);
|
---|
[5574] | 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);
|
---|
[6760] | 135 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
[5574] | 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);
|
---|
[6760] | 157 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
[5574] | 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);
|
---|
[6760] | 179 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
[5574] | 180 | }
|
---|
| 181 | finally {
|
---|
| 182 | File.Delete(tempFileName);
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | [TestMethod]
|
---|
| 187 | public void ParseEnglishCSVWithoutCommasWithNames() {
|
---|
| 188 | string tempFileName = Path.GetTempFileName();
|
---|
| 189 | WriteToFile(tempFileName,
|
---|
| 190 | @"x01, x02, x03, x04
|
---|
| 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);
|
---|
[6760] | 202 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
[5574] | 203 | }
|
---|
| 204 | finally {
|
---|
| 205 | File.Delete(tempFileName);
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | [TestMethod]
|
---|
| 211 | public void ParseGermanTabSeparated() {
|
---|
| 212 | string tempFileName = Path.GetTempFileName();
|
---|
| 213 | WriteToFile(tempFileName,
|
---|
| 214 | "0,00\t 0,00\t 0,00\t 3,14" + Environment.NewLine +
|
---|
| 215 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 216 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 217 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 218 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 219 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
| 220 | TableFileParser parser = new TableFileParser();
|
---|
| 221 | try {
|
---|
| 222 | parser.Parse(tempFileName);
|
---|
| 223 | Assert.AreEqual(6, parser.Rows);
|
---|
| 224 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 225 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
[5574] | 226 | }
|
---|
| 227 | finally {
|
---|
| 228 | File.Delete(tempFileName);
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | [TestMethod]
|
---|
| 233 | public void ParseGermanTabSeparatedWithNames() {
|
---|
| 234 | string tempFileName = Path.GetTempFileName();
|
---|
| 235 | WriteToFile(tempFileName,
|
---|
| 236 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
| 237 | "0,00\t 0,00\t 0,00\t 3,14" + Environment.NewLine +
|
---|
| 238 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 239 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 240 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 241 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 242 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
| 243 | TableFileParser parser = new TableFileParser();
|
---|
| 244 | try {
|
---|
| 245 | parser.Parse(tempFileName);
|
---|
| 246 | Assert.AreEqual(6, parser.Rows);
|
---|
| 247 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 248 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
[5574] | 249 | }
|
---|
| 250 | finally {
|
---|
| 251 | File.Delete(tempFileName);
|
---|
| 252 | }
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | [TestMethod]
|
---|
| 256 | public void ParseEnglishTabSeparated() {
|
---|
| 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);
|
---|
[6760] | 270 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
[5574] | 271 | }
|
---|
| 272 | finally {
|
---|
| 273 | File.Delete(tempFileName);
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
| 276 | [TestMethod]
|
---|
| 277 | public void ParseEnglishTabSeparatedWithNames() {
|
---|
| 278 | string tempFileName = Path.GetTempFileName();
|
---|
| 279 | WriteToFile(tempFileName,
|
---|
| 280 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
| 281 | "0.00\t 0.00\t 0.00\t 3.14" + Environment.NewLine +
|
---|
| 282 | "0.00\t 0.00\t 0.00\t 0.00" + 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");
|
---|
| 287 | TableFileParser parser = new TableFileParser();
|
---|
| 288 | try {
|
---|
| 289 | parser.Parse(tempFileName);
|
---|
| 290 | Assert.AreEqual(6, parser.Rows);
|
---|
| 291 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 292 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
[5574] | 293 | }
|
---|
| 294 | finally {
|
---|
| 295 | File.Delete(tempFileName);
|
---|
| 296 | }
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | [TestMethod]
|
---|
| 300 | public void ParseTabSeparatedWithoutCommas() {
|
---|
| 301 | string tempFileName = Path.GetTempFileName();
|
---|
| 302 | WriteToFile(tempFileName,
|
---|
| 303 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
| 304 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 305 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 306 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 307 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 308 | "0\t 0\t 0\t 0");
|
---|
| 309 | TableFileParser parser = new TableFileParser();
|
---|
| 310 | try {
|
---|
| 311 | parser.Parse(tempFileName);
|
---|
| 312 | Assert.AreEqual(6, parser.Rows);
|
---|
| 313 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 314 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
[5574] | 315 | }
|
---|
| 316 | finally {
|
---|
| 317 | File.Delete(tempFileName);
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 | [TestMethod]
|
---|
| 321 | public void ParseTabSeparatedWithoutCommasWithNames() {
|
---|
| 322 | string tempFileName = Path.GetTempFileName();
|
---|
| 323 | WriteToFile(tempFileName,
|
---|
| 324 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
| 325 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
| 326 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 327 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 328 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 329 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 330 | "0\t 0\t 0\t 0");
|
---|
| 331 | TableFileParser parser = new TableFileParser();
|
---|
| 332 | try {
|
---|
| 333 | parser.Parse(tempFileName);
|
---|
| 334 | Assert.AreEqual(6, parser.Rows);
|
---|
| 335 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 336 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
[5574] | 337 | }
|
---|
| 338 | finally {
|
---|
| 339 | File.Delete(tempFileName);
|
---|
| 340 | }
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | [TestMethod]
|
---|
[6760] | 344 | public void ParseWithEmtpyLines() {
|
---|
| 345 | string tempFileName = Path.GetTempFileName();
|
---|
| 346 | WriteToFile(tempFileName,
|
---|
| 347 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
| 348 | "0\t 0\t 0\t 3" + Environment.NewLine +
|
---|
| 349 | Environment.NewLine +
|
---|
| 350 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 351 | " " + Environment.NewLine +
|
---|
| 352 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 353 | "0\t 0\t 0\t 0" + Environment.NewLine + Environment.NewLine);
|
---|
| 354 | TableFileParser parser = new TableFileParser();
|
---|
| 355 | try {
|
---|
| 356 | parser.Parse(tempFileName);
|
---|
| 357 | Assert.AreEqual(4, parser.Rows);
|
---|
| 358 | Assert.AreEqual(4, parser.Columns);
|
---|
| 359 | }
|
---|
| 360 | finally {
|
---|
| 361 | File.Delete(tempFileName);
|
---|
| 362 | }
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | [TestMethod]
|
---|
[5574] | 366 | public void ParseGermanSpaceSeparated() {
|
---|
| 367 | string tempFileName = Path.GetTempFileName();
|
---|
| 368 | WriteToFile(tempFileName,
|
---|
| 369 | @"0,00 0,00 0,00 3,14
|
---|
| 370 | 0,00 0,00 0,00 0,00
|
---|
| 371 | 0,00 0,00 0,00 0,00
|
---|
| 372 | 0,00 0,00 0,00 0,00
|
---|
| 373 | 0,00 0,00 0,00 0,00
|
---|
| 374 | 0,00 0,00 0,00 0,00");
|
---|
| 375 | TableFileParser parser = new TableFileParser();
|
---|
| 376 | try {
|
---|
| 377 | parser.Parse(tempFileName);
|
---|
| 378 | Assert.AreEqual(6, parser.Rows);
|
---|
| 379 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 380 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
[5574] | 381 | }
|
---|
| 382 | finally {
|
---|
| 383 | File.Delete(tempFileName);
|
---|
| 384 | }
|
---|
| 385 | }
|
---|
| 386 | [TestMethod]
|
---|
| 387 | public void ParseGermanSpaceSeparatedWithNames() {
|
---|
| 388 | string tempFileName = Path.GetTempFileName();
|
---|
| 389 | WriteToFile(tempFileName,
|
---|
| 390 | @"x01 x02 x03 x04
|
---|
| 391 | 0,00 0,00 0,00 3,14
|
---|
| 392 | 0,00 0,00 0,00 0,00
|
---|
| 393 | 0,00 0,00 0,00 0,00
|
---|
| 394 | 0,00 0,00 0,00 0,00
|
---|
| 395 | 0,00 0,00 0,00 0,00
|
---|
| 396 | 0,00 0,00 0,00 0,00");
|
---|
| 397 | TableFileParser parser = new TableFileParser();
|
---|
| 398 | try {
|
---|
| 399 | parser.Parse(tempFileName);
|
---|
| 400 | Assert.AreEqual(6, parser.Rows);
|
---|
| 401 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 402 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
[5574] | 403 | }
|
---|
| 404 | finally {
|
---|
| 405 | File.Delete(tempFileName);
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | [TestMethod]
|
---|
| 410 | public void ParseEnglishSpaceSeparated() {
|
---|
| 411 | string tempFileName = Path.GetTempFileName();
|
---|
| 412 | WriteToFile(tempFileName,
|
---|
| 413 | @"0.00 0.00 0.00 3.14
|
---|
| 414 | 0.00 0.00 0.00 0.00
|
---|
| 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 | TableFileParser parser = new TableFileParser();
|
---|
| 420 | try {
|
---|
| 421 | parser.Parse(tempFileName);
|
---|
| 422 | Assert.AreEqual(6, parser.Rows);
|
---|
| 423 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 424 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
[5574] | 425 | }
|
---|
| 426 | finally {
|
---|
| 427 | File.Delete(tempFileName);
|
---|
| 428 | }
|
---|
| 429 | }
|
---|
| 430 | [TestMethod]
|
---|
| 431 | public void ParseEnglishSpaceSeparatedWithNames() {
|
---|
| 432 | string tempFileName = Path.GetTempFileName();
|
---|
| 433 | WriteToFile(tempFileName,
|
---|
| 434 | @"x01 x02 x03 x04
|
---|
| 435 | 0.00 0.00 0.00 3.14
|
---|
| 436 | 0.00 0.00 0.00 0.00
|
---|
| 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 | TableFileParser parser = new TableFileParser();
|
---|
| 442 | try {
|
---|
| 443 | parser.Parse(tempFileName);
|
---|
| 444 | Assert.AreEqual(6, parser.Rows);
|
---|
| 445 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 446 | Assert.AreEqual((double)parser.Values[3][0], 3.14);
|
---|
[5574] | 447 | }
|
---|
| 448 | finally {
|
---|
| 449 | File.Delete(tempFileName);
|
---|
| 450 | }
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 | [TestMethod]
|
---|
| 454 | public void ParseSpaceSeparatedWithoutCommas() {
|
---|
| 455 | string tempFileName = Path.GetTempFileName();
|
---|
| 456 | WriteToFile(tempFileName,
|
---|
| 457 | @"0 0 0 3
|
---|
| 458 | 0 0 0 0
|
---|
| 459 | 0 0 0 0
|
---|
| 460 | 0 0 0 0
|
---|
| 461 | 0 0 0 0
|
---|
| 462 | 0 0 0 0");
|
---|
| 463 | TableFileParser parser = new TableFileParser();
|
---|
| 464 | try {
|
---|
| 465 | parser.Parse(tempFileName);
|
---|
| 466 | Assert.AreEqual(6, parser.Rows);
|
---|
| 467 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 468 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
[5574] | 469 | }
|
---|
| 470 | finally {
|
---|
| 471 | File.Delete(tempFileName);
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 | [TestMethod]
|
---|
| 475 | public void ParseSpaceSeparatedWithoutCommasWithNames() {
|
---|
| 476 | string tempFileName = Path.GetTempFileName();
|
---|
| 477 | WriteToFile(tempFileName,
|
---|
| 478 | @"x01 x02 x03 x04
|
---|
| 479 | 0 0 0 3
|
---|
| 480 | 0 0 0 0
|
---|
| 481 | 0 0 0 0
|
---|
| 482 | 0 0 0 0
|
---|
| 483 | 0 0 0 0
|
---|
| 484 | 0 0 0 0");
|
---|
| 485 | TableFileParser parser = new TableFileParser();
|
---|
| 486 | try {
|
---|
| 487 | parser.Parse(tempFileName);
|
---|
| 488 | Assert.AreEqual(6, parser.Rows);
|
---|
| 489 | Assert.AreEqual(4, parser.Columns);
|
---|
[6760] | 490 | Assert.AreEqual((double)parser.Values[3][0], 3);
|
---|
[5574] | 491 | }
|
---|
| 492 | finally {
|
---|
| 493 | File.Delete(tempFileName);
|
---|
| 494 | }
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | private void WriteToFile(string fileName, string content) {
|
---|
| 498 | using (StreamWriter writer = new StreamWriter(fileName)) {
|
---|
| 499 | writer.Write(content);
|
---|
| 500 | }
|
---|
| 501 | }
|
---|
| 502 | }
|
---|
| 503 | }
|
---|