I have the following two methods:
public int Average (params int[] array)
{
if (array.Length > 0)
{
double avg = Sum(ints) / arr.Length;
return (int)avg;
}
return 0;
}
public int Sum(params int[] array2)
{
int total = 0;
for (int n = 0; n < array2.Length; n++)
{
total += arr[n];
}
return total;
}
But for testing purposes I tried adding the int.MaxValue / 2 and int.MaxValue / 2 + 4. in the array. But why does the unit test fail, although the sum of the two values will be less than int.MaxValue?
No sir, the sum will be more than
int.MaxValue:You overflew the int max value.
Simple math: (x/2)+ (x/2 +4) == x+4