diff --git a/src/UglyToad.PdfPig.Tests/Dla/DlaHelper.cs b/src/UglyToad.PdfPig.Tests/Dla/DlaHelper.cs index ea1bf803..40a59922 100644 --- a/src/UglyToad.PdfPig.Tests/Dla/DlaHelper.cs +++ b/src/UglyToad.PdfPig.Tests/Dla/DlaHelper.cs @@ -2,16 +2,23 @@ { internal static class DlaHelper { + private static readonly string DlaFolder = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Dla", "Documents")); + private static readonly string IntegrationFolder = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Integration", "Documents")); + public static string GetDocumentPath(string name, bool isPdf = true) { - var documentFolder = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Dla", "Documents")); - if (!name.EndsWith(".pdf") && isPdf) { name += ".pdf"; } - return Path.Combine(documentFolder, name); + string doc = Path.Combine(DlaFolder, name); + if (File.Exists(doc)) + { + return doc; + } + + return Path.Combine(IntegrationFolder, name); } } } \ No newline at end of file diff --git a/src/UglyToad.PdfPig.Tests/Dla/Documents/caly-issues-56-1.pdf b/src/UglyToad.PdfPig.Tests/Dla/Documents/caly-issues-56-1.pdf new file mode 100644 index 00000000..7ca04dfa Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Dla/Documents/caly-issues-56-1.pdf differ diff --git a/src/UglyToad.PdfPig.Tests/Dla/Documents/caly-issues-58-2.pdf b/src/UglyToad.PdfPig.Tests/Dla/Documents/caly-issues-58-2.pdf new file mode 100644 index 00000000..2f27af0e Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Dla/Documents/caly-issues-58-2.pdf differ diff --git a/src/UglyToad.PdfPig.Tests/Dla/Documents/fseprd1102849.pdf b/src/UglyToad.PdfPig.Tests/Dla/Documents/fseprd1102849.pdf new file mode 100644 index 00000000..a08d7ecc Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Dla/Documents/fseprd1102849.pdf differ diff --git a/src/UglyToad.PdfPig.Tests/Dla/NearestNeighbourWordExtractorTests.cs b/src/UglyToad.PdfPig.Tests/Dla/NearestNeighbourWordExtractorTests.cs index 90ac7748..d9cb607f 100644 --- a/src/UglyToad.PdfPig.Tests/Dla/NearestNeighbourWordExtractorTests.cs +++ b/src/UglyToad.PdfPig.Tests/Dla/NearestNeighbourWordExtractorTests.cs @@ -4,19 +4,84 @@ public class NearestNeighbourWordExtractorTests { - [Fact] - public void Words2559Doc() + public static IEnumerable DataWords => new[] { - // Microsoft Word count of words = 2559 + new object[] + { + "2559 words.pdf", + 5118, + 2559 + }, + new object[] + { + "fseprd1102849.pdf", + 12903, + 11177 + }, + new object[] + { + "90 180 270 rotated.pdf", + 589, + 292 + }, + new object[] + { + "complex rotated.pdf", + 805, + 403 + }, + new object[] + { + "no horizontal distance.pdf", + 4, + 2 + }, + new object[] + { + "no vertical distance.pdf", + 22, + 10 + }, + new object[] + { + "no vertical horizontal distance.pdf", + 4, + 2 + }, + new object[] + { + "Random 2 Columns Lists Hyph - Justified.pdf", + 1191, + 607 + }, + new object[] + { + "caly-issues-56-1.pdf", + 184, + 156 + }, + new object[] + { + "caly-issues-58-2.pdf", + 49, + 49 + }, + }; - using (var document = PdfDocument.Open(DlaHelper.GetDocumentPath("2559 words.pdf"))) + [SkippableTheory] + [MemberData(nameof(DataWords))] + public void WordCount(string path, int wordCount, int noSpacesWordCount) + { + using (var document = PdfDocument.Open(DlaHelper.GetDocumentPath(path))) { var page = document.GetPage(1); var words = NearestNeighbourWordExtractor.Instance.GetWords(page.Letters).ToArray(); + Assert.Equal(wordCount, words.Length); + var noSpacesWords = words.Where(x => !string.IsNullOrEmpty(x.Text.Trim())).ToArray(); - Assert.Equal(2559, noSpacesWords.Length); + Assert.Equal(noSpacesWordCount, noSpacesWords.Length); } } } diff --git a/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj b/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj index a4f32175..be423630 100644 --- a/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj +++ b/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj @@ -101,9 +101,18 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest + + PreserveNewest + PreserveNewest