Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Problem: Draw A Control Flow Diagram For This Function. Label Each Edge With An Uppercase Letter

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Problem: Draw a control flow diagram for this function. Label each edge with an uppercase letter.

int funWithNumbers(int a, int b) {


if (a > b) {
while (a >= b) {
a -= 1;
b += 1;
}
} else {
b += a;
}
return b;
}
Solution:
Problem: Fill in the table below with a test suite that provides path coverage of the code from the previ-
ous question. Cover no more than 2 iterations of the loop. In the covers column, list the relevant labeled
items in your CFG that each test case covers. If there is some part of the coverage that is impossible to
cover, then list it in the covers column, and put “N/A” in the associated x and y cells. Some cells in the
table may be left blank.

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.

int blammo(int u, int v) {


int t;
while (v != 0) {
t = u;
u = v;
v = t % v; // Recall that % computes remainder of t/v
}
if (u < 0) { return –u; }
return u;
}
Solution:
Problems:

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

Solution: Path Coverage


Consider this binary-search function and its associated control-flow graph.

False True

False True

False True
Problems:

Consider the following test cases for the binary_search function.

array key imin imax


a. [1] 0 0 0
b. [1] 1 0 0
c. [1] 1 1 0
d. [1, 2, 3] 1 0 2
e. [1, 2, 3] 2 0 2
f. [1, 2, 3] 3 0 2
g. [1, 2, 3] 1 2 0
h. [1, 2, 3] 2 2 0
i. [1, 2, 3] 3 2 0

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:

Consider the following test cases for the binary_search function.

array key imin imax


a. [0] 0 0 0
b. [0] 1 0 0
c. [0] 1 1 0
d. [0] -1 0 0

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

You might also like