Midterm2012 Sol

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

Midterm

SE465/ECE453/CS447/CS647 W 2012 page of 1 8


University of Waterloo
Student ID:
Signature:
Student Name:
Course Number:

2012 University of Waterloo
Department of Electrical and Computer Engineering
SE465/ECE453/CS447/CS647 Software Testing, Quality Assurance & Maintenance
Instructor: Lin Tan
Examination Date and Time: Tuesday, February 28th, 2012, 5:30 - 6:50 PM
Room(s): (SE465): RCH 305/309
(ECE453/CS447/CS647): RCH 105/110
Instructions:

You have 80 minutes to complete the exam.

You can bring printed or handwritten material, e.g., books, slides, notes, etc.

If you separate the pages, make sure your names and student IDs are on the top of every page.

Unauthorized duplication or archival of these questions is not permitted. To be returned with the
exam booklet after the completion of the exam.

If information appears to be missing from a question, make a reasonable assumption, state your
assumption, and proceed. Do not simplify the question.

Attempt to answer questions in the space provided. If necessary, you may use the back of another
page. If you do this, please indicate it clearly.

Illegible answers receive NO point.

Question Points
Q1 15
Q2 10
Q3 20
Q4 20
Q5 35
Total 100
Midterm
SE465/ECE453/CS447/CS647 W 2012 page of 2 8
University of Waterloo
Q1. Fault, Error and Failure. (15 points)
Below is a faulty Java program. The if-statement needs to take account of negative values. One x is
changing the if-statement to:
if (x[i]%2==1 || x[i]%2==-1)
Based on the x above, answer the following questions for this program. Assume short-circuit boolean
evaluation for these questions. Hint: Whether the second clause, x[i]%2==-1, is executed or not af-
fects the program counter (PC). Justify your answers.

----------------------------------------------------------------------------------------------
public static int odd(int[] x) {
// Effects: if x==null throw NullPointerException,
// else return the number of elements in x that are odd
int count = 0;
for (int i =0; i < x.length; i++) {
if (x[i]%2==1) {
count++;
}
}
return count;
}
----------------------------------------------------------------------------------------------

(a) If possible, identify a test case that does not execute the fault. (5 points)
x must be either null or empty (x=[]). In those cases, the faulty line, if (x[i]%2==1), will not be executed.

(b) If possible, identify a test case that executes the fault, but does not result in an error state. (5
points)

x = [1, 3]
Any nonempty x with only positive odd numbers is a correct answer. Negative odd numbers and even
numbers cause errors: (1) negative odd numbers cause failures, which of course cause errors; and (2)
even numbers cause the PC to point to the second clause because the rst clause is evaluated to be
false.

Midterm
SE465/ECE453/CS447/CS647 W 2012 page of 3 8
University of Waterloo
(c) If possible identify a test case that results in an error, but not a failure. Hint: Don't forget about the
program counter (PC).(5 points)

x = [2, 4]

An erroneous state:
x = [2, 4]
i = 0
count = 0
PC = i++

The correct/expected state:


x = [2, 4]
i = 0
count = 0
PC = the second clause of the predicate/branch (x[0]%2 ==-1)

Any nonempty x containing even numbers but not negative odd numbers is a correct answer.
Given an even number, the PC of the correct program will points to the second clause of the predicate/
branch (x[i]%2 ==-1). The state corresponding to this PC will be missing in the incorrect program.

-------------------
Grading:
- Students only need to nd one test case that satises the condition, and do not need to come up with
all possible answers as the sample solutions.
- Deduct 1 point if no justication is provided.

Midterm
SE465/ECE453/CS447/CS647 W 2012 page of 4 8
University of Waterloo
Q2. One problem with using Prime Path Coverage (PPC) as a coverage criterion is that a
prime path may be infeasible but contains feasible simple paths. (10 points)
(a) Please use one simple program and its corresponding control ow graph (no more than 6 nodes) to
illustrate this problem. Identify one prime path that is infeasible, and the feasible simple paths that
are proper subpaths of the prime path. Note that it is possible to answer this question with a control
ow graph of 4 nodes only. (8 points)

1: i = 10;
2: while (i>0) {
3: print i;
i--;
}
4: exit

The prime path [1, 2, 4] is not feasible, but the simple paths [1,2] and [2,4] are feasible.

(b) Propose one solution to address this problem. (2 points)

1) Replace the infeasible prime path with relevant feasible simple paths,
2) Allow touring with a sidetrip (e.g., best effort touring)

------------
Grading:
- Answering either receives the full 2 points.

Midterm
SE465/ECE453/CS447/CS647 W 2012 page of 5 8
University of Waterloo
Q3. Let us dene Bridge Coverage (BC) as follows. If removing an edge adds unreach-
able nodes to the graph, then this edge is a bridge. The set of test requirements for BC
contains all bridges. For this problem, assume that a graph contains at least two nodes,
and all nodes in a graph are reachable from the initial nodes. (20 points)

(a) Does BC subsume Node coverage (NC)? If yes, justify your answer. If no, give a counterexample.
Simply saying yes or no receives no points. (10 points)

BC does not subsume NC. A counterexample is shown below (not the smallest example).

TRBC = {[1,2], [2,3], [3,5]}
TRNC = {[1, 2, 3,4, 5}
Test path [1,2,3,5] satises BC, but not NC because node 4 is not visited.

Another counterexample is that you make all nodes initial nodes. Then TRBC is empty.

Simply giving the different test requirements is not enough. Need to give the test set (or the corre-
sponding test paths) that violate the denition of subsumption, because although the test requirements
of BC and NC may be different for one graph, any test set that satises BC still satisfy NC. For exam-
ple, the following graph is not a counterexample, because although the test requirements are different,
test paths that satisfy BC also satisfy NC.
TRBC = {[1,2]]}
TRNC = {[1, 2, 3}
Any test paths that visit [1,2] also visit node 3.

Note that a graph with an unreachable node or a graph with only one node is not a correct answer, be-
cause they violate the assumptions of the question.

(b) Does NC subsume BC? If yes, justify your answer. If no, give a counterexample. Simply saying yes
or no receives no points. (10 points)

For any bridge [a, b], any test case that visits b must also visit the edge [a, b] (can be proved by contra-
diction). Any test set that satises NC must visit node b (TR of NC contains all nodes, including node b).
Therefore, for any bridge [a, b], the test set will visit it. Therefore, NC subsumes BC.
1
5
2
3
4
1
2
3
Midterm
SE465/ECE453/CS447/CS647 W 2012 page of 6 8
University of Waterloo
Q4. Logic Coverage (20 points)
For the predicate p = (a ! b) " (b ! c), answer the following questions. Justify your answers.
(a) Compute and simplify the conditions under which each of the clauses determines predicate p. The
conditions must only use ", !, and , and contain the minimal number of logic operators. Complete
the table. (8 points)
(b) Identify all pairs of rows from your table that satisfy GACC with respect to each clause. (5 points)
(c) Write a minimal (the number of test requirements is minimal) set of test requirements (TR) for
GACC. Write the minimal set of test requirements as a set of rows. (2 points)
(d) Identify all pairs of rows from your table that satisfy CACC with respect to each clause. (5 points)
(a) pa = ( b " (b ! c) ) # (b ! c) = b # (b ! c) = b ! c; pb= a " c; pc = b ! a
(b) GACC: Clause a: (2, 6)
Clause b: {1, 2, 5} X {3, 4, 7}
Clause c: (5, 6)
(c) TRGACC = {2, 3, 5, 6}, {2, 4, 5, 6} or {2, 5, 6, 7}
(d) CACC: Clause a: (2, 6)
Clause b: {1, 2, 5} X {3, 4, 7}
Clause c: (5, 6)
------------
Grading:
- OK to infer (a) from truth tables.
- Deduct 0.5 point for not meeting the simplication requirement
a b c p pa pb pc
1 T T T T T
2 T T F T T T
3 T F T F T
4 T F F F T
5 F T T T T T
6 F T F F T T
7 F F T F T
8 F F F F
Midterm
SE465/ECE453/CS447/CS647 W 2012 page of 7 8
University of Waterloo
Q5. Graph Coverage & Logic Coverage (35 points)
Read the following simplified version of the function getDimensionLineBetweenPointsAt extracted
from SweetHome3D. Line numbers are added to the function for your convenience. points.length is
the number of rows in points, i.e., the number of points stored in the two dimensional array points.
Function Point2D.distanceSq(x,y,a,b) returns the Euclidean distance between the points (x,y) and
(a,b), i.e., the distance between the points (x,y) and (a,b) that you would measure with a ruler. This
function does not modify its parameters.

(a) Draw the Control Flow Graph (CFG). Draw the CFG in a way that it contains seven nodes with
one initial node and two nal/accepting nodes. Please follow the convention used in class: put the
branch conditions on the nodes and not on the edges. (8 points)
(b) Annotate each node with its def-set and use-set. For a cleaner graph, it is better not to reuse the
graph from (a). Consider only variables i, points, distance, and nextPointIndex. (7 points)
(c) List the test requirements for All-Defs Coverage (ADC) and All-Uses Coverage (AUC). Consider
only the variable i. Justify your answers. (8 points)
(d) Find a minimal test set (the number of test cases in the test set is minimal) to satisfy All-Uses
Coverage (AUC). Consider only the variable i. Justify your answers. (7 points)
(e) List the test requirements for Predicate Coverage (PC) for the predicate in Line L4 and nd one
test case to satisfy PC. Justify your answers. (5 points)

--------------------------------------------------------------------------------------------------------------------------
private DimensionLine getDimensionLineBetweenPointsAt(float[][] points) {
L1: for (int i = 0; i < points.length; i++) {
L2: int nextPointIndex = (i + 1) % points.length;
// Ignore sides with a length smaller than 0.1 cm
L3: double distance = Point2D.distanceSq(points[i][0],
points[i][1], points[nextPointIndex][0], points[nextPointIndex][1]);
L4: if (distance > 0.01) {
L5: float xStart, yStart, xEnd, yEnd;
L6: xStart = points[i][0];
L7: yStart = points[i][1];
L8: xEnd = points[nextPointIndex][0];
L9: yEnd = points[nextPointIndex][1];

L10: return new DimensionLine(points[i][0], yStart, xEnd, yEnd, 0);
} // end of if (distance > 0.01
} // end of the for loop
L11: return null;
}
--------------------------------------------------------------------------------------------------------------------------

(a) &(b): See the graphs. Although the denition of points is before L1, we accept both def (1) = {i} and
def (1) = {i, points} as correct answers.
(c) TRADC = {[1, 2], [6, 2]} (answers not unique, see TRAUC)
TRAUC = {[1, 2, 3,4,5], [1, 2, 3,4,6], [6, 2, 3,4,5], [6, 2, 3,4,6], [1,2,3], [1,2], [6,2], [6,2,3]}
Please list all du-paths even if they are a subpath of another.
Midterm
SE465/ECE453/CS447/CS647 W 2012 page of 8 8
University of Waterloo

(d) test case t1: points [ (0,0), (0,1)], which maps to the test path [1, 2, 3,4,5].
test case t2: points [ (0,0), (0,0.001), (0,0.002), (0,1.002)], which maps to the test path [1, 2, 3,4,6,
2,3,4,6,2,3,4,5].
test set T = {t1, t2} satises AUC.
(e) TRPC = {distance > 0.01, distance <= 0.01}
test case t2 satises PC for L4.
------------
Grading:
- Accept different ways of drawing CFG but deduct 1 point for not having 7 nodes.
- Deduct 1 point for not marking the initial node
- Deduct 1 point for not marking the nal nodes
L1: int i = 0
L1: i < points.length
L2
L4
L1: i++
L5
L6
L7
L8
L9
L11
def (3) = {nextPointIndex, distance}
use (3) = {i, points, nextPointIndex}
use (4) = {distance}
use (6)= {i}
def (6)= {i}
use (5) = {i, points, nextPointIndex}
def (1) = {i}
use (2) = {i, points}
F
7

You might also like