???????????????????Guesser?????Guess??????
?????????CASE?????????????Guesser?????Guess??????
public class Guesser
{
public string Guess(string inputNumber)
{
throw new System.NotImplementedException();
}
}
?????????????????????Run??
??????????System.NotImplementedException: The method or operation is not implemented.
??????????????????Guess???????????????????????"4a0b"??????????????????
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++;
}
}
return string.Format("{0}a{1}b"?? ACount?? BCount);
}
}

????OK??????????????????????????????????????CASE???
??????????CASE??????????
????To-Do-List:
????????“2975” ???4a0b??
????????“2957” ???2a2b??
????????“9257” ???0a4b??
????????“1348” ???0a0b??
???????Guesser??.
???????????CASE??????9257?????????????????????????????0a4b ??
????????????CASE????飬?????????????????????
[TestMethod]
public void should_return_2a2b_when_input_numbers_all_figures_right_and_2_positions_right()
{
var inputNumber = "2957";
var actual = new Guesser().Guess(inputNumber);
Assert.AreEqual("2a2b"?? actual);
}
Run.....
???????PASS??Assert.AreEqual failed. Expected:<2a2b>. Actual:<2a0b>.
??????????????guess??????????????CASE PASS??
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);
}
}
????????????CASE...pass.?????????To-Do-List