public void SolveNullLetters()
        {
            var puzzle = new WordSlidePuzzle(new KnownWords(Enumerable.Empty <string>()));
            var ex     = Assert.Throws <ArgumentNullException>(() => puzzle.Solve("test", availableLetters: null));

            Assert.That(ex.ParamName, Is.EqualTo("availableLetters"), "had ArgumentNullException but not for expected parameter");
        }
        public void SolveNullUnknown()
        {
            var puzzle = new WordSlidePuzzle(new KnownWords(Enumerable.Empty <string>()));
            var ex     = Assert.Throws <ArgumentNullException>(() => puzzle.Solve(pattern: null, Array.Empty <char[]>()));

            Assert.That(ex.ParamName, Is.EqualTo("pattern"), "had ArgumentNullException but not for expected parameter");
        }
        public void SolveSingleWord(KnownWords knownWords, string wordPattern, char[][] letters, string expectedWord)
        {
            var puzzle    = new WordSlidePuzzle(knownWords);
            var solutions = puzzle.Solve(wordPattern, letters);

            Assert.That(solutions.Contains(expectedWord));
        }
        public void SolveLetterSizeMismatch()
        {
            var puzzle = new WordSlidePuzzle(new KnownWords(Enumerable.Empty <string>()));

            char[][] letters =
            {
                new[] { 'a' },
                new[] { 'b' },
                new[] { 'c' }
            };
            var ex = Assert.Throws <ArgumentException>(() => puzzle.Solve("????", letters));

            Assert.That(ex.Message, Is.EqualTo("The partial word had a length of 4 but the available letters only had 3 slots."));
        }
Exemplo n.º 5
0
        public static void WordSlideMenu(KnownWords knownWords)
        {
            Console.WriteLine($"Enter what you know about the word with {UnknownWord.UnknownToken} for missing characters:");
            var wordPattern = _ReadLn();

            char[][] availableLetters = _ReadWordSlideLetters(wordPattern);
            var      wordSlide        = new WordSlidePuzzle(knownWords);
            var      answers          = wordSlide.Solve(wordPattern, availableLetters).ToList();

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

            SolveMoreOrQuit(knownWords);
        }
        public void SolveNullSubWordAvailableLetterMismatch()
        {
            var knownWord  = "four";
            var knownWords = new KnownWords(new [] { knownWord });
            //var unknownWord = new UnknownWord(new string(UnknownWord.UnknownToken, knownWord.Length + 1));
            var wordPattern = new string(UnknownWord.UnknownToken, knownWord.Length + 1);

            Assert.That(knownWords.AllWordsOfLength(wordPattern.Length), Is.Empty, "precondition: there is no known word the length of the unknown word");
            //Assert.That(unknownWord.SubWordCounts, Is.Null, "precondition: unknownWord.SubWordCounts must be null");
            var puzzle           = new WordSlidePuzzle(knownWords);
            var availableLetters = new char[wordPattern.Length][];

            for (var i = 0; i < availableLetters.Length; i++)
            {
                availableLetters[i] = new[] { 'X' };
            }

            var solutions = puzzle.Solve(wordPattern, availableLetters);

            Assert.That(solutions, Is.Empty, "If there are no known words of the required length the solution should be empty");
        }