public void TestProcessInputCommandInvalid() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(closedLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "ninja"; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); StringBuilder expectedString = new StringBuilder(); expectedString.Append("Invalid command"); expectedString.Append(Environment.NewLine); expectedString.Append("\nEnter your move (L=left, R=right, U=up, D=down):"); expectedString.Append("Good Bye!"); expectedString.Append(Environment.NewLine); string expected = expectedString.ToString(); string output = sw.ToString(); output = output.Substring(output.Length - 77); Assert.AreEqual<string>(expected, output); } }
public void TestIsPieceOnEdgeAllEdges() { mockBoard = new MockLabyrinthBoard(mockLabyrinthEmpty); // Positioning the piece in the beginning. for (int i = 0; i < LabyrinthBoard.PIECE_INITIAL_POSITION; i++) { mockBoard.MovePieceLeft(); mockBoard.MovePieceUp(); } for (int i = 0; i < LabyrinthBoard.LABYRINTH_SIZE - 1; i++) { Assert.IsTrue(mockBoard.IsPieceOnEdge()); mockBoard.MovePieceRight(); } Assert.IsTrue(mockBoard.IsPieceOnEdge()); for (int i = 0; i < LabyrinthBoard.LABYRINTH_SIZE - 1; i++) { Assert.IsTrue(mockBoard.IsPieceOnEdge()); mockBoard.MovePieceDown(); } Assert.IsTrue(mockBoard.IsPieceOnEdge()); for (int i = 0; i < LabyrinthBoard.LABYRINTH_SIZE - 1; i++) { Assert.IsTrue(mockBoard.IsPieceOnEdge()); mockBoard.MovePieceLeft(); } Assert.IsTrue(mockBoard.IsPieceOnEdge()); for (int i = 0; i < LabyrinthBoard.LABYRINTH_SIZE - 1; i++) { Assert.IsTrue(mockBoard.IsPieceOnEdge()); mockBoard.MovePieceUp(); } Assert.IsTrue(mockBoard.IsPieceOnEdge()); }
public void TestProcessInputCommandExit() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(closedLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "exit"; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); StringBuilder expectedString = new StringBuilder(); expectedString.Append("Good Bye!"); expectedString.Append(Environment.NewLine); string expected = expectedString.ToString(); string output = sw.ToString(); output = output.Substring(output.Length - 11); Assert.AreEqual<string>(expected, output); } }
public void TestProcessInputCommandRestart() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(closedLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "restart"; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); string expected = testBoard.ToString(); string output = testEngine.Labyrinth.ToString(); Assert.AreNotEqual<string>(expected, output); } }
public void TestWalkInLabirinth() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(mockLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "L"; userInterface.SimulateWin = true; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); StringBuilder expectedString = new StringBuilder(); expectedString.Append("Congratulations! You escaped in 3 moves."); expectedString.Append(Environment.NewLine); expectedString.Append("Please, enter your name:"); string expected = expectedString.ToString(); string output = sw.ToString(); output = output.Substring(output.Length - 395,66); Assert.AreEqual<string>(expected, output); } }
public void TestStartMethodForCorrectOutput() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(mockLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "exit"; testEngine = new Engine(testBoard,scores,userInterface); testEngine.Start(); string welcomeString = "Welcome to “Labirinth” game. Your goal is to escape. \nUse 'top' to view the top scoreboard, \n'restart' to start a new game \nand 'exit' to quit the game.\n"; string boardString = testBoard.ToString(); string enterMoveString = "\nEnter your move (L=left, R=right, U=up, D=down):"; StringBuilder startMethodOutput = new StringBuilder(); startMethodOutput.Append(welcomeString); startMethodOutput.Append(Environment.NewLine); startMethodOutput.Append(boardString); startMethodOutput.Append(enterMoveString); startMethodOutput.Append("Good Bye!"); startMethodOutput.Append(Environment.NewLine); string expected = startMethodOutput.ToString(); string output = sw.ToString(); Assert.AreEqual<string>(expected, output); } }
public void TestProcessInputDirectionUp() { TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(mockLabyrinth); int positionY = testBoard.PiecePositionRow; MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "U"; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); Assert.AreEqual<int>(positionY - 1, testEngine.Labyrinth.PiecePositionRow); }
public void TestIsPieceOnEdgeAllInternal() { mockBoard = new MockLabyrinthBoard(mockLabyrinthEmpty); // Positioning the piece in the beginning, one position away from the edge. for (int i = 0; i < LabyrinthBoard.PIECE_INITIAL_POSITION - 1; i++) { mockBoard.MovePieceLeft(); mockBoard.MovePieceUp(); } for (int i = 1; i < LabyrinthBoard.LABYRINTH_SIZE - 2; i++) { Assert.IsFalse(mockBoard.IsPieceOnEdge()); mockBoard.MovePieceRight(); } Assert.IsFalse(mockBoard.IsPieceOnEdge()); for (int i = 1; i < LabyrinthBoard.LABYRINTH_SIZE - 2; i++) { Assert.IsFalse(mockBoard.IsPieceOnEdge()); mockBoard.MovePieceDown(); } Assert.IsFalse(mockBoard.IsPieceOnEdge()); for (int i = 1; i < LabyrinthBoard.LABYRINTH_SIZE - 2; i++) { Assert.IsFalse(mockBoard.IsPieceOnEdge()); mockBoard.MovePieceLeft(); } Assert.IsFalse(mockBoard.IsPieceOnEdge()); for (int i = 1; i < LabyrinthBoard.LABYRINTH_SIZE - 2; i++) { Assert.IsFalse(mockBoard.IsPieceOnEdge()); mockBoard.MovePieceUp(); } Assert.IsFalse(mockBoard.IsPieceOnEdge()); }
public void TestMovePieceUpImpossible() { mockBoard = new MockLabyrinthBoard(mockLabyrinthStuck); mockBoard.MovePieceUp(); char[,] charRepresentation = GetCharArray(mockBoard); Assert.AreEqual('*', charRepresentation[LabyrinthBoard.PIECE_INITIAL_POSITION, LabyrinthBoard.PIECE_INITIAL_POSITION - 1]); }
public void TestMovePieceRight() { mockBoard = new MockLabyrinthBoard(mockLabyrinth); mockBoard.MovePieceRight(); char[,] charRepresentation = GetCharArray(mockBoard); Assert.AreEqual('*', charRepresentation[LabyrinthBoard.PIECE_INITIAL_POSITION, LabyrinthBoard.PIECE_INITIAL_POSITION + 1]); }
public void TestIsPossibleCellOccupied() { int[,] mockLabyrinth = {{1, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}}; mockBoard = new MockLabyrinthBoard(mockLabyrinth); Assert.IsFalse(mockBoard.IsPossibleCell(0, 0)); }
public void TestIsPossibleCellAvailable() { mockBoard = new MockLabyrinthBoard(mockLabyrinth); Assert.IsTrue(mockBoard.IsPossibleCell(LabyrinthBoard.LABYRINTH_SIZE - 1, LabyrinthBoard.LABYRINTH_SIZE - 1)); }