测试驱动开发TDD(3)
作者:网络转载 发布时间:[ 2014/1/20 15:46:21 ] 推荐标签:测试技术
修改GameManager类,让所有CASE PASS.
public string Guess(string input)
{
times++;
IsGameOver = times == MAX_TIMES;
var validator = new Validator();
if (!validator.Validate(input))
{
return "try again " + validator.ErrorMsg;
}
var result = guesser.Guess(input);
if (result == "4a0b")
{
IsGameOver = true;
return "You win!";
}
return "try again result is " + result + ".";
}
猜测数字
输入验证
生成答案
输入次数
输出猜测结果
后:完善GameManager类的work flow。
public class GameManager
{
private const int MAX_TIMES = 6;
private int times;
private readonly IGuesser guesser;
public bool IsGameOver { get; private set; }
public GameManager(IGuesser guesser)
{
this.guesser = guesser;
}
private void Start()
{
times = 0;
IsGameOver = false;
OutputGameHeader();
}
public void Run()
{
Start();
while (!IsGameOver)
{
Console.WriteLine();
Console.WriteLine(string.Format("[The {0}st time ] : please input number!", times + 1));
var input = Console.ReadLine();
if (IsExit(input)) continue;
var result = Guess(input);
Console.WriteLine(result);
}
OutputGamefooter();
}
private bool IsExit(string input)
{
if (input.ToLower().Trim() == "exit")
{
Console.WriteLine("Make sure to exit game?(Y/N)");
var readLine = Console.ReadLine();
if (readLine != null)
{
var isexit = readLine.ToLower().Trim();
if (isexit == "y")
{
IsGameOver = true;
}
}
return true;
}
return false;
}
public string Guess(string input)
{
times++;
IsGameOver = times == MAX_TIMES;
var validator = new Validator();
if (!validator.Validate(input))
{
return "try again " + validator.ErrorMsg;
}
var result = guesser.Guess(input);
if (result == "4a0b")
{
IsGameOver = true;
return "You win!";
}
return "try again result is " + result + ".";
}
private void OutputGameHeader()
{
Console.Clear();
Console.WriteLine(" --- Game Start! ---");
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine("| You can input a number or input exit for exiting this game! |");
Console.WriteLine("---------------------------------------------------------------");
}
private void OutputGamefooter()
{
Console.WriteLine("--------------------------------");
Console.WriteLine("| Game Over! [Answer] is " + guesser.AnswerNumber + " |");
Console.WriteLine("--------------------------------");
}
}
Program.cs
class Program
{
static void Main(string[] args)
{
var isRepeatGame = false;
do
{
IGuesser guesser = new Guesser(new AnswerGenerator());
var game = new GameManager(guesser);
game.Run();
Console.WriteLine("Try again?(Y/N)");
var line = Console.ReadLine();
if (line == null) continue;
var readLine = line.ToLower().Trim();
isRepeatGame = readLine == "y";
} while (isRepeatGame);
}
}
跑下所有的测试。
相关推荐
更新发布
功能测试和接口测试的区别
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