????????????TDD(1)
???????????? ???????[ 2014/1/16 10:49:02 ] ???????????????? ???????? TDD
???????????????????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
??????
???·???
??????????????????
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