Browse Source

Added TestHeader and delimiter is now public

Piotr Czajkowski 2 years ago
parent
commit
31b02914fd
2 changed files with 38 additions and 6 deletions
  1. 19 5
      memoQAnalysis/Analysis.cs
  2. 19 1
      memoQAnalysisTests/AnalysisTests.cs

+ 19 - 5
memoQAnalysis/Analysis.cs

@@ -14,17 +14,31 @@ namespace memoQAnalysis
         public List<MemoQAnalysis> Data { get; }
         public Encoding OutputEncoding = Encoding.Unicode;
 
-        private readonly string _delimiter;
+        private const string HeaderComma = ",,X-translated,,,,,,,,101%,,,,,,,,Repetitions,,,,,,,,100%,,,,,,,,95% - 99%,,,,,,,,85% - 94%,,,,,,,,75% - 84%,,,,,,,,50% - 74%,,,,,,,,No match,,,,,,,,Fragments,,,,,,,,Total,,,,,,,,";
+        private const string HeaderSemicolon =
+            ";;X-translated;;;;;;;;101%;;;;;;;;Repetitions;;;;;;;;100%;;;;;;;;95% - 99%;;;;;;;;85% - 94%;;;;;;;;75% - 84%;;;;;;;;50% - 74%;;;;;;;;No match;;;;;;;;Fragments;;;;;;;;Total;;;;;;;;";
+        public string Delimiter;
+
+        public string Header
+        {
+            get
+            {
+                if (Delimiter.Equals(",")) return HeaderComma;
+                if (Delimiter.Equals(";")) return HeaderSemicolon;
+
+                return HeaderComma.Replace(",", Delimiter);
+            }
+        }
 
         public Analysis(string path, string delimiter = ",")
         {
-            _delimiter = delimiter;
+            Delimiter = delimiter;
             Data = ReadFromFile(path);
         }
 
         public Analysis(byte[] data, string delimiter = ";")
         {
-            _delimiter = delimiter;
+            Delimiter = delimiter;
             Data = ReadData(data);
         }
 
@@ -40,7 +54,7 @@ namespace memoQAnalysis
         {
             var configuration = new CsvConfiguration(CultureInfo.InvariantCulture)
             {
-                Delimiter = _delimiter
+                Delimiter = Delimiter
             };
 
             using (var csv = new CsvReader(streamReader, configuration))
@@ -96,7 +110,7 @@ namespace memoQAnalysis
         {
             var configuration = new CsvConfiguration(CultureInfo.InvariantCulture)
             {
-                Delimiter = _delimiter
+                Delimiter = Delimiter
             };
             configuration.RegisterClassMap<MemoQAnalysisMapping>();
 

+ 19 - 1
memoQAnalysisTests/AnalysisTests.cs

@@ -45,7 +45,7 @@ namespace memoQAnalysisTests
             var test = new Analysis(MainTestFile);
             Assert.Equal(601, test.WordsToTranslateWithRepetitions());
         }
-        
+
         [Fact]
         public void ReadAnalysisFromBytes()
         {
@@ -192,5 +192,23 @@ namespace memoQAnalysisTests
 
             File.Delete(path);
         }
+
+        [Fact]
+        public void TestHeader()
+        {
+            const string headerComma = ",,X-translated,,,,,,,,101%,,,,,,,,Repetitions,,,,,,,,100%,,,,,,,,95% - 99%,,,,,,,,85% - 94%,,,,,,,,75% - 84%,,,,,,,,50% - 74%,,,,,,,,No match,,,,,,,,Fragments,,,,,,,,Total,,,,,,,,";
+            const string headerSemicolon = ";;X-translated;;;;;;;;101%;;;;;;;;Repetitions;;;;;;;;100%;;;;;;;;95% - 99%;;;;;;;;85% - 94%;;;;;;;;75% - 84%;;;;;;;;50% - 74%;;;;;;;;No match;;;;;;;;Fragments;;;;;;;;Total;;;;;;;;";
+            const string headerTab =
+            @"		X-translated								101%								Repetitions								100%								95% - 99%								85% - 94%								75% - 84%								50% - 74%								No match								Fragments								Total								";
+
+            var test = new Analysis(MainTestFile);
+            Assert.Equal(headerComma, test.Header);
+
+            test.Delimiter = ";";
+            Assert.Equal(headerSemicolon, test.Header);
+
+            test.Delimiter = "\t";
+            Assert.Equal(headerTab, test.Header);
+        }
     }
 }