????????????TDD(3)
???????????? ???????[ 2014/1/20 15:46:21 ] ???????????????
???????GameManager?ò????????
public class GameManager
{
private readonly IGuesser guesser;
public bool IsGameOver { get; private set; }
private const int MAX_TIMES = 6;
private int times;
public GameManager(IGuesser guesser)
{
this.guesser = guesser;
}
public void Guess(string input)
{
times++;
IsGameOver = times == MAX_TIMES;
guesser.Guess(input);
}
}
ok
?????2?????
???????????
?????????
???????????
????????2???
????????2??????????????????????????÷???"you win"????Gameover???????????????????Guesser??validator?????Cover??????????????????????????
[TestClass]
public class GameManagerTest
{
private _gameManager _game;
[TestInitialize]
public void Init()
{
IGuesser guesser = new Guesser(new AnswerGeneratorForTest());
_game = new _gameManager(guesser);
}
[TestMethod]
public void should_return__game_over_when_input_times_is_six_and_result_is_wrong()
{
const string input = "1368";
const int maxtimes = 6;
var actual = false;
for (var time = 0; time < maxtimes; time++)
{
_game.Guess(input);
}
actual = _game.Is_gameOver;
Assert.AreEqual(true?? actual);
}
[TestMethod]
public void should_return_you_win_and__game_is_over_when_input_is_equal_answer_number()
{
const string input = "2975";
var actual = _game.Guess(input);
Assert.AreEqual("You win!"?? actual);
Assert.AreEqual(true?? _game.Is_gameOver);
}
[TestMethod]
public void should_return_try_again_input_must_be_four_digits_when_input_is_not_equal_four_digits()
{
const string input = "15243";
var actual = _game.Guess(input);
Assert.AreEqual("try again the input must be four digits."?? actual);
}
[TestMethod]
public void should_return_try_again_input_can_not_be_empty_when_input_is_empty()
{
const string input = "";
var actual = _game.Guess(input);
Assert.AreEqual("try again the input can't be empty."?? actual);
}
[TestMethod]
public void should_return_try_again_input_must_be_fully_digital_when_input_is_not_all_digital()
{
const string input = "a4sw";
var actual = _game.Guess(input);
Assert.AreEqual("try again the input must be fully digital."?? actual);
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11