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)); } } } }
// 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 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)); } } }
// 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 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_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()); }