The code in the original question
/******************************************************* * Finds and prints n prime integers * Jeff Offutt, SPR ING 2003 ******************************************************/ 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(Isdivisible (primes[i], curprime)) {//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
Control Flow Graph
B: Array out of bounds, when maxprimes = = 4 o'clock, n=5 will raise the bounds
C:
N= 1 o'clock, does not meet numprimes<n, so point to 12
D:
Dot Overwrite {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
Side overrides {(2,3), (2,12), (3,4), (4,5), (5,6), (5,9), (6,7), (6,8), (7,5), (8,9), (9,10), (9,11), (10,11), (11,2), (12,13), ( 13,14), (13,16), (14,15), (15,13)}
The 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), ( , 12,13,14,15), (1,2,12,13,16), (3,4,5,6,8,9,11,2,12,13,14,15), (3,4,5,6,8,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,10,11,2,12,13,16), (3,4,5,9,11,2,12,13,14,15), (3, 4,5,9,10,11,2,12,13,14,15), (3,4,5,9,11,2,12,13,16), (3,4,5,9,10,11,2,12,13,16), (6,7,5,9,11,2,12,13,14,15), (6, 7,5,9,10,11,2,12,13,14,15), (6,7,5,9,11,2,12,13,16), (6,7,5,9,10,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 Master Path overrides
The triangles in the first experiment have completed full coverage
Tri class
Package stlab1; Public classTri { Public StaticString Istri (DoubleADoubleBDoublec) {if(b >= a && b >=c) {Doubletemp =b; b=A; A=temp; } if(c >= a && c >=b) {Doubletemp =C; C=A; A=temp; } if(b + C <=a)return "not a triangle ."; if(A = = b && b = =c)return "equilateral triangle"; if(A = = B | | b = = c | | a = =c) {return "isosceles Triangle"; } if(A * = = b * B + c *c)return "Right Triangle"; return "General Triangles"; }}
Test class
Package Stlab1;importStaticorg.junit.assert.*; import org.junit.after;import org.junit.afterclass;import org.junit.before;import org.junit.BeforeClass; Import Org.junit.Test; Public classtritest {@BeforeClass Public Static voidSetupbeforeclass () throws Exception {} @AfterClass Public Static voidTeardownafterclass () throws Exception {} @Before Public voidsetUp () throws Exception {} @After Public voidTearDown () throws Exception {} @Test Public voidTest () {Tri tri=NewTri (); Assertequals ("equilateral triangle", Tri.istri (1,1,1)); Assertequals ("not a triangle .", Tri.istri (0,1,2)); Assertequals ("Right Triangle", Tri.istri (3,4,5)); Assertequals ("isosceles Triangle", Tri.istri (3,3,5)); Assertequals ("General Triangles", Tri.istri (4,6,7)); Assertequals ("isosceles Triangle", Tri.istri (4,4,2)); Assertequals ("isosceles Triangle", Tri.istri (3,2,2)); }}
Software Testing (iv) Master path overlay HW3