Public Static voidPrintprimes (intN) {intCurprime; intNumprimes; BooleanIsPrime; int[] primes =New int[Maxprimes]; primes [0] = 2; Numprimes= 1; Curprime= 2; while(Numprimes <N) {curprime++; IsPrime=true; for(inti = 0; I <= numPrimes-1; i++) { if(curprime%primes[i]==0) {IsPrime=false; Break; } } if(IsPrime) {Primes[numprimes]=Curprime; Numprimes++; } } for(inti = 0; I <= numPrimes-1; i++) {System.out.println ("Prime:" +Primes[i]); }
First, control flow diagram
Second, the test Case t1= (n=3), and t2= (n=5), T2 prone to two T1 is not prone to errors are: array out of bounds.
Third, n=1, the corresponding test path access connection While statement starts to the edge of the for statement, rather than passing through the while loop body.
Iv. node overwrite: {0,1,2,3,4,5,6,7,8,9,10,11,12}
Side overlays: {(0,1), (2,3), (3,4), (4,5), (5,7), (4,6), (3,7), (7,9), (6,3), (7,8), (8,9), (1,9), (9,10), (10,11), (11,10), ( 10,12)}
Main path overrides: {(0,1,2,3,4,5,7,8,9,10,11,), (0,1,2,3,4,5,7,8,9,10,12), (0,1,2,3,4,5,7,9,10,11), (0,1,2,3,4,5,7,9,10,12), ( 0,1,2,3,4,6),
(0,1,9,10,12), (10,11,10), (11,10,11), (3,4,6,3), (4,6,3,4), (6,3,4,6)}
V. Main PATH coverage
Software Test Map Overlay