Problem: Draw A Control Flow Diagram For This Function. Label Each Edge With An Uppercase Letter
Problem: Draw A Control Flow Diagram For This Function. Label Each Edge With An Uppercase Letter
Problem: Draw A Control Flow Diagram For This Function. Label Each Edge With An Uppercase Letter
Input
Covers
x y
Solution:
Problem: Draw a control flow diagram for this function. Label each node in the graph with a capital let-
ter, and label each edge with a lowercase letter.
1. Fill in the table below with a test suite that provides statement coverage of the “blammo” code. In the
covers column, list the relevant labeled items in your CFG that each test case covers. Some cells in
the table may be left blank.
Input
Covers
u v
2. Fill in the table below with a test suite that provides path coverage of the “blammo” code. Cover no
more than 1 iteration of the loop. In the covers column, list the relevant labeled items in your CFG
that each test case covers. Some cells in the table may be left blank.
Input
Covers
u v
Solutions:
1.
2.
Problem: Draw a control-flow graph for the following function. Label each edge in the graph with an
uppercase letter.
Solution:
Problem: Fill in the table below with a test suite that provides path coverage of the min_of_three
function from the previous question. In the covers column, list the relevant labeled edges in your CFG
that each test case covers. Some cells in the table may be left blank.
Input Expected
Covers
x y z Output
Solution:
Consider the following control-flow graph for a gcd function in answering the questions below.
H
Problem: Fill in the table below with a test suite that provides condition coverage of the gcd function
(see control-flow graph above). In the Covers column, list the relevant labeled edges in the CFG that each
test case covers. Some cells in the table may be left blank.
Input Expected
Covers
x y Output
Problem: Fill in the table below with a test suite that provides path coverage of the gcd function (see
control-flow graph above). In the Covers column, list the relevant labeled edges in the CFG that each test
case covers. Some cells in the table may be left blank. You need only cover executions that involve 1 iter-
ation of the loop.
Input Expected
Covers
x y Output
Solution: Condition Coverage
False True
False True
False True
Problems:
1. Select tests from the above to create a test suite that provides statement coverage of the bina-
ry_search function. Your suite should contain the minimum number of tests to provide the cover-
age.
2. Select tests from the above to create a test suite that provides condition coverage of the bina-
ry_search function. Your suite should contain the minimum number of tests to provide the cover-
age.
3. Select tests from the above to create a test suite that provides path coverage of the binary_search
function. Cover only paths that contain one loop iteration or fewer (i.e., no path should enter the loop
more than once). Your suite should contain the minimum number of tests to provide the coverage.
Solutions:
1.
2.
3.
Problems:
1. Select tests from the above to create a test suite that provides statement coverage of the bina-
ry_search function. Your suite should contain the minimum number of tests to provide the cover-
age.
2. Select tests from the above to create a test suite that provides condition coverage of the bina-
ry_search function. Your suite should contain the minimum number of tests to provide the cover-
age.
3. Select tests from the above to create a test suite that provides path coverage of the binary_search
function. Cover only paths that contain one loop iteration or fewer (i.e., no path should enter the loop
more than once). Your suite should contain the minimum number of tests to provide the coverage.
Solutions:
1. a, b, d
2. a, b, d
3. a, b, c, d
Consider this figure in answer the following questions.
def find_smallest(array)
smallest = array[0]
i = 1
while i < array.length
if array[i] < smallest
smallest = array[i]
end
i = i + 1
end
return smallest
end
Figure 1. Function that finds the smallest value in an array.
Problem:
Draw a control-flow graph (CFG) for the function in Figure 1. In addition to the usual CFG features, label
the nodes with capital letters (A, B, C, etc.), and label the edges with numbers (1, 2, 3, etc.). Don’t forget
to include entry and exit points.
Solution:
Problems:
Use the CFG you created for the function in Figure 1 to answer the following questions.
1. Fill in the table below with a test suite that provides statement coverage. In the Covers column, list
the letter labels (A, B, C, etc.) of the nodes covered by each test case.
Input Expected
Covers
array Output
2. Fill in the table below with a test suite that provides branch coverage. In the Covers column, list the
number labels (1, 2, 3, etc.) of the edges covered by each test case (only true/false edges needed).
Input Expected
Covers
array Output
3. Fill in the table below with a test suite that provides path coverage. In the Covers column, list the
number labels (1, 2, 3, etc.) of the edges covered by each test case. You need only cover executions
that involve at most 1 iteration of each loop (if there are any). Before you fill in the table, list all the
paths to be covered.
Paths:
Input Expected
Covers
array Output
Solutions:
Multiple solutions are possible. These are just examples of correct solutions.
1.
2.
3.