public void TestExecuteCommandRestartCorrect() { BullsAndCowsGame_Accessor game = SetSecretNumberDigits(1, 2, 3, 4); game.FindBullsAndCowsCount("0000"); game.ExecuteCommand(null, "0000"); game.ExecuteCommand(null, "restart"); int expected = 0; int actual = game.GuessesCount; Assert.AreEqual <int>(expected, actual, EXECUTING_COMMAND_ERROR_MSG); }
public void TestExecuteCommandGuessedMessageWithoutCheats() { BullsAndCowsGame_Accessor game = SetSecretNumberDigits(1, 2, 3, 4); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Console.SetOut(writer); StringReader reader = new StringReader("Anton"); Console.SetIn(reader); Scoreboard scoreboard = new Scoreboard(); game.ExecuteCommand(scoreboard, "1234"); writer.Close(); reader.Close(); string expected = "Congratulations! You guessed the secret number in 1 attempt." + Environment.NewLine + "Please enter your name for the top scoreboard: " + "Scoreboard:" + Environment.NewLine + "1. Anton --> 1 guess" + Environment.NewLine; string actual = sb.ToString(); Assert.AreEqual <string>(expected, actual, EXECUTING_COMMAND_ERROR_MSG); }
public void TestExecuteCommandWrongNumber() { BullsAndCowsGame_Accessor game = SetSecretNumberDigits(1, 2, 3, 4); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Console.SetOut(writer); game.ExecuteCommand(null, "4321"); writer.Close(); string expected = "Wrong number! Bulls: 0, Cows: 4" + Environment.NewLine; string actual = sb.ToString(); Assert.AreEqual <string>(expected, actual, EXECUTING_COMMAND_ERROR_MSG); }
public void TestExecuteCommandHelp() { BullsAndCowsGame_Accessor game = SetSecretNumberDigits(1, 2, 3, 4); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Console.SetOut(writer); game.CheatNumber = new char[4] { 'X', '2', '3', '4' }; game.ExecuteCommand(null, "help"); writer.Close(); string expected = "The number looks like 1234." + Environment.NewLine; string actual = sb.ToString(); Assert.AreEqual <string>(expected, actual, EXECUTING_COMMAND_ERROR_MSG); }
public void TestExecuteCommandTop() { BullsAndCowsGame_Accessor game = SetSecretNumberDigits(1, 2, 3, 4); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Console.SetOut(writer); Scoreboard scoreboard = new Scoreboard(); scoreboard.AddNewResult(new PlayerInfo("Tisho", 1)); game.ExecuteCommand(scoreboard, "top"); writer.Close(); string expected = "Scoreboard:" + Environment.NewLine + "1. Tisho --> 1 guess" + Environment.NewLine; string actual = sb.ToString(); Assert.AreEqual <string>(expected, actual, EXECUTING_COMMAND_ERROR_MSG); }
public void TestExecuteCommandGuessedMessageWithCheats() { BullsAndCowsGame_Accessor game = SetSecretNumberDigits(1, 2, 3, 4); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); Console.SetOut(writer); Scoreboard scoreboard = new Scoreboard(); game.GetCheat(); game.ExecuteCommand(scoreboard, "1234"); writer.Close(); string expected = "Congratulations! You guessed the secret number in 1 attempt and 1 cheat." + Environment.NewLine + "You are not allowed to enter the top scoreboard." + Environment.NewLine + "Top scoreboard is empty." + Environment.NewLine; string actual = sb.ToString(); Assert.AreEqual <string>(expected, actual, EXECUTING_COMMAND_ERROR_MSG); }