Ok so I have two arrays of integers, and I have to return the average rating of the two days. This is the code that I have come up with thus far, but apparently it does not meet the expectations. Result:
Message: Expected: 5.0d But was: 3.0d
Unit:
public double WeekendAverage(int[] saturday, int[] sunday)
{
int[] n = { saturday.Length, sunday.Length };
int sum = 0;
for (int i = 0; i < n.Length; i++)
{
sum = saturday[i] + sunday[i];
return sum / n.Length;
}
return sum;
}
UnitTest:
[TestCase(new[] { 1, 2, 3, 4, 5, 7, 8, 5, 10 }, new[] { 9, 9, 9, 8, 9, 8, 9, 9, 9, 10, 10 }, 7)]
public void WeekendAverage(int[] saturday, int[] sunday, double expected)
{
var actual = warmups.WeekendAverage(saturday, sunday);
Assert.AreEqual(expected, actual);
}
nin your code will have only two values, length of Saturday array and length of Sunday array. It will not have the actual values from Saturday and Sunday. Also you are returning from for loop so the loop will be executed only once. You need make the logic clear and debug the code and see if it runs as per the logic. And correct it accordingly