public void WordCannotHaveUnknowns()
        {
            var word    = "wh?t";
            var subject = new AnagramPuzzle(new KnownWords(Enumerable.Empty <string>()));

            Assert.Throws <ArgumentException>(() => subject.Solve(word));
            word = word.Replace(UnknownWord.UnknownToken, 'a');
            Assert.DoesNotThrow(() => subject.Solve(word), "removing the unknown character should have fixed issue of throwing ArgumentException");
        }
        public void AnagramNeedsAtLeastTwoLetters()
        {
            var word    = "A";
            var subject = new AnagramPuzzle(new KnownWords(Enumerable.Empty <string>()));

            Assert.Throws <ArgumentException>(() => subject.Solve(word));
            word = "AA";
            Assert.DoesNotThrow(() => subject.Solve(word), "Having at least 2 characters should have fixed issue of throwing ArgumentException");
        }
        public void SolveTest(KnownWords knownWords, string originalWord, string expectedAnagram)
        {
            var puzzle    = new AnagramPuzzle(knownWords);
            var solutions = puzzle.Solve(originalWord);

            Assert.That(solutions, Has.Member(expectedAnagram), "expected anagram was not in the list of solutions");
        }
        public void AnagramsDoNotIncludeOriginalWord()
        {
            var word       = "decorations";
            var knownWords = new KnownWords(new[] { "decorations", "coordinates" });
            var subject    = new AnagramPuzzle(knownWords);
            var anagrams   = subject.Solve(word);
            var expected   = new[] { "coordinates" };

            Assert.That(anagrams, Is.EquivalentTo(expected), "solved anagrams should not include the original word");
        }
Beispiel #5
0
        public static void AnagramMenu(KnownWords knownWords)
        {
            Console.WriteLine("Type in the word you want to find anagrams for:");
            var word          = _ReadLn();
            var anagramPuzzle = new AnagramPuzzle(knownWords);
            var answers       = anagramPuzzle.Solve(word).ToList();

            Console.WriteLine($"There are {answers.Count} possible anagrams:");
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
            SolveMoreOrQuit(knownWords);
        }