public IEnumerable <WordCombination> FindAllPossibleCombinationsOfLength(IWordsIndex wordsIndex, int desiredLength)
        {
            if (wordsIndex == null)
            {
                throw new ArgumentNullException(nameof(wordsIndex));
            }
            if (desiredLength < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(desiredLength));
            }

            return(Enumerable
                   .Range(1, desiredLength - 1)
                   .SelectMany(i => wordsIndex.GetWordsOfLength(i)
                               .SelectMany(word => wordsIndex.GetWordsOfLength(desiredLength - i)
                                           .Select(otherWord => new WordCombination(word, otherWord)))));
        }
예제 #2
0
 public void SetUp()
 {
     _desiredLength = 6;
     _allWords      = new[] {
         new Word("albums"),
         new Word("al"),
         new Word("u"),
         new Word("ticket"),
         new Word("foul"),
         new Word("be"),
         new Word("befoul"),
         new Word("magazine"),
         new Word("bums"),
         new Word("trump")
     };
     _wordsIndex = new FakeWordsIndex(_allWords);
     _sut        = new AllPossibleCombinationsFinder();
 }