cs525T_homework4

advertisement
Scott Froberg
CS525T Testing for Developers
2/16/2012
Hw4
(a) Draw the control flow graph for the printPrimes() method.
See Attached
(b) Consider test cases t1 = (n = 3) and t2 = (n = 5). Although these tour the same prime paths in
printPrimes(), they do not necessarily find the same faults. Design a simple fault that t2 would be
more likely to discover than t1 would.
The simplest fault is to reduce the size of the prime array to less than 5
int [] primes = new int [4];
This will cause an exception in testcase t2.
(c) For printPrimes(), find a test case such that the corresponding test path visits the edge that connects
the beginning of the while statement to the for statement without going through the body of the
while loop.
If the n= 1 then the body of the while loop will not execute. The resulting test path is
[1, 2, 12, 13, 14, 15, 13, 16]
(d) Enumerate the test requirements for Node Coverage, Edge Coverage, and Prime Path Coverage for
the graph for printPrimes().
Node Coverage: {1,2,3,4,5,6,7,8,9,10,11,12,13,14 15,16}
Edge Coverage: {[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,9],[6,8],[8,5],[5,9],[9,10]
[9,11],[10,11],[11,2],[2,12],[12,13],[13,14],[13,16],[14,15],[15,13]}
Prime Path Coverage: 66 prime paths
[5 6 8 5 ]
[6 8 5 6 ]
[8 5 6 8 ]
[13 14 15 13 ]
[14 15 13 14 ]
[14 15 13 16 ]
[15 13 14 15 ]
[1 2 12 13 16 ]
[1 2 12 13 14 15 ]
[1 2 3 4 5 6 8 ]
[1 2 3 4 5 9 11 ]
[2 3 4 5 9 11 2 ]
[3 4 5 9 11 2 3 ]
[4 5 9 11 2 3 4 ]
[5 9 11 2 3 4 5 ]
[9 11 2 3 4 5 9 ]
[11 2 3 4 5 9 11 ]
[1 2 3 4 5 9 10 11 ]
[2 3 4 5 9 10 11 2 ]
[3 4 5 9 10 11 2 3 ]
[4 5 9 10 11 2 3 4 ]
[6 8 5 9 11 2 3 4 ]
[5 9 10 11 2 3 4 5 ]
[9 10 11 2 3 4 5 9 ]
[10 11 2 3 4 5 9 10 ]
[11 2 3 4 5 9 10 11 ]
[1 2 3 4 5 6 7 9 11 ]
[2 3 4 5 6 7 9 11 2 ]
[3 4 5 6 7 9 11 2 3 ]
[3 4 5 9 11 2 12 13 16 ]
[4 5 6 7 9 11 2 3 4 ]
[5 6 7 9 11 2 3 4 5 ]
[6 7 9 11 2 3 4 5 6 ]
[7 9 11 2 3 4 5 6 7 ]
[7 9 11 2 3 4 5 6 8 ]
[6 8 5 9 10 11 2 3 4 ]
[6 8 5 9 11 2 12 13 16 ]
[8 5 6 7 9 11 2 3 4 ]
[9 11 2 3 4 5 6 7 9 ]
[11 2 3 4 5 6 7 9 11 ]
[1 2 3 4 5 6 7 9 10 11 ]
[2 3 4 5 6 7 9 10 11 2 ]
[3 4 5 6 7 9 10 11 2 3 ]
[3 4 5 9 10 11 2 12 13 16 ]
[3 4 5 9 11 2 12 13 14 15 ] [4 5 6 7 9 10 11 2 3 4 ]
[5 6 7 9 10 11 2 3 4 5 ]
[6 7 9 10 11 2 3 4 5 6 ]
[7 9 10 11 2 3 4 5 6 7 ]
[7 9 10 11 2 3 4 5 6 8 ]
[6 8 5 9 10 11 2 12 13 16 ] [6 8 5 9 11 2 12 13 14 15 ]
[8 5 6 7 9 10 11 2 3 4 ]
[8 5 6 7 9 11 2 12 13 16 ]
[9 10 11 2 3 4 5 6 7 9 ]
[10 11 2 3 4 5 6 7 9 10 ]
[11 2 3 4 5 6 7 9 10 11 ]
[3 4 5 6 7 9 11 2 12 13 16 ]
[3 4 5 9 10 11 2 12 13 14 15 ]
[6 8 5 9 10 11 2 12 13 14 15 ]
[8 5 6 7 9 10 11 2 12 13 16 ]
[8 5 6 7 9 11 2 12 13 14 15 ]
[3 4 5 6 7 9 10 11 2 12 13 16 ]
[3 4 5 6 7 9 11 2 12 13 14 15 ]
[8 5 6 7 9 10 11 2 12 13 14 15 ]
[3 4 5 6 7 9 10 11 2 12 13 14 15 ]
(e) List test paths that achieve Node Coverage but not Edge Coverage on the graph.
This is not possible because complete Edge Coverage subsumes Complete Node coverage.
(f) List test paths that achieve Edge Coverage but not Prime Path Coverage on the graph.
There are no edge paths for this graph that are not subsumed by Prime Path Coverage.
If there were Edge-Pair coverage then there would be Edge Coverage that is not covered
by Path Coverage.
The Edge Coverage is
{1,2,12,13,14,15,13,16}, {1,2,3,4,5,9,10,11,2,12,13,16},
{1,2,3,4,5,6,8,5,9,11,2,12,13,16}, {1,2,3,4,5,6,7,9,11,2,12,13,16}
Download