For the "average" function do the following:
------------------------------------------------------------------------------------------------------------------
public class Average {
public int average(int k, int[] list){
int average = 0;
int n = Math.min(k, list.length);
if( n > 0) {
for(int i = 0 ; i < n; i++){
average += list[i];
}
average = average/n;
}
return average;
}}
-------------------------------------------------------------------------------------------------------------------
1. Write a brief functional description for the function.
2. Generate functional test case based on functional description.
3. Identify and specify the partitions and generate partition test cases.
4. Generate boundary value test cases.
5. Implement the average function in a class Averagge and generate test cases using Junit.
6. Compile and run the test cases. Record any failures and errors that are reported. Analyze and briefly explain why each of the failures and errors occurs and how you fix them. Correct all the failures and errors until the CUT (Component Under Test) passes all the test cases.
a) In case there is no failure, please inject a fault yourself and complete the section f. (That means you need to inject a fault in this average method, and see if your tests can find the fault. For example, instead of i=0, change the code to i=1, or instead of min , use max .. these faults cause the function to not behave as you describe in the section a, and since you design your tests according to this description , your test should be able to reveal the fault and fail. but if your test did not fail after you inject the fault, then you need to redesign and add a new test to reveal your injected fault.)
7. Measure the code coverage using a code coverage tools such as EclEmma. Your test case must achieve 100% branch coverage.
a) Cobertura is described in Appendix C
b) EclEmma is a Java code coverage analysis for the Eclipse IDE.