Public Static voidPrintprimes (intN) {intCurprime;//Value currently considered for primeness intNumprimes;//Number of primes found so far. BooleanIsPrime;//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 streaming chart.
b) Test Cases t1= (n=3) and t2= (n=5), design an error T2 can find but T1 cannot find.
Array out of bounds problem.
c) Find a test case that does not pass through the while loop.
N=1;
d) identify all test requirements for point coverage, edge coverage, and master path coverage.
Dot overwrite: {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
Side overlays: {(2,3), (3,4), (4,5), (5,6), (5,9), (6,7), (6,8), (7,5), (8,9), (9,10), (9,11), (10,11), (11,2), (2,12), (12,13), ( 13,14), (13,16), (14,15), (15,13)}
Main path Overrides:
{(1,2,3,4,5,6,7), (1,2,3,4,5,6,8,9,11), (1,2,3,4,5,6,8,9,10,11), (1,2,3,4,5,9,11), (1,2,3,4,5,9,10,11), ( 1,2,12,13,16), (1,2,12,13,14,15),
(2,3,4,5,9,11,2), (2,3,4,5,9,10,11,2), (2,3,4,5,6,8,9,11,2), (2,3,4,5,6,8,9,10,11,2),
(3,4,5,9,11,2,3), (3,4,5,9,10,11,2,3), (3,4,5,6,8,9,11,2,3), (3,4,5,6,8,9,10,11,2,3), (3,4,5,9,11,2,12,13,16), ( 3,4,5,9,11,2,12,13,14,15), (3,4,5,9,10,11,2,12,13,16), (3,4,5,9,10,11,2,12,13,14,15), (3,4,5,6,8,9,11,2,12,13,16) , (3,4,5,6,8,9,11,2,13,14,15), (3,4,5,6,8,9,10,11,2,12,13,16), (3,4,5,6,8,9,10,11,2,12,13,14,15),
(4,5,9,11,2,3,4), (4,5,9,10,11,2,3,4), (4,5,6,8,9,11,2,3,4), (4,5,6,8,9,10,11,2,3,4),
(5,6,7,5), (5,9,11,2,3,4,5), (5,9,10,11,2,3,4,5), (5,6,8,9,11,2,3,4,5), (5,6,8,9,10,11,2,3,4,5),
(6,7,5,6), (6,8,9,11,2,3,4,5,6), (6,8,9,10,11,2,3,4,5,6), (6,7,5,9,11,2,12,13,16), (6,7,5,9,11,2,12,13,14,15), ( 6,7,5,9,10,11,2,12,13,16), (6,7,5,9,10,11,2,12,13,14,15), (6,7,5,9,11,2,3,4,5,6), (6,7,5,9,10,11,2,3,4,5,6),
(7,5,6,7), (7,5,6,8,9,11,2,3,4), (7,5,6,8,9,10,11,2,3,4), (7,5,6,8,9,11,2,12,13,16), (7,5,6,8,9,11,2,12,13,14,15), (7,5,6,8,9,10,11,2,12,13,16), (7,5,6,8,9,10,11,2,12,13,14,15),
(8,9,11,2,3,4,5,6,8), (8,9,10,11,2,3,4,5,6,8), (8,9,11,2,3,4,5,6,7), (8,9,10,11,2,3,4,5,6,7),
(9,11,2,3,4,5,9), (9,10,11,2,3,4,5,9), (9,11,2,3,4,5,6,8,9), (9,10,11,2,3,4,5,6,8,9),
(10,11,2,3,4,5,9,10), (10,11,2,3,4,5,6,8,9,10),
(11,2,3,4,5,9,11), (11,2,3,4,5,9,10,11), (11,2,3,4,5,6,8,9,11), (11,2,3,4,5,6,8,9,10,11)
(13,14,15,13),
(14,15,13,14), (14,15,13,16),
(15,13,14,15)}
JUnit for Master path overlay test
Public classStatistics {/** * * @paramnumbers *@returnThe length of the array*/ Public intCallength (int[] numbers) { intLength =numbers.length; returnlength; } /** * * @paramnumbers *@returnThe mean value of the array*/ Public DoubleCalmean (int[] numbers) { intLength =callength (numbers); Doublesum; Sum= 0.0; for(inti = 0; i < length; i++) {sum+=Numbers[i]; } Doublemean = SUM/(Double) length; returnmean; } /** * * @paramnumbers *@returnThe var value of the array*/ Public DoubleCalvar (int[] numbers) { intLength =callength (numbers); Doublemean =Calmean (numbers); DoubleVarsum = 0.0; for(inti = 0; i < length; i++) {varsum= Varsum + ((numbers[i]-mean) * (Numbers[i]-mean)); } Doublevar = varsum/(length-1.0); returnvar; }}
Import Staticorg.junit.assert.*;ImportOrg.junit.Before;Importorg.junit.Test; Public classStatisticstest {PrivateStatistics Statistics; @Before Public voidSetUp ()throwsException {Statistics=NewStatistics (); } @Test Public voidTest () {//fail ("not yet implemented"); intA[] = {1,1,1,1,1,1} ; Assertequals (0.0,statistics.calvar (a), 0.0001); }}
Software Test Learning (4)