This assignment has two parts:
- Using a white-box coverage measurement tool for Java programs.
- Drawing control flow graphs for a program.
Part a. Coverage Tool for Java (20 points)
Use the code from your previous JUnit assignment (A2).
Recall that there were five classes, World,
Coordinate, WorldTest, CoordinateTest,
and TestAll. Measure code coverage of your own test
cases using the EclEmma Eclipse plugin.
How to install
- Go to Help -> Install New Software...
- Click on Add...
- Enter location: http://update.eclemma.org/ name : EclEmma Update Site and click ok.
- After clicking it will take some time to EclEmma plugin appear in the text box.
- Click Select All and then Next.
- Click next, accept license agreement and client Finish. Ignore the security warning and restart eclipse.
How to use
- Select the project for A2.
- At the top where you have the Play buttons for running programs, click on the down-arrow next to the play button that has a red and green rectangle on the bottom-left of the play button.
- You can run the project as JUnit or as Java Application.
- You should be able to view Coverage in the view Console. You can expand the package in the console and view coverage for individual files. If you run multiple times as you add test cases, you can view new coverage by selecting the sessions from a dropdown menu (the one with gears).
- You can also right click on the project for A2, and select Properties. Click on Coverage to see a summary of various types of coverage.
- The code view will show colors indicating which parts of the code are covered (or not).
- green for fully covered lines
- yellow for partly covered lines
- red for lines that have not been executed at all
(10 points) Copy the coverage numbers as part of the report.
(10 points) If any of your coverage numbers is less than 100%, write new
test cases and increase the coverage to 100%. All the numbers must be 100%
after you have added your test cases. Add the test cases to your report.
If your coverage is already 100%, you automatically get the 10 points. If you
feel that a certain part of the code is unreachable, provide an explanation
in your report. Points will be deducted if the explanation is incorrect.
Part b. Control flow graph. (30 points)
We have provided code for performing binary search.
The problem specification is as follows:
- Input: Array A[0..N-1] and number to be searched target.
- Output: The index of the number if found, or -1 if not found.
The following (possibly buggy) code implements the above problem.
/* Code for binary search program */
int binSearch(int[] A, int target) {
int low = 0;
int high = A.length-1;
while (low <= high) {
int middle = low + (high - low)/2;
if (target < A[middle])
high = middle - 1;
else if (target > A[middle])
low = middle + 1;
else
return middle;
}
return -1;
}
Tasks for part b:
- Draw the control-flow graph of this code inside the
binSearch method. Label each node with statement numbers and
clearly indicate the statements corresponding to each node. (10 points)
- Write test inputs that give 100% node coverage. For each test input,
show which nodes are being covered.
(10 points)
- Write test inputs that give 100% edge coverage. For each test input,
show which edges are being covered.
(10 points)
Turnin instructions
Print your answers and hand them as a single stapled report at the beginning
of class. DO NOT turn in handwritten assignments; type your answers.
Do not submit the assignment using Canvas.