????????????TDD(2)
???????????? ???????[ 2014/1/17 11:30:54 ] ????????TDD ????????
?????????????????????????????????е?CASE??????飬??????е??PASS??
????To-Do-List:
?????2?????
???????????
?????????
???????????
????????2???
?????????????????????????????
??????????????????????????????????????1???????????2??4λ??3???????
?????????и??????????????????????????????????????????????????????????Guesser??????
public class Guesser
{
private const string AnswerNumber = "2975";
public string Guess(string inputNumber)
{
var aCount = 0;
var bCount = 0;
for (var index = 0; index < AnswerNumber.Length; index++)
{
if (AnswerNumber[index]==inputNumber[index])
{
aCount++;
continue;
}
if (AnswerNumber.Contains(inputNumber[index].ToString()))
{
bCount++;
}
}
return string.Format("{0}a{1}b"?? aCount?? bCount);
}
}
?????????????????private const string AnswerNumber = "2975";?????????????Guesser??????????????????????????????????Щ????????????磺?????????????
??????????????????????????????????????????????????????MOCK???????"????????"?????????????????????????????????????á?
?????????????д?????
[TestClass]
public class AnswerGeneratorTest
{
[TestMethod]
public void should_pass_when_answer_generator_number_is_four_digits_and_fully_digital()
{
Regex regex = new Regex(@"^d{4}$");
var answerGenerator = new AnswerGenerator();
var actual = regex.IsMatch(answerGenerator.Generate());
Assert.AreEqual(true?? actual);
}
[TestMethod]
public void should_pass_when_answer_generator_number_do_not_repeat()
{
var answerGenerator = new AnswerGenerator();
var actual = answerGenerator.Generate().Distinct().Count() == 4;
Assert.AreEqual(true?? actual);
}
}
???AnswerGenerator???ò????????
????cao????δ?????????
public class AnswerGenerator
{
public string Generate()
{
var answerNumber = new StringBuilder();
Enumerable.Range(0?? 9)
.Select(x => new { v = x?? k = Guid.NewGuid().ToString() })
.OrderBy(x => x.k)
.Select(x => x.v)
.Take(4).ToList()
.ForEach(num => answerNumber.Append(num.ToString()));
return answerNumber.ToString();
}
}
???????в????
?????????????????????????????IAnswerGenerator????????????????С?
public interface IAnswerGenerator
{
string Generate();
}
[csharp] view plaincopy
public class AnswerGenerator : IAnswerGenerator
{
public string Generate()
{
var answerNumber = new StringBuilder();
Enumerable.Range(0?? 9)
.Select(x => new { v = x?? k = Guid.NewGuid().ToString() })
.OrderBy(x => x.k)
.Select(x => x.v)
.Take(4).ToList()
.ForEach(num => answerNumber.Append(num.ToString()));
return answerNumber.ToString();
}
}
public class AnswerGeneratorForTest : IAnswerGenerator
{
public string Generate()
{
return "2975";
}
}
??????
???·???
??????????????????
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