首页 > 代码库 > 软件测试作业三-printPrimes()
软件测试作业三-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()
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。