コード例 #1
0
        public void MovesSingleLine()
        {
            // ReSharper disable StringLiteralTypo
            AlphabetSoup puzzle = new AlphabetSoup {
                Solution = "abcdefghijklmnopqrstuvwxyz"
            };

            // ReSharper restore StringLiteralTypo
            puzzle.GenerateLineAtIndex(0);
            puzzle.ScrambleLines();
            bool foundSingleNonNullLine = false;

            foreach (string line in puzzle.Lines)
            {
                Console.WriteLine(line);
                if (foundSingleNonNullLine) //All other lines should be null.
                {
                    Assert.IsNull(line);
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        foundSingleNonNullLine = true;
                    }
                }
            }
        }
コード例 #2
0
        private void ApplyTest(String input, string expected)
        {
            AlphabetSoup calculator = new AlphabetSoup(input);
            string       result     = calculator.GetResult();

            Assert.AreEqual(expected, result);
        }
コード例 #3
0
            public void CreatesExpectedPuzzle()
            {
                AlphabetSoup puzzle = new AlphabetSoup(Repository);
                // ReSharper disable StringLiteralTypo
                const string SOLUTION = "greenredyellowpurpleorange";
                // ReSharper restore StringLiteralTypo
                List <string> lines = puzzle.GeneratePuzzle(SOLUTION);

                Assert.AreEqual(26, lines.Count);
                StringBuilder builder = new StringBuilder();

                foreach (string currentLine in lines)
                {
                    string tabDelimitedLine = string.Join('\t'.ToString(), currentLine.ToCharArray());
                    builder.AppendLine(tabDelimitedLine);
                }

                var formattedPuzzle = builder.ToString();

                Console.WriteLine(formattedPuzzle);

                for (int index = 0; index < 26; index++)
                {
                    string line       = lines[index];
                    string hiddenWord = AssertExactlyOneSubstringIsAWord(line);
                    Console.WriteLine($"{line} {hiddenWord.ToUpper()}");
                    Assert.AreEqual(SOLUTION[index], line[0], "Expected first letter in the line to match the solution.");
                    Assert.AreEqual((char)97 + index, line[3], "Expected the alphabet to be in the middle.");
                }
            }
コード例 #4
0
            public void Output_FitsExpectedFormat()
            {
                AlphabetSoup puzzle = new AlphabetSoup(Repository);
                string       line   = puzzle.GenerateSingleLine('a', 'b');

                Assert.AreEqual(7, line.Length, "Expected 7 letters.");

                AssertExactlyOneSubstringIsAWord(line);
            }
コード例 #5
0
        public void PopulatesExpectedLine()
        {
            // ReSharper disable StringLiteralTypo
            AlphabetSoup puzzle = new AlphabetSoup {
                Solution = "abcdefghijklmnopqrstuvwxyz"
            };

            // ReSharper restore StringLiteralTypo
            puzzle.GenerateLineAtIndex(0);
            Assert.AreEqual('a', puzzle.Lines[0][3], "Fourth character of this line should be 'a'");
        }
コード例 #6
0
            public void ExampleThatStartsInSecondPosition()
            {
                AlphabetSoup puzzle = new AlphabetSoup(Repository)
                {
                    RandomSeed = 1
                };

                // ReSharper disable StringLiteralTypo
                Assert.AreEqual("allayam", puzzle.GenerateSingleLine('a', 'a'));
                Assert.AreEqual("alabout", puzzle.GenerateSingleLine('a', 'b'));
                // ReSharper restore StringLiteralTypo
            }
コード例 #7
0
            public void CallTwice_GeneratesDifferentLines(StartPosition selectedPosition)
            {
                AlphabetSoup puzzle    = new AlphabetSoup(Repository);
                string       firstLine = puzzle.HideWordInLine("stuck", selectedPosition);

                Assert.AreEqual(7, firstLine.Length, "Expected 7 letters.");
                AssertExactlyOneSubstringIsAWord(firstLine);

                string secondLine = puzzle.HideWordInLine("stuck", selectedPosition);

                Assert.AreEqual(7, secondLine.Length, "Expected 7 letters.");
                AssertExactlyOneSubstringIsAWord(secondLine);

                Assert.AreNotEqual(firstLine, secondLine);
            }
コード例 #8
0
            public void SimpleTest_PutsWordInExpectedPosition()
            {
                AlphabetSoup puzzle = new AlphabetSoup(Repository);
                string       line   = puzzle.HideWordInLine("stuck", StartPosition.FirstPosition);

                Assert.AreEqual(7, line.Length, "Expected 7 letters.");
                Assert.AreEqual("stuck", line.Substring(0, 5), "Expected word in first position");
                AssertExactlyOneSubstringIsAWord(line);

                line = puzzle.HideWordInLine("stuck", StartPosition.SecondPosition);
                Assert.AreEqual(7, line.Length, "Expected 7 letters.");
                Assert.AreEqual("stuck", line.Substring(1, 5), "Expected word in second position");
                AssertExactlyOneSubstringIsAWord(line);

                line = puzzle.HideWordInLine("stuck", StartPosition.ThirdPosition);
                Assert.AreEqual(7, line.Length, "Expected 7 letters.");
                Assert.AreEqual("stuck", line.Substring(2, 5), "Expected word in third position");
                AssertExactlyOneSubstringIsAWord(line);
            }
コード例 #9
0
 public static string AlphabetSoupTests(string str)
 {
     return(AlphabetSoup.AlphabetSoupMethod(str));
 }
コード例 #10
0
        public void Default_UsesDefaultRepository()
        {
            AlphabetSoup puzzle = new AlphabetSoup();

            Assert.IsNotNull(puzzle);
        }