We have the following method.
public int Factorial(int number)
{
int result = 1;
for (int i = 1; i <= number; i++)
{
result *= i;
}
return result;
}
And we have two tests of this method.
[Fact]
void FactorialTest1()
{
const int number = 4;
int expectedResult = 1;
for (int i = 1; i <= number; i++)
{
expectedResult *= i;
}
var actualResult = Factorial(number);
Assert.Equal(expectedResult, actualResult);
}
[Fact]
void FactorialTest2()
{
const int number = 4;
const int expectedResult = 24;
var actualResult = Factorial(number);
Assert.Equal(expectedResult, actualResult);
}
Which of these tests is more correct?
The first test completely duplicates the code of the Factorial
method. It seems wrong to me
1