This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Two possible metrics are state coverage and path coverage. It is possible to get 100% coverage both the metrics for this example. Problem 3.3. (5 points) Here is the binary search code that was implemented in Java's JDK and used widely for many years: 1: public static int binarySearch(int a, int key) { 2: int low = 0; 3: int high = a.length  1; 4: 5: while (low <= high) { 6: int mid = (low + high) / 2; 7: int midVal = a[mid]; 8: 9: if (midVal < key) 10: low = mid + 1 11: else if (midVal > key) 12: high = mid  1; 13: else 14: return mid; // key found 15: } 16: return (low + 1); // key not found. 17: } (a) Find tests to achieve 100% branch coverage. a = {0, 1, 2, 3, 4}… key = 1 a = {0, 1, 2, 3, 4}… key = 5 (b) This code has a bug. Can you find a test that demonstrates the bug? Case where array length is greater than integer bounds....
View
Full Document
 Spring '08
 staff
 Software engineering, Code coverage, branch coverage, Finite State Machine

Click to edit the document details