AnalysisTests.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 ReadModifySaveCheck()
  99. {
  100. var test = new Analysis(MainTestFile);
  101. var originalFirstFile = test.Data.FirstOrDefault();
  102. Assert.NotNull(originalFirstFile);
  103. originalFirstFile.NinentyFiveNineWords = 1050;
  104. var path = "testSave.csv";
  105. test.Save(path);
  106. var readTest = new Analysis(path);
  107. var readFirstFile = readTest.Data.FirstOrDefault();
  108. Assert.NotNull(readFirstFile);
  109. Assert.Equal(originalFirstFile.NinentyFiveNineWords, readFirstFile.NinentyFiveNineWords);
  110. File.Delete(path);
  111. }
  112. }
  113. }