Use the following method Printprimes () for questions a-d below.
1./** *****************************************************
2. * Finds and Prints n prime integers
3. * Jeff Offutt, Spring 2003
4. ********************************************************* */
5. private static void Printprimes (int n)
6. {
7. int curprime; Value currently considered for primeness
8. int numprimes; Number of primes found so far.
9. Boolean IsPrime; Is Curprime prime?
Ten. int [] primes = new int [maxprimes]; The list of prime numbers.
11.
//Initialize 2 into the list of primes.
primes [0] = 2;
Numprimes = 1;
Curprime = 2;
while (Numprimes < n)
17. {
curprime++; Next number to consider ...
IsPrime = true;
for (int i = 0; I <= numPrimes-1; i++)
{//For each previous prime.
if (Isdivisible (Primes[i], curprime))
. {//Found a divisor, curprime is not prime.
IsPrime = false;
break; Out of loop through primes.
26.}
27.}
if (IsPrime)
{//Save it!
Primes[numprimes] = Curprime;
numprimes++;
32.}
.}//End while
34.
//Print all the primes out.
(int i = 0; I <= numPrimes-1; i++)
37. {
System.out.println ("Prime:" + primes[i]);
39.}
+.}//End Printprimes
Q:
(a) Draw the control flow graph for the Printprimes () method.
(b) Consider test cases T1 = (n = 3) and t2 = (n = 5). Although these tour the same prime paths in Printprimes (), they does not necessarily find the same faults. Design a simple fault that T2 would is more likely to discover than T1 would.
(c) for Printprimes (), find a test case such this corresponding test path visits the edge that connects the beginning Of the while statement to the-statement without going through the body of the while loop.
(d) Enumerate the test requirements for node coverage, Edge coverages, and prime path coverage for the graph for Printprime S ().
A:
(a)
(b) Move line, IsPrime = True, above line, so, no primes after 4.
(c) Test T3 = (n = 1)
(d) Node coverage test requirement: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
Edge coverage Test Requirement: {(1, 2), (2, 3), (+ 3, 4), (4, 5), (5, 6), (6, 8), (5, 7), (7, 4), (4, 8), (8, 9), (9, 10), (10, 2), (2, 11), (11, 12), (12, 13), (13, 12), (12, 14)}
Prime path Coverage test requirement: {[1, 2, 3, 4, 5, 6, 8, 9, 10], [1, 2, 3, 4, 5, 7], [1, 2, 3 , 4, 8, 9, 10], [1, 2, 3, 4, 5, 6, 8, 10], [1, 2, 3, 4, 8, 10], [2, 3, 4, 5, 6, 8, 9, 10, 2], [4, 5, 7, 4], [2, 3, 4, 8, 9 , 10, 2], [2, 3, 4, 5, 6, 8, 10, 2], [2, 3, 4, 8, 10, 2], [1, 2, 11, 12, 13], [1, 2, 11, 12, 14], [12, 13, 12], [13, 12; 1] 3], [13, 12, 14], [3, 4, 5, 6, 8, 9, 10, 2, 11, 12, 13], [3, 4, 5, 6, 8, 9, 10, 2, 11, 12, 14], [3, 4, 5, 6, 8, 10, 2, 11, 12, 13], [3, 4, 5, 6, 8, 10, 2, 11, 12, 14], [3, 4, 8, 9, 10, 2, 11, 12, 13], [3, 4, 8, 9, 10, 2, 11, 12, 14], [3, 4 10, 2, 11, 12, 13], [3, 4, 8, 10, 2, 11, 12, 14], [7, 4, 5, 6, 8, 9, 10, 2, 11, 12, 13], [7, 4, 5, 6, 8, 9, 10, 2, 11, 12, 14], [7, 4, 5, 6, 8, 10, 2, 11, 12, 13], [7, 4, 5, 6, 8, 10, 2, 11, 12, 14], [7, 4, 8, 9, 10, 2, 11, 12, 13], [7, 4, 8, 9 , 10, 2, 11, 12, 14], [7, 4, 8, 10, 2, 11, 12, 13], [7, 4, 8, 10, 2, 11, 12, 14], [5, 7, 4, 5], [7, 4, 5, 7], [3, 4, 5, 6, 8, 9, 10, 2, 3], [3, 4, 5, 6, 8, 10, 2, 3], [3, 4, 8, 9, 10, 2, 3], [3, 4, 8, 10, 2, 3], [4, 8, 9, 10, 2, 3, 4], [4, 8, 10, 2, 3, 4], [4, 5, 6, 8 , 9, 10, 2, 3, 4], [4, 5, 6, 8, 10, 2, 3, 4], [5, 6, 8, 9, 10, 2, 3, 4, 5], [5, 6, 8, 10, 2, 3, 4, 5], [6, 8, 9, 10, 2, 3, 4, 5, 6], [6, 8, 10, 2, 3, 4, 5, 6], [8, 9, 10, 2, 3, 4, 5, 6, 8], [8, 10, 2, 3, 4, 5, 6, 8], [8, 9, 10, 2, 3, 4, 8], [8, 10, 2, 3, 4, 8], [9, 10, 2, 3, 4, 5, 6, 8, 9], [9, 10, 2, 3, 4, 8, 9], [10, 2, 3, 4, 5, 6, 8, 9, 10], [10, 2, 3, 4, 5, 6, 8, 10], [10, 2, 3, 4, 8, 9, 10], [10, 2, 3, 4, 8, 9, 10], [10, 2, 3, 4, 8, 10]}
A Prime path coverage test for program of LAB1:
Each test is the prime path test.
1 PackageLab1;2 3 Public classLAB1 {4 5 PublicString Check (intAintBintc) {6 //sorting makes A<=b<=c7 inttemp;8 if(A >b) {9 if(A >c) {Tentemp =C; Onec =A; A if(B >temp) -A =temp; - Else{ theA =b; -b =temp; - } -}Else{ +temp =A; -A =b; +b =temp; A } at}Else if(B >c) { -temp =C; -c =b; -b =temp; - } - in if(A <= 0 | | A + b <=c) - return"The input edges cannot form a triangle"; to Else if(A = = B | | b = =c) + returnA = = c? "Equilateral triangle": "isosceles triangle"; - Else the return"General Triangle"; * } $ Panax Notoginseng}
1 PackageLab1;2 3 Import Staticorg.junit.Assert.assertEquals;4 5@RunWith (parameterized.class)6 Public classLab1test {7 8 Private intinput1;9 Private intInput2;Ten Private intinput3; One PrivateString expected; A PrivateLAB1 test; - - PublicLab1test (intINPUT1,intInput2,intInput3, String expected) { the This. INPUT1 =input1; - This. Input2 =Input2; - This. INPUT3 =input3; - This. Expected =expected; + } - + @Before A Public voidsetUp () { atTest =NewLab1 (); - } - - @Parameters - Public StaticCollection<object[]>GetData () { - returnArrays.aslist (Newobject[][]{ in{2, 3, 4, "General triangle"}, -{8, 7, 9, "General triangle"}, to{5, 5, 5, "equilateral triangle"}, +{1, 1, 1, "equilateral triangle"}, -{6, 7, 7, "isosceles triangle"}, the{10, 7, 9, "General triangle"}, *{9, 7, 4, "General triangle"}, ${2, 2, 3, "isosceles triangle"},Panax Notoginseng{1, 6, 4, "The input edge cannot form a triangle"}, -{0,-1, 3, "The input edge cannot form a triangle"}, the }); + } A the @Test + Public voidTestcheck () { -Assertequals ( This. Expected, Test.check (INPUT1, Input2, INPUT3)); $ } $}
Software Testing--graph Coverage (1)