Software Quality Assignment #1
public class BinarySearch {
public static int binarySearch(Object [] data, Object key) {
int lower = 0;
int upper = data.length - 1;
int location;
while (true) {
location = midpoint(lower, upper);
if (data[location] == key) { return (location); }
else if (data[location] < key) { lower = location + 1; } else { upper = location - 1; }
} }
public static int midpoint(int lower, int upper) { return ((lower + upper) / 2); }
}
For the program given above, provide:
1: (5 points) A computation tree representation for a data object that has a length of no more than 4.
2: (5 points) A control flow graph representation.
3: (5 points) The code shown above is not robust. Show the changes that you would need to make to this code in order to make it robust.
4: (20 points) In Rosenblum, the author describes four assertion constructs: assume, promise, return, and assert. Use these constructs to place assertions where appropriate in the code shown below.
int gcd(int a, int b) {
int p = a;
int q = b;
while(p != q) {
if(p > q) p = p - q;
else q = q - p; }
return p;
}
5: (10 points) Assume that in each of the statements shown below, that the first arithmetic operator is wrong and should be the operator shown in parentheses. Assuming that x, y, and z are input values, describe and provide test data that would NOT reveal the fault.
a) x = x + 4; (*)
b) y = (x * y/3) * z; (-)
7: (10 points) Boundary interior exercises each loop twice, if possible. Describe a control flow graph annotated with def and use information where N iterations are needed to satisfy ordered context coverage and explain.
8: (10 points) Assume test sets T1 and T2 satisfy testing criteria C1 and C2, respectively, and that criterion C1 subsumes criterion C2. Which test set will detect more faults? Justify your answer.