Exemple #1
0
            public void FiveLetters_VisitsAllRows()
            {
                LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(3)
                {
                    RandomSeed = 1
                };

                puzzle.PlaceSolution("12345");
                Console.WriteLine(puzzle.FormatHtmlForGoogle());
                //The third box (in the center) should go down, not up.
                Assert.AreEqual(Direction.Down, puzzle.GetCellAtCoordinates(1, 1).Direction);
            }
Exemple #2
0
            public void SetsExpectedClue_ClueAppearsInHtml()
            {
                LettersAndArrowsPuzzle fourByFourPuzzle = new LettersAndArrowsPuzzle("OHIO", true, 4, 42);

                fourByFourPuzzle.SetClueForRowIndex(0, "Vending machine bills");                       //ONES
                fourByFourPuzzle.SetClueForRowIndex(1, "They have their pluses and minuses");          //IONS
                fourByFourPuzzle.SetClueForRowIndex(2, "Try to gain favor by cringing or flattering"); //FAWN
                fourByFourPuzzle.SetClueForRowIndex(3, "Optimist's feeling");                          //HOPE

                string puzzleAsHtml = fourByFourPuzzle.FormatHtmlForGoogle();

                StringAssert.Contains("Vending machine bills", puzzleAsHtml);
                StringAssert.Contains("They have their pluses and minuses", puzzleAsHtml);
                StringAssert.Contains("Try to gain favor by cringing or flattering", puzzleAsHtml);
                StringAssert.Contains("Optimist's feeling", puzzleAsHtml);
            }
Exemple #3
0
            public void OHIO_CreatesExpectedFile()
            {
                const string HTML_DIRECTORY   = @"html\LettersAndArrows\";
                string       SOURCE_DIRECTORY = ConfigurationManager.AppSettings["SourceDirectory"] + "LettersAndArrows";

                LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle("ohio", true, 4, 42);

                puzzle.FillEmptyCells();
                string generateHtml = puzzle.FormatHtmlForGoogle();

                File.WriteAllText(HTML_DIRECTORY + "actualExample1.html", generateHtml);
                var  expectedLines     = File.ReadAllLines(HTML_DIRECTORY + "expectedExample1.html");
                var  actualLines       = File.ReadAllLines(HTML_DIRECTORY + "actualExample1.html");
                bool anyLinesDifferent = false;

                for (var index = 0; index < expectedLines.Length; index++)
                {
                    string expectedLine = expectedLines[index];
                    string actualLine   = "End of file already reached.";
                    if (index >= 0 && actualLines.Length > index)
                    {
                        actualLine = actualLines[index];
                    }

                    if (expectedLine != actualLine)
                    {
                        anyLinesDifferent = true;
                        Console.WriteLine($"Expected Line {index}:{expectedLine}");
                        Console.WriteLine($"  Actual Line {index}:{expectedLine}");
                    }
                }

                if (anyLinesDifferent)
                {
                    Console.WriteLine("Updating source file. Will show up as a difference in source control.");
                    File.WriteAllLines(SOURCE_DIRECTORY + @"\expectedExample1.html", actualLines);
                }
                Assert.IsFalse(anyLinesDifferent, "Didn't expect any lines to be different.");
            }
Exemple #4
0
            public void OHIO_RowsAsWords_CreatesWords()
            {
                LettersAndArrowsPuzzle puzzle     = new LettersAndArrowsPuzzle("ohio", true);
                WordRepository         repository = new WordRepository();
                const int EXPECTED_SIZE           = 4;

                Assert.AreEqual(EXPECTED_SIZE, puzzle.Size);
                StringBuilder builder = new StringBuilder();

                for (int row = 0; row < EXPECTED_SIZE; row++)
                {
                    builder.Clear();
                    for (int column = 0; column < EXPECTED_SIZE; column++)
                    {
                        builder.Append(puzzle.GetCellAtCoordinates(row, column).Letter);
                    }

                    string wordCandidate = builder.ToString().ToLower();
                    Assert.IsTrue(repository.IsAWord(wordCandidate), $"Expected '{wordCandidate}' to be a word");
                }

                Console.WriteLine(puzzle.FormatHtmlForGoogle());
            }