标签:boolean 软件测试 bool 节点 out pack new imp org
作业内容:
private static void printPrimes(int n) { int curPrime; int numPrimes; boolean isPrime; int MAXPRIMES=50; int [] primes = new int [MAXPRIMES]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true; for (int i = 0; i <= numPrimes-1; i++) { if (curPrime%primes[i]==0) { isPrime = false; break; } } if (isPrime) { primes[numPrimes] = curPrime; numPrimes++; } } for (int i = 0; i <= numPrimes-1; i++) { System.out.println ("Prime: " + primes[i]); } }
a)控制流图:
b)令MAXPRIMES=50
c)测试用例r=(n=1)
d)节点覆盖
TR={1,2,3,4,5,6,7,8,9,10,11,12,13}
边覆盖
TR={(1,2),(2,3),(2,4),(3,5),(4,11),(5,6),(6,7),(6,8),(7,9),(7,10),(8,5),(9,10),(10,2),(11,12),(11,13),(12,11)}
主路径覆盖
TR={[1,2,4,11,12],[1,2,4,11,13],[1,2,3,5,6,8],[1,2,3,5,6,7,10],[1,2,3,5,6,7,9,10],[11,12,11],[12,11,12],[5,6,8,5],[6,8,5,6],[8,5,6,8]}
e)Juint
完整代码
package printPrimes; public class prime { public static String printPrimes(int n) { int curPrime; int numPrimes; boolean isPrime; int MAXPRIMES=50; int [] primes = new int [MAXPRIMES]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true; for (int i = 0; i <= numPrimes-1; i++) { if (curPrime%primes[i]==0) { isPrime = false; break; } } if (isPrime) { primes[numPrimes] = curPrime; numPrimes++; } } String re=""; for (int i = 0; i <= numPrimes-1; i++) { re=re+primes[i]; System.out.print(primes[i]); } return re; } }
生成测试类
package printPrimes; import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; public class primeTest { prime p; @Before public void setUp() throws Exception { p=new prime(); } @After public void tearDown() throws Exception { } @Test public void testPrintPrimes() { String rel=p.printPrimes(8); assertEquals("wrong",rel,"235711131719"); } }
f)Eclemma
标签:boolean 软件测试 bool 节点 out pack new imp org
原文地址:http://www.cnblogs.com/xzbwx/p/6545610.html