Changeset 14029 for branches/crossvalidation-2434/HeuristicLab.Tests/HeuristicLab.Problems.Instances.DataAnalysis-3.3
- Timestamp:
- 07/08/16 14:40:02 (8 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Tests
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Tests/HeuristicLab.Problems.Instances.DataAnalysis-3.3/TableFileParserTest.cs
r12012 r14029 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Globalization; 23 25 using System.IO; 24 26 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 589 591 } 590 592 593 594 [TestMethod] 595 [TestCategory("Problems.Instances")] 596 [TestProperty("Time", "short")] 597 public void ParseWithColumnTypeConversionDE() { 598 // If first entry of a column can be parsed as a double we assume all values are doubles. 599 // However, if any of the following entries cannot be parsed as a double we convert the whole column to a string column. 600 // Special care needs to be taken with missing values, NaN (n.def.) and infinity values. 601 // We only support DE-DE and InvariantCulture number formats 602 string tempFileName = Path.GetTempFileName(); 603 var deCultureInfo = CultureInfo.GetCultureInfo("DE-DE"); 604 WriteToFile(tempFileName, 605 "str\tdbl\tdbl\tdbl" + Environment.NewLine + 606 "1,3\t1,3\t0\t3" + Environment.NewLine + 607 "1,3\t\t0\t0" + Environment.NewLine + 608 "s\t" + double.NaN.ToString(deCultureInfo) + "\t0\t0" + Environment.NewLine + // double.NaN might have a different string representation on different systems (even when using the same CultureInfo) 609 "s\t" + double.PositiveInfinity.ToString(deCultureInfo) + "\t0\t0" + Environment.NewLine + 610 "s\t" + double.NegativeInfinity.ToString(deCultureInfo) + "\t0\t0" + Environment.NewLine + 611 "s\t0\t0\t0"); 612 TableFileParser parser = new TableFileParser(); 613 try { 614 parser.Parse(tempFileName, 615 deCultureInfo.NumberFormat, 616 deCultureInfo.DateTimeFormat, 617 '\t', 618 true); 619 Assert.AreEqual(6, parser.Rows); 620 Assert.AreEqual(4, parser.Columns); 621 Assert.IsTrue(parser.Values[0] is List<string>); 622 Assert.IsTrue(parser.Values[1] is List<double>); 623 Assert.IsTrue(parser.Values[2] is List<double>); 624 Assert.IsTrue(parser.Values[3] is List<double>); 625 Assert.IsTrue(double.IsNaN((double)parser.Values[1][1])); // missing value 626 Assert.IsTrue(double.IsNaN((double)parser.Values[1][2])); 627 Assert.IsTrue(double.IsPositiveInfinity((double)parser.Values[1][3])); // NOTE: in DE-DE NumberFormat just "unendlich" is not allowed (compare with InvariantCulture) 628 Assert.IsTrue(double.IsNegativeInfinity((double)parser.Values[1][4])); 629 } finally { 630 File.Delete(tempFileName); 631 } 632 } 633 634 [TestMethod] 635 [TestCategory("Problems.Instances")] 636 [TestProperty("Time", "short")] 637 public void ParseWithColumnTypeConversionInvariant() { 638 // see ParseWithColumnTypeConversionDE above 639 // same routine only using invariant culture 640 string tempFileName = Path.GetTempFileName(); 641 WriteToFile(tempFileName, 642 @"str,dbl,dbl,dbl 643 1.3,1.3,0,3 644 1.3,,0,0 645 s,NaN,0,0 646 s,Infinity,0,0 647 s,-Infinity,0,0 648 s,0,0,0"); 649 TableFileParser parser = new TableFileParser(); 650 try { 651 parser.Parse(tempFileName, 652 CultureInfo.InvariantCulture.NumberFormat, 653 CultureInfo.InvariantCulture.DateTimeFormat, 654 ',', 655 parser.AreColumnNamesInFirstLine(tempFileName)); 656 Assert.AreEqual(6, parser.Rows); 657 Assert.AreEqual(4, parser.Columns); 658 Assert.IsTrue(parser.Values[0] is List<string>); 659 Assert.IsTrue(parser.Values[1] is List<double>); 660 Assert.IsTrue(parser.Values[2] is List<double>); 661 Assert.IsTrue(parser.Values[3] is List<double>); 662 Assert.IsTrue(double.IsNaN((double)parser.Values[1][1])); // missing value 663 Assert.IsTrue(double.IsNaN((double)parser.Values[1][2])); 664 Assert.IsTrue(double.IsPositiveInfinity((double)parser.Values[1][3])); // NOTE: in InvariantCulture +Infinity is not allowed (compare with DE-DE) 665 Assert.IsTrue(double.IsNegativeInfinity((double)parser.Values[1][4])); 666 } finally { 667 File.Delete(tempFileName); 668 } 669 } 670 591 671 private void WriteToFile(string fileName, string content) { 592 672 using (StreamWriter writer = new StreamWriter(fileName)) {
Note: See TracChangeset
for help on using the changeset viewer.