コード例 #1
0
ファイル: Benchmark.cs プロジェクト: rastyslaw/UidGenerator
 private void TestPrefixExistence(IPrefixMatcher sut, IList <string> testData)
 {
     for (int i = 0; i < testData.Count; i++)
     {
         sut.HasPrefix(testData[i]);
     }
 }
コード例 #2
0
        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");
            }
        }