public virtual void Setup(BenchmarkContext context)
        {
            var testAssemblyPath = Path.GetFullPath(GetType().Assembly.Location);
            var filesDirectory   = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "files/");

            Task.WhenAll(
                new[]
            {
                new Func <Task>(async() =>
                {
                    Checker = await WordList.CreateFromFilesAsync(Path.Combine(filesDirectory, "English (American).dic")).ConfigureAwait(false);
                }),
                new Func <Task>(async() =>
                {
                    Words = new List <string>();
                    using (var reader = new StreamReader(Path.Combine(filesDirectory, "List_of_common_misspellings.txt"), Encoding.UTF8, true))
                    {
                        string line;
                        while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
                        {
                            line = line.Trim();

                            if (line.Length == 0 || line.StartsWith("#") || line.StartsWith("["))
                            {
                                continue;
                            }

                            Words.AddRange(line.Split(WordSplitChars, StringSplitOptions.RemoveEmptyEntries));
                        }
                    }
                })
            }
                .Select(f => f())
                ).Wait();
        }
示例#2
0
            public async Task can_find_good_words_in_dictionary(string dictionaryFilePath, string word)
            {
                var dictionary = await WordList.CreateFromFilesAsync(dictionaryFilePath);

                var checkResult = dictionary.Check(word);

                checkResult.Should().BeTrue();
            }
示例#3
0
            public async Task words_without_suggestions_offer_no_suggestions(string dictionaryFilePath, string word)
            {
                var dictionary = await WordList.CreateFromFilesAsync(dictionaryFilePath);

                var actual = dictionary.Suggest(word);

                actual.Should().BeEmpty();
            }
示例#4
0
            public async Task can_find_correct_best_suggestion(string dictionaryFilePath, string givenWord, string[] expectedSuggestions)
            {
                var dictionary = await WordList.CreateFromFilesAsync(dictionaryFilePath);

                var actual = dictionary.Suggest(givenWord);

                actual.Should().NotBeNullOrEmpty();
                actual.ShouldBeEquivalentTo(expectedSuggestions);
            }
示例#5
0
            public async Task words_offer_at_least_suggestions_in_any_order(string dictionaryFilePath, string word, string[] expectedSuggestions)
            {
                var dictionary = await WordList.CreateFromFilesAsync(dictionaryFilePath);

                var actual = dictionary.Suggest(word);

                actual.Should().NotBeNullOrEmpty();
                actual.Should().Contain(expectedSuggestions);
            }
示例#6
0
            public async Task words_offer_specific_suggestions(string dictionaryFilePath, string word, string[] expectedSuggestions)
            {
                var dictionary = await WordList.CreateFromFilesAsync(dictionaryFilePath);

                var actual = dictionary.Suggest(word);

                actual.Should().NotBeNullOrEmpty();
                actual.ShouldBeEquivalentTo(expectedSuggestions);
            }
 public void Benchmark(BenchmarkContext context)
 {
     foreach (var filePair in TestFiles)
     {
         var checker = WordList.CreateFromFilesAsync(filePair.DictionaryFilePath, filePair.AffixFilePath).GetAwaiter().GetResult();
         checker.Check(TestWord);
         FilePairsLoaded.Increment();
     }
 }
示例#8
0
            public async Task checking_large_word_does_not_cause_errors(string filePath)
            {
                // attampt to reproduce https://github.com/hunspell/hunspell/issues/446
                var largeInput = new string('X', 102);
                var dictionary = await WordList.CreateFromFilesAsync(filePath);

                var actual = dictionary.Check(largeInput);

                actual.Should().BeFalse();
            }
        public override void Setup(BenchmarkContext context)
        {
            base.Setup(context);

            var testAssemblyPath = Path.GetFullPath(GetType().Assembly.Location);
            var filesDirectory   = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "files/");

            Checker = WordList.CreateFromFilesAsync(Path.Combine(filesDirectory, "English (American).dic")).GetAwaiter().GetResult();

            WordsChecked = context.GetCounter(nameof(WordsChecked));
        }
            public async Task can_find_good_words_in_dictionary(string dictionaryFilePath, string word)
            {
                if (dictionaryFilePath.EndsWith("base_utf.dic") && word.Contains("İ"))
                {
                    // NOTE: These tests are bypassed because capitalization only works when the language is turkish and the UTF8 dic has no language applied
                    return;
                }

                var dictionary = await WordList.CreateFromFilesAsync(dictionaryFilePath);

                var checkResult = dictionary.Check(word);

                checkResult.Should().BeTrue();
            }
            public async Task can_find_correct_best_suggestion(string dictionaryFilePath, string givenWord, string[] expectedSuggestions)
            {
                var dictionary = await WordList.CreateFromFilesAsync(dictionaryFilePath);

                var actual = dictionary.Suggest(givenWord);

                actual.Should().NotBeNull();

                // ',' can either be a delimiter in the test data or part of the data
                var actualText   = string.Join(", ", actual);
                var expectedText = string.Join(", ", expectedSuggestions);

                actualText.Should().Be(expectedText);
            }
 protected Task <WordList> LoadEnUsAsync() =>
 WordList.CreateFromFilesAsync("files/English (American).dic");