private void TestPrefixCompletionSuggestions(IPrefixMatcher sut, IList <string> testData) { for (int i = 0; i < testData.Count; i++) { IList <string> prefixes = sut.GetWordsByPrefix(testData[i]).Take(10).ToList(); //to list ensures we actually use the generator if there is a generator implementation underneath //take limits number of responses like somebody would do on a drop down list } }
private void AssertHaveProvidedWords(IPrefixMatcher tester, IEnumerable <string> words) { var orderedWords = words.OrderBy(x => x).ToArray(); var testerWords = tester.GetWordsByPrefix("").OrderBy(x => x).ToArray(); try { Assert.Equal(orderedWords, testerWords); } catch (EqualException) { var onlyInTester = string.Join(", ", testerWords.Except(orderedWords)); var onlyInExpected = string.Join(", ", orderedWords.Except(testerWords)); var duplicates = string.Join(", ", testerWords.GroupBy(x => x).Select(x => new { count = x.Count(), word = x.Key }).Where(x => x.count > 1)); Assert.True(false, $"Collections differ:\nOnly in tester: {onlyInTester}\nOnly in expected: {onlyInExpected}\nDuplicates: {duplicates}"); } foreach (var word in orderedWords) { Assert.True(tester.HasPrefix(word), $"Prefix: {word} should exist in Dawg, but its not"); Assert.True(tester.HasWord(word), $"Word: {word} should exist in Dawg, but its not"); } }