软件测试作业三-printPrimes()
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件测试作业三-printPrimes()相关的知识,希望对你有一定的参考价值。
作业内容:
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
以上是关于软件测试作业三-printPrimes()的主要内容,如果未能解决你的问题,请参考以下文章