[5013] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Problems.DataAnalysis.Evaluators;
|
---|
| 26 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 27 | using System.IO;
|
---|
| 28 | namespace HeuristicLab.Problems.DataAnalysis.Tests {
|
---|
| 29 |
|
---|
| 30 | [TestClass()]
|
---|
| 31 | public class TableFileParserTest {
|
---|
| 32 |
|
---|
| 33 | [TestMethod]
|
---|
| 34 | public void ParseCSV() {
|
---|
| 35 | string tempFileName = Path.GetTempFileName();
|
---|
| 36 | WriteToFile(tempFileName,
|
---|
| 37 | @"0.00, 0.00, 0.00, 3.14
|
---|
| 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 | 0.00, 0.00, 0.00, 0.00");
|
---|
| 43 | TableFileParser parser = new TableFileParser();
|
---|
| 44 | try {
|
---|
| 45 | parser.Parse(tempFileName);
|
---|
| 46 | Assert.AreEqual(6, parser.Rows);
|
---|
| 47 | Assert.AreEqual(4, parser.Columns);
|
---|
| 48 | Assert.AreEqual(parser.Values[0, 3], 3.14);
|
---|
| 49 | }
|
---|
| 50 | finally {
|
---|
| 51 | File.Delete(tempFileName);
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | [TestMethod]
|
---|
| 55 | public void ParseCSVWithNames() {
|
---|
| 56 | string tempFileName = Path.GetTempFileName();
|
---|
| 57 | WriteToFile(tempFileName,
|
---|
| 58 | @"x01, x02, x03, x04
|
---|
| 59 | 0.00, 0.00, 0.00, 3.14
|
---|
| 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 | 0.00, 0.00, 0.00, 0.00");
|
---|
| 65 | TableFileParser parser = new TableFileParser();
|
---|
| 66 | try {
|
---|
| 67 | parser.Parse(tempFileName);
|
---|
| 68 | Assert.AreEqual(6, parser.Rows);
|
---|
| 69 | Assert.AreEqual(4, parser.Columns);
|
---|
| 70 | Assert.AreEqual(parser.Values[0, 3], 3.14);
|
---|
| 71 | }
|
---|
| 72 | finally {
|
---|
| 73 | File.Delete(tempFileName);
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | [TestMethod]
|
---|
| 78 | public void ParseGermanCSV() {
|
---|
| 79 | string tempFileName = Path.GetTempFileName();
|
---|
| 80 | WriteToFile(tempFileName,
|
---|
| 81 | @"0,00; 0,00; 0,00; 3,14
|
---|
| 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 | 0,00; 0,00; 0,00; 0,00");
|
---|
| 87 | TableFileParser parser = new TableFileParser();
|
---|
| 88 | try {
|
---|
| 89 | parser.Parse(tempFileName);
|
---|
| 90 | Assert.AreEqual(6, parser.Rows);
|
---|
| 91 | Assert.AreEqual(4, parser.Columns);
|
---|
| 92 | Assert.AreEqual(parser.Values[0, 3], 3.14);
|
---|
| 93 | }
|
---|
| 94 | finally {
|
---|
| 95 | File.Delete(tempFileName);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | [TestMethod]
|
---|
| 100 | public void ParseGermanCSVWithNames() {
|
---|
| 101 | string tempFileName = Path.GetTempFileName();
|
---|
| 102 | WriteToFile(tempFileName,
|
---|
| 103 | @"x01; x02; x03; x04
|
---|
| 104 | 0,00; 0,00; 0,00; 3,14
|
---|
| 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 | 0,00; 0,00; 0,00; 0,00");
|
---|
| 110 | TableFileParser parser = new TableFileParser();
|
---|
| 111 | try {
|
---|
| 112 | parser.Parse(tempFileName);
|
---|
| 113 | Assert.AreEqual(6, parser.Rows);
|
---|
| 114 | Assert.AreEqual(4, parser.Columns);
|
---|
| 115 | Assert.AreEqual(parser.Values[0, 3], 3.14);
|
---|
| 116 | }
|
---|
| 117 | finally {
|
---|
| 118 | File.Delete(tempFileName);
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | [TestMethod]
|
---|
| 123 | public void ParseGermanCSVWithoutCommas() {
|
---|
| 124 | string tempFileName = Path.GetTempFileName();
|
---|
| 125 | WriteToFile(tempFileName,
|
---|
| 126 | @"0; 0; 0; 3
|
---|
| 127 | 0; 0; 0; 0
|
---|
| 128 | 0; 0; 0; 0
|
---|
| 129 | 0; 0; 0; 0
|
---|
| 130 | 0; 0; 0; 0
|
---|
| 131 | 0; 0; 0; 0");
|
---|
| 132 | TableFileParser parser = new TableFileParser();
|
---|
| 133 | try {
|
---|
| 134 | parser.Parse(tempFileName);
|
---|
| 135 | Assert.AreEqual(6, parser.Rows);
|
---|
| 136 | Assert.AreEqual(4, parser.Columns);
|
---|
| 137 | Assert.AreEqual(parser.Values[0, 3], 3);
|
---|
| 138 | }
|
---|
| 139 | finally {
|
---|
| 140 | File.Delete(tempFileName);
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | [TestMethod]
|
---|
| 144 | public void ParseGermanCSVWithoutCommasWithNames() {
|
---|
| 145 | string tempFileName = Path.GetTempFileName();
|
---|
| 146 | WriteToFile(tempFileName,
|
---|
| 147 | @"x01; x02; x03; x04
|
---|
| 148 | 0; 0; 0; 3
|
---|
| 149 | 0; 0; 0; 0
|
---|
| 150 | 0; 0; 0; 0
|
---|
| 151 | 0; 0; 0; 0
|
---|
| 152 | 0; 0; 0; 0
|
---|
| 153 | 0; 0; 0; 0");
|
---|
| 154 | TableFileParser parser = new TableFileParser();
|
---|
| 155 | try {
|
---|
| 156 | parser.Parse(tempFileName);
|
---|
| 157 | Assert.AreEqual(6, parser.Rows);
|
---|
| 158 | Assert.AreEqual(4, parser.Columns);
|
---|
| 159 | Assert.AreEqual(parser.Values[0, 3], 3);
|
---|
| 160 | }
|
---|
| 161 | finally {
|
---|
| 162 | File.Delete(tempFileName);
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | [TestMethod]
|
---|
| 167 | public void ParseEnglishCSVWithoutCommas() {
|
---|
| 168 | string tempFileName = Path.GetTempFileName();
|
---|
| 169 | WriteToFile(tempFileName,
|
---|
| 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 | parser.Parse(tempFileName);
|
---|
| 179 | Assert.AreEqual(6, parser.Rows);
|
---|
| 180 | Assert.AreEqual(4, parser.Columns);
|
---|
| 181 | Assert.AreEqual(parser.Values[0, 3], 3);
|
---|
| 182 | }
|
---|
| 183 | finally {
|
---|
| 184 | File.Delete(tempFileName);
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | [TestMethod]
|
---|
| 189 | public void ParseEnglishCSVWithoutCommasWithNames() {
|
---|
| 190 | string tempFileName = Path.GetTempFileName();
|
---|
| 191 | WriteToFile(tempFileName,
|
---|
| 192 | @"x01, x02, x03, x04
|
---|
| 193 | 0, 0, 0, 3
|
---|
| 194 | 0, 0, 0, 0
|
---|
| 195 | 0, 0, 0, 0
|
---|
| 196 | 0, 0, 0, 0
|
---|
| 197 | 0, 0, 0, 0
|
---|
| 198 | 0, 0, 0, 0");
|
---|
| 199 | TableFileParser parser = new TableFileParser();
|
---|
| 200 | try {
|
---|
| 201 | parser.Parse(tempFileName);
|
---|
| 202 | Assert.AreEqual(6, parser.Rows);
|
---|
| 203 | Assert.AreEqual(4, parser.Columns);
|
---|
| 204 | Assert.AreEqual(parser.Values[0, 3], 3);
|
---|
| 205 | }
|
---|
| 206 | finally {
|
---|
| 207 | File.Delete(tempFileName);
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | [TestMethod]
|
---|
| 213 | public void ParseGermanTabSeparated() {
|
---|
| 214 | string tempFileName = Path.GetTempFileName();
|
---|
| 215 | WriteToFile(tempFileName,
|
---|
| 216 | "0,00\t 0,00\t 0,00\t 3,14" + 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" + Environment.NewLine +
|
---|
| 220 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 221 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
| 222 | TableFileParser parser = new TableFileParser();
|
---|
| 223 | try {
|
---|
| 224 | parser.Parse(tempFileName);
|
---|
| 225 | Assert.AreEqual(6, parser.Rows);
|
---|
| 226 | Assert.AreEqual(4, parser.Columns);
|
---|
| 227 | Assert.AreEqual(parser.Values[0, 3], 3.14);
|
---|
| 228 | }
|
---|
| 229 | finally {
|
---|
| 230 | File.Delete(tempFileName);
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | [TestMethod]
|
---|
| 235 | public void ParseGermanTabSeparatedWithNames() {
|
---|
| 236 | string tempFileName = Path.GetTempFileName();
|
---|
| 237 | WriteToFile(tempFileName,
|
---|
| 238 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
| 239 | "0,00\t 0,00\t 0,00\t 3,14" + 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" + Environment.NewLine +
|
---|
| 243 | "0,00\t 0,00\t 0,00\t 0,00" + Environment.NewLine +
|
---|
| 244 | "0,00\t 0,00\t 0,00\t 0,00");
|
---|
| 245 | TableFileParser parser = new TableFileParser();
|
---|
| 246 | try {
|
---|
| 247 | parser.Parse(tempFileName);
|
---|
| 248 | Assert.AreEqual(6, parser.Rows);
|
---|
| 249 | Assert.AreEqual(4, parser.Columns);
|
---|
| 250 | Assert.AreEqual(parser.Values[0, 3], 3.14);
|
---|
| 251 | }
|
---|
| 252 | finally {
|
---|
| 253 | File.Delete(tempFileName);
|
---|
| 254 | }
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | [TestMethod]
|
---|
| 258 | public void ParseEnglishTabSeparated() {
|
---|
| 259 | string tempFileName = Path.GetTempFileName();
|
---|
| 260 | WriteToFile(tempFileName,
|
---|
| 261 | "0.00\t 0.00\t 0.00\t 3.14" + 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" + Environment.NewLine +
|
---|
| 266 | "0.00\t 0.00\t 0.00\t 0.00");
|
---|
| 267 | TableFileParser parser = new TableFileParser();
|
---|
| 268 | try {
|
---|
| 269 | parser.Parse(tempFileName);
|
---|
| 270 | Assert.AreEqual(6, parser.Rows);
|
---|
| 271 | Assert.AreEqual(4, parser.Columns);
|
---|
| 272 | Assert.AreEqual(parser.Values[0, 3], 3.14);
|
---|
| 273 | }
|
---|
| 274 | finally {
|
---|
| 275 | File.Delete(tempFileName);
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 | [TestMethod]
|
---|
| 279 | public void ParseEnglishTabSeparatedWithNames() {
|
---|
| 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(parser.Values[0, 3], 3.14);
|
---|
| 295 | }
|
---|
| 296 | finally {
|
---|
| 297 | File.Delete(tempFileName);
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | [TestMethod]
|
---|
| 302 | public void ParseTabSeparatedWithoutCommas() {
|
---|
| 303 | string tempFileName = Path.GetTempFileName();
|
---|
| 304 | WriteToFile(tempFileName,
|
---|
| 305 | "0\t 0\t 0\t 3" + 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" + Environment.NewLine +
|
---|
| 309 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 310 | "0\t 0\t 0\t 0");
|
---|
| 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(parser.Values[0, 3], 3);
|
---|
| 317 | }
|
---|
| 318 | finally {
|
---|
| 319 | File.Delete(tempFileName);
|
---|
| 320 | }
|
---|
| 321 | }
|
---|
| 322 | [TestMethod]
|
---|
| 323 | public void ParseTabSeparatedWithoutCommasWithNames() {
|
---|
| 324 | string tempFileName = Path.GetTempFileName();
|
---|
| 325 | WriteToFile(tempFileName,
|
---|
| 326 | "x01\t x02\t x03\t x04" + Environment.NewLine +
|
---|
| 327 | "0\t 0\t 0\t 3" + 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" + Environment.NewLine +
|
---|
| 331 | "0\t 0\t 0\t 0" + Environment.NewLine +
|
---|
| 332 | "0\t 0\t 0\t 0");
|
---|
| 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(parser.Values[0, 3], 3);
|
---|
| 339 | }
|
---|
| 340 | finally {
|
---|
| 341 | File.Delete(tempFileName);
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | [TestMethod]
|
---|
| 346 | public void ParseGermanSpaceSeparated() {
|
---|
| 347 | string tempFileName = Path.GetTempFileName();
|
---|
| 348 | WriteToFile(tempFileName,
|
---|
| 349 | @"0,00 0,00 0,00 3,14
|
---|
| 350 | 0,00 0,00 0,00 0,00
|
---|
| 351 | 0,00 0,00 0,00 0,00
|
---|
| 352 | 0,00 0,00 0,00 0,00
|
---|
| 353 | 0,00 0,00 0,00 0,00
|
---|
| 354 | 0,00 0,00 0,00 0,00");
|
---|
| 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(parser.Values[0, 3], 3.14);
|
---|
| 361 | }
|
---|
| 362 | finally {
|
---|
| 363 | File.Delete(tempFileName);
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
| 366 | [TestMethod]
|
---|
| 367 | public void ParseGermanSpaceSeparatedWithNames() {
|
---|
| 368 | string tempFileName = Path.GetTempFileName();
|
---|
| 369 | WriteToFile(tempFileName,
|
---|
| 370 | @"x01 x02 x03 x04
|
---|
| 371 | 0,00 0,00 0,00 3,14
|
---|
| 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 | 0,00 0,00 0,00 0,00
|
---|
| 376 | 0,00 0,00 0,00 0,00");
|
---|
| 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(parser.Values[0, 3], 3.14);
|
---|
| 383 | }
|
---|
| 384 | finally {
|
---|
| 385 | File.Delete(tempFileName);
|
---|
| 386 | }
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | [TestMethod]
|
---|
| 390 | public void ParseEnglishSpaceSeparated() {
|
---|
| 391 | string tempFileName = Path.GetTempFileName();
|
---|
| 392 | WriteToFile(tempFileName,
|
---|
| 393 | @"0.00 0.00 0.00 3.14
|
---|
| 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 | 0.00 0.00 0.00 0.00
|
---|
| 398 | 0.00 0.00 0.00 0.00");
|
---|
| 399 | TableFileParser parser = new TableFileParser();
|
---|
| 400 | try {
|
---|
| 401 | parser.Parse(tempFileName);
|
---|
| 402 | Assert.AreEqual(6, parser.Rows);
|
---|
| 403 | Assert.AreEqual(4, parser.Columns);
|
---|
| 404 | Assert.AreEqual(parser.Values[0, 3], 3.14);
|
---|
| 405 | }
|
---|
| 406 | finally {
|
---|
| 407 | File.Delete(tempFileName);
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | [TestMethod]
|
---|
| 411 | public void ParseEnglishSpaceSeparatedWithNames() {
|
---|
| 412 | string tempFileName = Path.GetTempFileName();
|
---|
| 413 | WriteToFile(tempFileName,
|
---|
| 414 | @"x01 x02 x03 x04
|
---|
| 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(parser.Values[0, 3], 3.14);
|
---|
| 427 | }
|
---|
| 428 | finally {
|
---|
| 429 | File.Delete(tempFileName);
|
---|
| 430 | }
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | [TestMethod]
|
---|
| 434 | public void ParseSpaceSeparatedWithoutCommas() {
|
---|
| 435 | string tempFileName = Path.GetTempFileName();
|
---|
| 436 | WriteToFile(tempFileName,
|
---|
| 437 | @"0 0 0 3
|
---|
| 438 | 0 0 0 0
|
---|
| 439 | 0 0 0 0
|
---|
| 440 | 0 0 0 0
|
---|
| 441 | 0 0 0 0
|
---|
| 442 | 0 0 0 0");
|
---|
| 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(parser.Values[0, 3], 3);
|
---|
| 449 | }
|
---|
| 450 | finally {
|
---|
| 451 | File.Delete(tempFileName);
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 | [TestMethod]
|
---|
| 455 | public void ParseSpaceSeparatedWithoutCommasWithNames() {
|
---|
| 456 | string tempFileName = Path.GetTempFileName();
|
---|
| 457 | WriteToFile(tempFileName,
|
---|
| 458 | @"x01 x02 x03 x04
|
---|
| 459 | 0 0 0 3
|
---|
| 460 | 0 0 0 0
|
---|
| 461 | 0 0 0 0
|
---|
| 462 | 0 0 0 0
|
---|
| 463 | 0 0 0 0
|
---|
| 464 | 0 0 0 0");
|
---|
| 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(parser.Values[0, 3], 3);
|
---|
| 471 | }
|
---|
| 472 | finally {
|
---|
| 473 | File.Delete(tempFileName);
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 | private void WriteToFile(string fileName, string content) {
|
---|
| 478 | using (StreamWriter writer = new StreamWriter(fileName)) {
|
---|
| 479 | writer.Write(content);
|
---|
| 480 | }
|
---|
| 481 | }
|
---|
| 482 | }
|
---|
| 483 | }
|
---|