標籤:
一、對一個方法進行測試
private static void printPrimes(int n){ int curPrime; int numPrimes; boolean isPrime; int [] primes = new int [43]; primes[0]=2; numPrimes = 1; curPrime = 2; while ( numPrimes < n) { curPrime ++ ; isPrime = true; for ( int i = 0 ; i <= numPrimes-1 ;i++){ if (isDivisible(primes[i],curPrime)) { isPrime = false; break ; } } if (isPrime){ primes[numPrimes] = curPrime ; numPrimes ++ ; } } for (int i = 0 ; i <= numPrimes -1 ; i++ ) { System.out.println("Prime: " + primes[i]); } }
1)畫出此方法的控制流程圖
2)T1 : n = 3 ;T2 : n = 5;
設計一個 Fault 使T2 能發現,T1不能發現:
答:
將 if ( isDivisible(primes[i],curPrime) 修改 為 if ( isDivisible(primes[0],curPrime)
3)設計一個測試案例不經過While的body
答:
n <= 1 即可
4)枚舉TR 對於 NC ,EC ,PPC
TR :
i)NC:{1,2,3,4,5,6,7,8,9,10,11,12,13}
ii)EC:{(1,2),(2,3),(2,10),(3,4),(4,5),(4,8),(5,6),(5,7),(6,8),(7,4),(8,2),(8,9),
(9,2),(10,11),(11,12),(11,13),(12,11)}
iii)PPC:一共51條
A.[11,12,11] , [12,11,12]點11,12組成的環可以寫出2條路徑
B.點4,5,7 組成的環可以寫出3條路徑
C.點2,3,4,8組成的環可以寫出4條路徑
D.點2,3,4,8,9組成的環可以寫出5條路徑
E.點2,3,4,5,6,8組成的環可以寫出6條路徑
F.點2,3,4,5,6,8,9組成的環可以寫出7條路徑
G.點1出發的有5條:[1,2,10,11,13],[1,2,10,11,12],[1,2,3,4,5,7],[1,2,3,4,8,9],[1,2,3,4,5,6,8,9]
H.點3出發的有9條:[3,4,5,7],[3,4,8,2,10,11,12],[3,4,8,2,10,11,13],[3,4,8,9,2,10,11,12],[3,4,8,9,2,10,11,13],
[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]
I.點5出發的有4條:[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]
J.點7出發的有4條:[7,4,5,6,8,2,10,11,12],[7,4,5,6,8,2,10,11,13],[7,4,5,6,8,9,2,10,11,12],[7,4,5,6,8,9,2,10,11,13]
K.點8出發的有2條:[8,2,3,4,5,7],[8,2,3,4,5,6]
軟體測試homework3