Review the knowledge of the path overlay based on the Printprimes () code. The relevant code is as follows:
/******************************************************* * Finds and prints n prime integers * Jeff Offutt, Sp Ring 2003 ******************************************************/ Public Static voidPrintprimes (intN) {intCurprime;//Value currently considered for primeness intNumprimes;//Number of primes found so far.Boolean isprime;//Is curprime prime? int[] primes =New int[Maxprimes];//The list of prime numbers. //Initialize 2 into the list of primes.primes [0] =2; Numprimes=1; Curprime=2; while(Numprimes <N) {curprime++;//next number to consider ...IsPrime =true; for(inti =0; I <= numprimes-1; i++) { //For each previous prime. if(curprime%primes[i]==0) { //Found a divisor, curprime is not prime.IsPrime =false; Break;//Out of loop through primes. } } if(isprime) {//Save It!Primes[numprimes] =Curprime; Numprimes++; } } //End while//Print all the primes out. for(inti =0; I <= numprimes-1; i++) {System. out. println ("Prime:"+Primes[i]); } } //End Printprimes
(a) Draw a control flow graph for printprimes ().
(b) Design a simple error that makes T2 (n=5) easier to spot than T1 (n=3).
An array of out-of-bounds errors that are more prone to occur. When Maxprimes is 4 o'clock, T2 will cross the border.
(c) Find a test case that allows the corresponding test path access connection while statement to start to the edge of the for statement, not through the while loop body.
When N=1, you can meet the requirements.
(d) require identification of all TR (test requirements) for point coverage, edge coverage, and master path coverage
1) Dot overwrite: {1,2,3,4,5,6,7,8,9,10,11,12,13}
2) Side overlay: {(2,3), (2,10), (3,4), (4,5), (4,8), (5,6), (5,7), (6,8), (7,4), (8,9), (8,2), (9,2), (10,11), (11,12), (12,11), (11,13)}
3) Main path overlay: {1,2,3,4,5,6,8,9},{1,2,3,4,5,7},{1,2,3,4,8,9},{2,3,4,8,2},{2,3,4,8,9,2},{1,2,10,11,12},{1,2,10,11,13}, {4,5,7,4},{5,7,4,5},{11,12,11},{12,11,12},{3,4,5,6,8,2,10,11,12},{3,4,5,6,8,2,10,11,13},{ 3,4,5,6,8,9,2,10,11,12},{3,4,5,6,8,9,2,10,11,13},{3,4,8,2,10,11,13},{3,4,8,2,10,11,12},},{3,4,8,9,2,10,11,12}, {3,4,8,9,2,10,11,12},{5,7,4,8,2,10,11,12},{5,7,4,8,2,10,11,13},{5,7,4,8,9,2,10,11,12},{5,7,4,8,9,2,10,11,13}
Finally, design the use case for the master Path Test overlay. Take the triangle as an example:
Package triangle; Public classTriangle {Private intSide1; Private intSide2; Private intSide3; Publictriangle () { This(1,1,1); } PublicTriangleintAintBintc) { This. Side1 =A; This. Side2 =b; This. Side3 =C; } PublicString GetType (intSide1,intSide2,intside3) throws exception{if(Side1 <1|| Side1 > -|| Side2 <1|| Side2 > -|| Side3 <1|| Side3 > -) return "Edge Fetch value out of range" ; if(Side1 + side2 <= side3 | | side1 + side3 <= Side2 | | Side2 + side3 <=side1)Throw NewException ("does not constitute a triangle"); if(Side1 = = Side2 && Side2 = =side3)return "equilateral triangle"; Else if((Side1 = = Side2 | | side1 = SIDE3 | | side2 = SIDE3) &&(Isrttriangle (SIDE1,SIDE2,SIDE3)))return "isosceles Right Triangle" ; Else if(Side1 = = Side2 | | side1 = SIDE3 | | side2 =side3)return "isosceles Triangle"; Else if(Isrttriangle (side1,side2,side3))return "Right Triangle"; Else return "General Triangles"; } PublicBoolean Isrttriangle (intAintBintc) { intA1 = A *A; intB1 = b *b; intC1 = c *C; if(a1 + B1 = = C1 | | A1 + c1 = B1 | | B1 + C1 = =A1)return true; return false; } Public Static voidMain (string[] args) {triangle TR=NewTriangle (3,4,5); Try{System. out. println (Tr.gettype (3,4,5)); }Catch(Exception e) {e.printstacktrace (); } } }
@Parameters Public StaticCollection<object[]>GetData () {returnArrays.aslist (Newobject[][]{{1,2,-1,false,"Edge Fetch value out of range"}, { About, About,101,false,"Edge Fetch value out of range"}, {3,2,2,false,"isosceles Triangle"}, {2,2,2,false,"equilateral triangle"}, {3,4,5,true,"Right Triangle"}, {3,4,2,false,"General Triangles"}, }); } @Test Public voidTesttype () throws Exception {assertequals ( This. Exptype,tr.gettype (INPUT1,INPUT2,INPUT3)); }
You can implement full coverage of the main path of the code.
Software Test Learning (4) Printprimes ()