Example #1
0
        private void DoTest(
            string first, string second,
            int expectedSubsequenceLength)
        {
            var firstSequence  = first.Split(' ').ToList();
            var secondSequence = second.Split(' ').ToList();
            var actual         = My_LongestCommonSubsequenceCalculator.Calculate(firstSequence, secondSequence);

            Assert.AreEqual(expectedSubsequenceLength, actual.Count);
            AssertSubsequence(actual, firstSequence);
            AssertSubsequence(actual, secondSequence);
            Assert.IsTrue(actual.All(firstSequence.Contains), // Contains будет сравнивать токены по ссылкам
                          nameof(My_LongestCommonSubsequenceCalculator) + " должен возвращать токены первого документа");
        }
Example #2
0
        private static void GenerateReport(List <DocumentContent> documents, IEnumerable <ComparisonResult> comparisonResults)
        {
            bool isNotImplemented = false;
            var  stringWriter     = new StringWriter();

            stringWriter.WriteLine(HtmlBegin);
            using (var writer = new HtmlTextWriter(stringWriter))
            {
                foreach (var comparisonResult in comparisonResults)
                {
                    var first              = documents.Find(d => d.Tokens == comparisonResult.Document1);
                    var second             = documents.Find(d => d.Tokens == comparisonResult.Document2);
                    var normalizedDistanze = GetNormalizedDistance(comparisonResult);
                    Console.WriteLine(
                        $"Расширенное расстояние Левенштейна между \"{first.DocumentName}\" и \"{second.DocumentName}\" равно {normalizedDistanze}");
                    List <string> commonSequence;
                    try
                    {
                        commonSequence = My_LongestCommonSubsequenceCalculator.Calculate(first.Tokens, second.Tokens);
                    }
                    catch (NotImplementedException)
                    {
                        isNotImplemented = true;
                        continue;
                    }

                    SaveResult(first, second, commonSequence, writer);
                }
            }
            stringWriter.WriteLine(HtmlEnd);

            if (isNotImplemented)
            {
                Console.WriteLine("Для генерации отчёта реализуйте класс \"LondestCommonSubsequenceCalculator\"");
            }
            else
            {
                var fileName = Path.Combine(Folders.ComparisonResults.FullName);
                File.WriteAllText(fileName, stringWriter.ToString());
                Console.WriteLine($"Отчёт находится в файле:\n{Folders.ComparisonResults}");
            }
        }