AnalysisTests.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using System.IO;
  2. using System.Linq;
  3. using memoQAnalysis;
  4. using Xunit;
  5. namespace memoQAnalysisTests
  6. {
  7. public class AnalysisTests
  8. {
  9. private const string MainTestFile = "./testFiles/utf8.csv";
  10. private const string UTF16TestFile = "./testFiles/utf16.csv";
  11. private const string UTF16NoHeaderTestFile = "./testFiles/utf16NoHeader.csv";
  12. [Fact]
  13. public void ReadAnalysisUTF8Comma()
  14. {
  15. var test = new Analysis(MainTestFile);
  16. Assert.Equal(3, test.Data.Count);
  17. }
  18. [Fact]
  19. public void ReadAnalysisUTF16Semicolon()
  20. {
  21. var test = new Analysis(UTF16TestFile, ";");
  22. Assert.Equal(3, test.Data.Count);
  23. }
  24. [Fact]
  25. public void ReadAnalysisUTF16SemicolonNoHeader()
  26. {
  27. var test = new Analysis(UTF16NoHeaderTestFile, ";");
  28. Assert.Equal(3, test.Data.Count);
  29. }
  30. [Fact]
  31. public void WordsToTranslateWithoutRepetitions()
  32. {
  33. var test = new Analysis(MainTestFile);
  34. Assert.Equal(0, test.WordsToTranslateWithoutRepetitions());
  35. }
  36. [Fact]
  37. public void WordsToTranslateWithRepetitions()
  38. {
  39. var test = new Analysis(MainTestFile);
  40. Assert.Equal(601, test.WordsToTranslateWithRepetitions());
  41. }
  42. [Fact]
  43. public void ReadAnalysisFromBytes()
  44. {
  45. var data = File.ReadAllBytes(UTF16TestFile);
  46. var test = new Analysis(data);
  47. Assert.Equal(3, test.Data.Count);
  48. }
  49. [Fact]
  50. public void TotalWords()
  51. {
  52. var test = new Analysis(MainTestFile);
  53. var total = test.Data.Sum(x => x.TotalWords);
  54. var originalFirstFile = test.Data.FirstOrDefault();
  55. Assert.NotNull(originalFirstFile);
  56. originalFirstFile.NinentyFiveNineWords = 1050;
  57. var expectedTotal = total + 1050;
  58. var newTotal = test.Data.Sum(x => x.TotalWords);
  59. Assert.Equal(expectedTotal, newTotal);
  60. }
  61. [Fact]
  62. public void TotalSegments()
  63. {
  64. var test = new Analysis(MainTestFile);
  65. var total = test.Data.Sum(x => x.TotalSegments);
  66. var originalFirstFile = test.Data.FirstOrDefault();
  67. Assert.NotNull(originalFirstFile);
  68. originalFirstFile.FiftySeventyFourSegments += 1050;
  69. var expectedTotal = total + 1050;
  70. var newTotal = test.Data.Sum(x => x.TotalSegments);
  71. Assert.Equal(expectedTotal, newTotal);
  72. }
  73. [Fact]
  74. public void TotalCharacters()
  75. {
  76. var test = new Analysis(MainTestFile);
  77. var total = test.Data.Sum(x => x.TotalCharacters);
  78. var originalFirstFile = test.Data.FirstOrDefault();
  79. Assert.NotNull(originalFirstFile);
  80. originalFirstFile.RepetitionsCharacters += 1050;
  81. var expectedTotal = total + 1050;
  82. var newTotal = test.Data.Sum(x => x.TotalCharacters);
  83. Assert.Equal(expectedTotal, newTotal);
  84. }
  85. [Fact]
  86. public void TotalAsianCharacters()
  87. {
  88. var test = new Analysis(MainTestFile);
  89. var total = test.Data.Sum(x => x.TotalAsianCharacters);
  90. var originalFirstFile = test.Data.FirstOrDefault();
  91. Assert.NotNull(originalFirstFile);
  92. originalFirstFile.HundredAsianCharacters += 1050;
  93. var expectedTotal = total + 1050;
  94. var newTotal = test.Data.Sum(x => x.TotalAsianCharacters);
  95. Assert.Equal(expectedTotal, newTotal);
  96. }
  97. [Fact]
  98. public void TotalTags()
  99. {
  100. var test = new Analysis(MainTestFile);
  101. var total = test.Data.Sum(x => x.TotalTags);
  102. var originalFirstFile = test.Data.FirstOrDefault();
  103. Assert.NotNull(originalFirstFile);
  104. originalFirstFile.HundredOneTags += 1050;
  105. var expectedTotal = total + 1050;
  106. var newTotal = test.Data.Sum(x => x.TotalTags);
  107. Assert.Equal(expectedTotal, newTotal);
  108. }
  109. [Fact]
  110. public void TotalReserved1()
  111. {
  112. var test = new Analysis(MainTestFile);
  113. var total = test.Data.Sum(x => x.TotalReserved1);
  114. var originalFirstFile = test.Data.FirstOrDefault();
  115. Assert.NotNull(originalFirstFile);
  116. originalFirstFile.NoMatchReserved1 += 1050;
  117. var expectedTotal = total + 1050;
  118. var newTotal = test.Data.Sum(x => x.TotalReserved1);
  119. Assert.Equal(expectedTotal, newTotal);
  120. }
  121. [Fact]
  122. public void TotalReserved2()
  123. {
  124. var test = new Analysis(MainTestFile);
  125. var total = test.Data.Sum(x => x.TotalReserved2);
  126. var originalFirstFile = test.Data.FirstOrDefault();
  127. Assert.NotNull(originalFirstFile);
  128. originalFirstFile.EightyFiveNinentyFourReserved2 += 1050;
  129. var expectedTotal = total + 1050;
  130. var newTotal = test.Data.Sum(x => x.TotalReserved2);
  131. Assert.Equal(expectedTotal, newTotal);
  132. }
  133. [Fact]
  134. public void TotalReserved3()
  135. {
  136. var test = new Analysis(MainTestFile);
  137. var total = test.Data.Sum(x => x.TotalReserved3);
  138. var originalFirstFile = test.Data.FirstOrDefault();
  139. Assert.NotNull(originalFirstFile);
  140. originalFirstFile.SeventyFiveEightyFourReserved3 += 1050;
  141. var expectedTotal = total + 1050;
  142. var newTotal = test.Data.Sum(x => x.TotalReserved3);
  143. Assert.Equal(expectedTotal, newTotal);
  144. }
  145. [Fact]
  146. public void ReadModifySaveCheck()
  147. {
  148. var test = new Analysis(MainTestFile);
  149. var originalFirstFile = test.Data.FirstOrDefault();
  150. Assert.NotNull(originalFirstFile);
  151. originalFirstFile.NinentyFiveNineWords = 1050;
  152. var path = "testSave.csv";
  153. test.Save(path);
  154. var readTest = new Analysis(path);
  155. var readFirstFile = readTest.Data.FirstOrDefault();
  156. Assert.NotNull(readFirstFile);
  157. Assert.Equal(originalFirstFile.NinentyFiveNineWords, readFirstFile.NinentyFiveNineWords);
  158. File.Delete(path);
  159. }
  160. [Fact]
  161. public void TestHeader()
  162. {
  163. const string headerComma = ",,X-translated,,,,,,,,101%,,,,,,,,Repetitions,,,,,,,,100%,,,,,,,,95% - 99%,,,,,,,,85% - 94%,,,,,,,,75% - 84%,,,,,,,,50% - 74%,,,,,,,,No match,,,,,,,,Fragments,,,,,,,,Total,,,,,,,,";
  164. const string headerSemicolon = ";;X-translated;;;;;;;;101%;;;;;;;;Repetitions;;;;;;;;100%;;;;;;;;95% - 99%;;;;;;;;85% - 94%;;;;;;;;75% - 84%;;;;;;;;50% - 74%;;;;;;;;No match;;;;;;;;Fragments;;;;;;;;Total;;;;;;;;";
  165. const string headerTab =
  166. @" X-translated 101% Repetitions 100% 95% - 99% 85% - 94% 75% - 84% 50% - 74% No match Fragments Total ";
  167. var test = new Analysis(MainTestFile);
  168. Assert.Equal(headerComma, test.Header);
  169. test.Delimiter = ";";
  170. Assert.Equal(headerSemicolon, test.Header);
  171. test.Delimiter = "\t";
  172. Assert.Equal(headerTab, test.Header);
  173. }
  174. }
  175. }