hw3_sol

hw3_sol - Two possible metrics are state coverage and path...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Problem 3.1. (5 points) Which of the following statements are true? 1. 100% path coverage implies 100% branch coverage True. 2. 100% statement coverage implies 100% branch coverage False . Example in lecture slides : if (x != 0) x = x+ 10; y = y/x; 3. Suppose test suite T 1 gets 100% branch coverage and test suite T 2 gets 100% statement coverage. There can be an execution path explored in T 2 but not by T 1 . True. 4. There is a program such that no test suite can get 100% branch coverage. True. Any example with deadcode. x = 10; if (x != 10) y = x; 5. There are incomparable coverage metrics; i.e., there are two coverage metrics such that 100% coverage for metric 1 does not imply 100% coverage for metric 2 and vice versa. True. Dataflow coverage and branch coverage.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Problem 3.2. 1. Finite state machine ? 2. Suggest some test coverage metrics for the finite state machine programming model. Can you get 100% coverage on these metrics for your elevator controller?
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the 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

Page1 / 3

hw3_sol - Two possible metrics are state coverage and path...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online