Question: The following C function returns the highest value in an array of maximum 5 integers (and minimum 1), -1 if bad input (too large array,

The following C function returns the highest value in an array of maximum 5 integers (and minimum 1), -1 if bad input (too large array, empty array, etc..). The program uses a couple of functions like Math.abs which returns the absolute value of an integer and Math.max which returns the maximum value in the tuple.

Ex. Math.abs(-10) is 10 and Math.max(10,5)=10.

int max_abs_integer(int[] numbers, int n){

n=5;

if((numbers.length > n)||(numbers.length ==0))

return -1;

int max_value = 0;

for(int i = 0; i

if (numbers[i] < 0 )

max_value = Math.max(max_value,Math.abs(numbers[i]));

else max_value = Math.max(max_value, numbers[i]);

}

return max_value;

}

Answer the following questions.

1. Draw the control graph.

2. The function is tested with the following test cases (separately): for each of them, define the output, statement and branch coverage.

int[] all_equals = {0,0,0,0,0};

int[] all_positive = {1,2,3,4,5};

int[] all_negative = {-1,-2,-3,-4,-5};

int[] out_of_size = {1,2,3,4,5,6};

int[] mixed = {-10,10,3,5,-6};

int[] empty = {};

3. Do the test cases achieve 100% statement, branch and loop coverage? If yes, mention the test cases that are enough to achieve a 100% coverage. If no, what other test cases need to be added?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!