?????????????????????????????????е?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";
}
}