Я пытаюсь проверить, имеет ли строка букву на основе данного теста. Однако буква a имеет исключение, каждая буква a будет считаться как половина значения. Например, буква a стоит 300, но мы хотим разделить на 2, а каждая буква будет стоить 150 баллов.
UnitTest:
[TestCase("software", 'w', 250, 250)]
[TestCase("craftmanship", 'a', 300, 300)]
public void WheelofFortune(string secretWord, char letterGuess, int pointValue, int expected)
{
var actual = warmups.WheelofFortune(secretWord, letterGuess, pointValue);
Assert.AreEqual(expected, actual);
}
Единица измерения:
//Given a target word, a letter guess by a customer, and a point value.
//Return the number of points earned.
public int WheelofFortune(string secretWord, char letterGuess, int pointValue)
{
int sum = 0;
int pointValue2 = (pointValue / 2);
for (int i = 0; i < secretWord.Length; i++)
{
if (secretWord[i] == letterGuess)
sum += pointValue;
if (secretWord[i] == letterGuess && letterGuess == 'a')
sum += pointValue2;
if (secretWord[i] == secretWord.Length - 1)
return sum;
}
return sum;
}
Проблема в мастерстве:
Сообщение: Ожидаемое: 300
Но было: 900
Почему я получаю 900, а не 300?