Exemplo n.º 1
0
            public void NoClues_ReturnsEmptyList()
            {
                ClueRepository repository = new ClueRepository();
                List <Clue>    clues      = repository.GetCluesForWord("Clueless");

                Assert.AreEqual(0, clues.Count);
            }
Exemplo n.º 2
0
            public void IncrementsClueCount()
            {
                ClueRepository repository = new ClueRepository();

                Assert.AreEqual(0, repository.CountOfWordWithClues, "Repository should start out empty");
                repository.AddClue("ONES", "Singletons");

                Assert.AreEqual(1, repository.CountOfWordWithClues, "Repository should have one clue now.");
            }
Exemplo n.º 3
0
            public void ExampleFile_ReturnsExpectedCollection()
            {
                PuzParser parser = new PuzParser();

                ClueRepository results = parser.ParseFile(@"data\uc200525.puz");

                Assert.IsNotNull(results);
                Assert.AreEqual(75, results.CountOfWordWithClues);
            }
Exemplo n.º 4
0
            public void SupportsMultipleClues()
            {
                ClueRepository repository = new ClueRepository();

                Assert.AreEqual(0, repository.CountOfWordWithClues, "Repository should start out empty");
                repository.AddClue("ONES", "Singletons");
                repository.AddClue("ONES", "Smallest denomination of folding money.");

                Assert.AreEqual(1, repository.CountOfWordWithClues, "Repository should have one clue now.");
            }
Exemplo n.º 5
0
            public void IsCaseInsensitive()
            {
                ClueRepository repository = new ClueRepository();

                Assert.AreEqual(0, repository.CountOfWordWithClues, "Repository should start out empty");
                repository.AddClue("ones", "Singletons");
                repository.AddClue("OnEs", "Smallest denomination of folding money.");
                List <Clue> clues = repository.GetCluesForWord("Ones");

                Assert.AreEqual(2, clues.Count);
            }
Exemplo n.º 6
0
            public void SupportsMultipleClues()
            {
                ClueRepository repository = new ClueRepository();

                Assert.AreEqual(0, repository.CountOfWordWithClues, "Repository should start out empty");
                repository.AddClue("ONES", "Singletons");
                repository.AddClue("ONES", "Smallest denomination of folding money.");
                List <Clue> clues = repository.GetCluesForWord("ONES");

                Assert.AreEqual(2, clues.Count);
            }
Exemplo n.º 7
0
            public void WordWithTwoClues_LeavesOne()
            {
                ClueRepository repository = new ClueRepository();

                repository.AddClue("word", "A string of letters", ClueSource.ClueSourceChip);
                repository.AddClue("word", "unit of meaning", ClueSource.ClueSourceIdiom);

                Assert.AreEqual(2, repository.GetCluesForWord("word").Count, "Expected 2 clues before delete");
                repository.RemoveClue("word", "unit of meaning");
                Assert.AreEqual(1, repository.GetCluesForWord("word").Count, "Expected 1 clue after delete");
            }
Exemplo n.º 8
0
            public void OtherExampleFile_ReturnsExpectedCollection(int fileNumber, string expectedWord,
                                                                   string expectedClue)
            {
                PuzParser parser = new PuzParser();

                ClueRepository results = parser.ParseFile($@"data\example{fileNumber}.puz");

                Assert.IsNotNull(results);
                Assert.LessOrEqual(74, results.CountOfWordWithClues);
                Assert.AreEqual(expectedClue, results.GetCluesForWord(expectedWord)[0].ClueText,
                                $"Expected clue for {expectedWord}");
            }
Exemplo n.º 9
0
            public void AllWords_ContainsSpecificWords(string word)
            {
                ClueRepository clues = new ClueRepository();

                clues.ReadFromDisk();
                var cluesForWord = clues.GetCluesForWord(word);

                foreach (var clueForWord in cluesForWord)
                {
                    Console.WriteLine($"{word.ToUpperInvariant()}: {clueForWord.ClueText}");
                }

                Assert.Less(0, clues.GetCluesForWord(word).Count,
                            $"Expected at least one clue for {word.ToUpperInvariant()}");
            }
Exemplo n.º 10
0
            public void MultipleClues_PopulatesClueDictionary()
            {
                ClueRepository repository = new ClueRepository();

                repository.ReadFromDisk(@"data\expected_nonempty_clue_repository.json");

                Assert.AreEqual(2, repository.CountOfWordWithClues);
                List <Clue> clues = repository.GetCluesForWord("ONES");

                Assert.AreEqual(2, clues.Count);
                List <Clue> cluesForLego = repository.GetCluesForWord("Lego");

                Assert.AreEqual(1, cluesForLego.Count);
                Assert.AreEqual("A small colorful brick.", cluesForLego[0].ClueText);
                Assert.AreEqual(ClueSource.ClueSourceChip, cluesForLego[0].ClueSource);
            }
Exemplo n.º 11
0
        public void CollectAllTheClues_NoAssertions()
        {
            const string DIRECTORY_WITH_PUZ_FILES =
                @"C:\Users\Chip\Source\Repos\WordPuzzle3\WordPuzzlesTest\data\PUZ";

            ClueRepository clues = new ClueRepository();

            clues.ReadFromDisk();
            foreach (string file in Directory.EnumerateFiles(DIRECTORY_WITH_PUZ_FILES, "*.json"))
            {
                Console.WriteLine($"Adding {file}, words so far {clues.CountOfWordWithClues}.");
                clues.ReadFromDisk(file);
            }
            // ReSharper disable StringLiteralTypo
            clues.WriteToDisk(DIRECTORY_WITH_PUZ_FILES + @"\allclues.json");
            // ReSharper restore StringLiteralTypo
        }
Exemplo n.º 12
0
            public void EmptyRepository_CreatesExpectedFile()
            {
                ClueRepository repository = new ClueRepository();

                // ReSharper disable StringLiteralTypo
                repository.WriteToDisk(@"data\actual_empty_clue_repository.json");
                // ReSharper restore StringLiteralTypo

                var expectedLines = File.ReadAllLines(@"data\expected_empty_clue_repository.json");
                var actualLines   = File.ReadAllLines(@"data\actual_empty_clue_repository.json");

                for (var index = 0; index < expectedLines.Length; index++)
                {
                    string expectedLine = expectedLines[index];
                    string actualLine   = actualLines[index];
                    Assert.AreEqual(expectedLine, actualLine, $"Unexpected line at index {index}");
                }
            }
Exemplo n.º 13
0
            public void MultipleClues_CreatesExpectedFile()
            {
                ClueRepository repository = new ClueRepository();

                repository.AddClue("ONES", "Singletons");
                repository.AddClue("ONES", "Smallest denomination of folding money.");

                repository.AddClue("Lego", "A small colorful brick.", ClueSource.ClueSourceChip);

                // ReSharper disable StringLiteralTypo
                repository.WriteToDisk(@"data\actual_nonempty_clue_repository.json");
                // ReSharper restore StringLiteralTypo

                var expectedLines = File.ReadAllLines(@"data\expected_nonempty_clue_repository.json");
                var actualLines   = File.ReadAllLines(@"data\actual_nonempty_clue_repository.json");

                for (var index = 0; index < expectedLines.Length; index++)
                {
                    string expectedLine = expectedLines[index];
                    string actualLine   = actualLines[index];
                    Assert.AreEqual(expectedLine, actualLine, $"Unexpected line at index {index}");
                }
            }
            public void LongerPhrase_ReturnsExpectedResult(bool includeSolution)
            {
                const string   HTML_DIRECTORY   = @"html\ReadDownColumn\";
                string         SOURCE_DIRECTORY = ConfigurationManager.AppSettings["SourceDirectory"] + "ReadDownColumn";
                ClueRepository clueRepository   = new ClueRepository();

                clueRepository.ReadFromDisk();

                var puzzle = new ReadDownColumnPuzzle
                {
                    Solution = "XRAY",
                    Words    = { "boxing", "parent", "brazen", "joyful" },
                    Clues    = new List <string>
                    {
                        clueRepository.GetCluesForWord("boxing")[0].ClueText,
                        clueRepository.GetCluesForWord("parent")[0].ClueText,
                        clueRepository.GetCluesForWord("brazen")[0].ClueText,
                        clueRepository.GetCluesForWord("joyful")[0].ClueText,
                    }
                };


                string generatedHtml = puzzle.FormatHtmlForGoogle(includeSolution);

                var actualFileName = "actualExample1.html";

                if (includeSolution)
                {
                    actualFileName = "actualExampleWithSolution1.html";
                }
                File.WriteAllText(HTML_DIRECTORY + actualFileName, generatedHtml);
                var expectedFileName = "expectedExample1.html";

                if (includeSolution)
                {
                    expectedFileName = "expectedExampleWithSolution1.html";
                }

                string[] expectedLines = new[] { " " };// need to have something to be different from generated file.
                if (File.Exists(HTML_DIRECTORY + expectedFileName))
                {
                    expectedLines = File.ReadAllLines(HTML_DIRECTORY + expectedFileName);
                }
                var  actualLines       = File.ReadAllLines(HTML_DIRECTORY + actualFileName);
                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 + $@"\{expectedFileName}", actualLines);
                }
                Assert.IsFalse(anyLinesDifferent, "Didn't expect any lines to be different.");
            }