// ReSharper restore StringLiteralTypo public void PopulatesExpectedLetters(string solution) { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(solution); List <char> expectedLetters = new List <char>(); foreach (char letter in solution.ToUpper()) { expectedLetters.Add(letter); } List <char> actualLetters = new List <char>(); for (int row = 0; row < puzzle.Size; row++) { for (int column = 0; column < puzzle.Size; column++) { char letterToAdd = puzzle.GetCellAtCoordinates(row, column).Letter; if (letterToAdd != ' ') { actualLetters.Add(letterToAdd); } } } CollectionAssert.IsSubsetOf(expectedLetters, actualLetters); }
public void SingleLetter_PlacesExpectedCell() { const int SIZE = 3; LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(SIZE); puzzle.PlaceSolution("a"); var populatedCell = puzzle.GetCellAtCoordinates(0, 0); Assert.AreEqual('A', populatedCell.Letter); Assert.AreEqual(0, populatedCell.Number); Assert.AreEqual(Direction.Undefined, populatedCell.Direction); for (int row = 0; row < SIZE; row++) { for (int column = 0; column < SIZE; column++) { if (row == 0 && column == 0) { continue; //all other cells should be empty. } Assert.AreEqual(LetterAndArrowCell.EmptyCell, puzzle.GetCellAtCoordinates(row, column)); } } }
public void TwoLetters_PlacesExpectedCells() { const int SIZE = 3; LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(SIZE); puzzle.PlaceSolution("ab"); var cellWithA = puzzle.GetCellAtCoordinates(0, 0); Assert.AreEqual('A', cellWithA.Letter); int offset = cellWithA.Number; Assert.AreNotEqual(0, offset); Direction directionForB = cellWithA.Direction; Assert.AreNotEqual(Direction.Undefined, directionForB); int expectedRowForB = 0; int expectedColumnForB = 0; switch (directionForB) { case Direction.Down: expectedRowForB += offset; break; case Direction.Right: //always goes down, so this isn't necessary. expectedColumnForB += offset; break; case Direction.Up: throw new Exception("Starting at 0, 0, the next direction should not be up."); case Direction.Left: throw new Exception("Starting at 0, 0, next direction should not be left."); } for (int row = 0; row < SIZE; row++) { for (int column = 0; column < SIZE; column++) { if (row == 0 && column == 0) { continue; //all other cells should be empty. } if (row == expectedRowForB && column == expectedColumnForB) { LetterAndArrowCell actualCellWhereBShouldBe = puzzle.GetCellAtCoordinates(row, column); Assert.AreEqual('B', actualCellWhereBShouldBe.Letter); Assert.AreEqual(0, actualCellWhereBShouldBe.Number); Assert.AreEqual(Direction.Undefined, actualCellWhereBShouldBe.Direction); } else { Assert.AreEqual(LetterAndArrowCell.EmptyCell, puzzle.GetCellAtCoordinates(row, column)); } } } }
public void RowsMustFormWords_ReturnsCorrectNumbers() { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle("CAMP", true, 0, 42); var words = puzzle.GetWords(); Assert.AreEqual("COLD", words[0], "Unexpected first word"); Assert.AreEqual("APEX", words[1], "Unexpected second word"); Assert.AreEqual("BALE", words[2], "Unexpected third word"); Assert.AreEqual("AMID", words[3], "Unexpected fourth word"); }
public void Empty5x5_FromCenter_ReturnsCorrectNumbers() { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(5); List <int> expectedNumbers = new List <int>() { -2, -1, 1, 2 }; CollectionAssert.AreEquivalent(expectedNumbers, puzzle.GetAvailableHorizontalCells(2, 2)); }
public void Empty4x4_FromOrigin_ReturnsCorrectNumbers() { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(4); List <int> expectedNumbers = new List <int>() { 1, 2, 3 }; CollectionAssert.AreEquivalent(expectedNumbers, puzzle.GetAvailableHorizontalCells(0, 0)); }
public void FourByFour_ReturnsExpectedWords() { LettersAndArrowsPuzzle sizeFourPuzzle = new LettersAndArrowsPuzzle("ohio", true, 0, 42); List <string> words = sizeFourPuzzle.GetWords(); Assert.AreEqual(4, words.Count, "Expected 4 words"); Assert.AreEqual("ONES", words[0], "Unexpected first word"); Assert.AreEqual("IONS", words[1], "Unexpected second word"); Assert.AreEqual("FAWN", words[2], "Unexpected third word"); Assert.AreEqual("HOPE", words[3], "Unexpected fourth word"); }
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); }
public void Empty4x4_CreatesExpectedObject() { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(4); Assert.AreEqual(4, puzzle.Size); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { Assert.AreEqual(LetterAndArrowCell.EmptyCell, puzzle.GetCellAtCoordinates(i, j)); } } }
public void NonEmpty5x5_FromCenter_ReturnsCorrectNumbers() { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(5); puzzle.SetCellAtCoordinates(2, 0, new LetterAndArrowCell() { Letter = 'A' }); List <int> expectedNumbers = new List <int>() { -1, 1, 2 }; CollectionAssert.AreEquivalent(expectedNumbers, puzzle.GetAvailableHorizontalCells(2, 2)); }
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); }
public void LeavesNoEmptyCells() { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(5); puzzle.FillEmptyCells(); for (int row = 0; row < 5; row++) { for (int column = 0; column < 5; column++) { var cell = puzzle.GetCellAtCoordinates(row, column); Assert.AreNotEqual(' ', cell.Letter); Assert.AreNotEqual(0, cell.Number); Assert.AreNotEqual(Direction.Undefined, cell.Direction); } } }
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."); }
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()); }
// ReSharper disable IdentifierTypo public void ABCD_ReturnsExpectedGrid() // ReSharper restore IdentifierTypo { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(2); // ReSharper disable StringLiteralTypo puzzle.PlaceSolution("abcd"); // ReSharper restore StringLiteralTypo /* * A D * B C */ LetterAndArrowCell actualA = puzzle.GetCellAtCoordinates(0, 0); Assert.AreEqual('A', actualA.Letter); Assert.AreEqual(1, actualA.Number); Assert.AreEqual(Direction.Down, actualA.Direction); LetterAndArrowCell actualB = puzzle.GetCellAtCoordinates(1, 0); Assert.AreEqual('B', actualB.Letter); Assert.AreEqual(1, actualB.Number); Assert.AreEqual(Direction.Right, actualB.Direction); LetterAndArrowCell actualC = puzzle.GetCellAtCoordinates(1, 1); Assert.AreEqual('C', actualC.Letter); Assert.AreEqual(-1, actualC.Number); Assert.AreEqual(Direction.Up, actualC.Direction); LetterAndArrowCell actualD = puzzle.GetCellAtCoordinates(0, 1); Assert.AreEqual('D', actualD.Letter); Assert.AreEqual(0, actualD.Number); Assert.AreEqual(Direction.Undefined, actualD.Direction); }
public void OverwriteSize_HasThatSize() { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle("ohio", false, 8); Assert.AreEqual(8, puzzle.Size); }
public void SetsAppropriateSize(int expectedSize, string solution) { LettersAndArrowsPuzzle puzzle = new LettersAndArrowsPuzzle(solution); Assert.AreEqual(expectedSize, puzzle.Size); }