The code given in the topic is
1 /******************************************************* 2 * Finds and prints n prime integers3 * Jeff Offutt, Spring 20034 ******************************************************/ 5 Public Static voidPrintprimes (intN)6 { 7 intCurprime;//Value currently considered for primeness8 intNumprimes;//Number of primes found so far.9Boolean isprime;//Is curprime prime?Ten int[] primes =New int[Maxprimes];//The list of prime numbers. One A //Initialize 2 into the list of primes. -primes [0] =2; -Numprimes =1; theCurprime =2; - while(Numprimes <N) - { -curprime++;//next number to consider ... +IsPrime =true; - for(inti =0; I <= numprimes-1; i++) +{//For each previous prime. A if(Isdivisible (primes[i], curprime)) at{//Found a divisor, curprime is not prime. -IsPrime =false; - Break;//Out of loop through primes. - } - } - if(IsPrime) in{//Save It! -Primes[numprimes] =Curprime; tonumprimes++; + } -}//End while the * //Print all the primes out. $ for(inti =0; I <= numprimes-1; i++) Panax Notoginseng { -System. out. println ("Prime:"+Primes[i]); the } +}//End Printprimes
(a): Control flow chart as follows
(b): Set Maxprimes to 4 so that t2= (n=5) will have an array out of bounds error, but t1= (n=3) has no effect.
(c): N=1 not meet Numprimes < N, it does not go through the while loop
(d): Dot overlay: {1,2,3,4,5,6,7,8,9,10,11,12,13,14}
Side overlays: {(2,3), (2,12), (3,4), (4,5), (5,6), (6,7), (6,8), (7,5), (8,9), (5,9), (9,10), (9,11), (10,11), (11,2), (12,13), (13,14), (14,15), (15,13), (13,16)}
Main path overrides: {(1,2,3,4,5,6,7), (1,2,3,4,5,6,8,9,10,11), (1,2,3,4,5,6,8,9,11), (1,2,3,4,5,9,10,11), (1,2,3,4,5,9,11), (1, 2,12,13,14,15), (1,2,12,16), (3,4,5,6,8,9,10,11,2,12,13,14,15),
(3,4,5,6,8,9,11,2,12,13,14,15), (3,4,5,6,8,9,10,11,2,12,13,16), (3,4,5,6,8,9,11,2,12,13,16), (3, 4,5,9,10,11,2,12,13,14,15), (3,4,5,9,11,2,12,13,14,15), (3,4,5,9,10,11,2,12,13,16),
(3,4,5,9,11,2,12,13,16), (6,7,5,9,10,11,2,12,13,14,15), (6,7,5,9,11,2,12,13,14,15), (6,7,5,9,10,11,2,12,13,16), (6 , 7,5,9,11,2,12,13,16), (14,15,13,16), (13,14,15,13), (5,6,7,5),
(2,3,4,5,6,8,9,10,11,2), (2,3,4,5,6,8,9,11,2), (2,3,4,5,9,10,11,2), (2,3,4,5,9,11,2)}
Design test Cases for master path overrides
Take the judging triangle of the last experiment as an example
1 Package Cn.tju.st;2 Public classCalculate {3 PublicString Triangle (intAintBintc)4 {5 String str;6 intd=a-b;7 inte=b-C;8 intf=a-C;9 if(d*e*f==0){TenStr="isosceles"; One if((a==b) && (b==c)) AStr="Equilateral"; - } - Else theStr="other"; - returnstr; - - } +}
Package cn.tju.st;import org.junit.after;import org.junit.before;import org.junit.test;importStaticorg.junit.assert.*; import Java.util.arrays;import java.util.collection;import Org.junit.runner.runwith;import Org.junit.runners.parameterized;import org.junit.runners.Parameterized.Parameters; @RunWith (parameterized.class) Public classCalculatetest {PrivateString type; Private intA; Private intb; Private intC; PublicCalculatetest (String type,intAintBintc) { This. Type =type; This. A =A; This. B =b; This. C =C; } @Before Public voidsetUp () throws Exception {//System.out.println ("This is before Test");} @After Public voidTearDown () throws Exception {System. out. println ("This was after test"); } @Parameters Public StaticCollection Preparedata () {object[][]Object= { {"Equilateral",1,1,1}, {"isosceles",2,2,3}, {"isosceles",2,3,3}, {"other",2,3,4}}; returnArrays.aslist (Object); } @Test Public voidTesttypeoftriangle () {Calculate Calc=NewCalculate (); Assertequals (Type, Calc.triangle (a,b,c)); }}
The test results are as follows, the master path overlay has been completed
Software Test Job (iv)