博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
软件测试作业03
阅读量:6711 次
发布时间:2019-06-25

本文共 2668 字,大约阅读时间需要 8 分钟。

a)

b) 令MAXPRIMES=4;则对于t2(n=5)会出现ArrayIndexOutOfBoundsException,即越界错误,而t1(n=3)则无法发现。

c)printPrimes(1)

d)

node coverage:

{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}

Edge coverage:

{(1,2),(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)}

Prime path coverage:

{

[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]

[1,2,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]

}

测试:

首先,为了便于测试,将原先printPrimes函数修改如下:

static final int MAXPRIMES=1024;public static String getPrimes(int n){	int curPrime; //Value currently considered for primeness        int numPrimes; // Number of primes found so far;        boolean isPrime; //Is curPrime prime?        int[] primes = new int[MAXPRIMES];// The list of primes.        // 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(int i = 0; i < numPrimes; i++ ) {                //for each previous prime.//               if(isDvisible(primes[i],curPrime)) {                                if(curPrime%primes[i]==0) {                    //Found a divisor, curPrime is not prime.                    isPrime = false;                    break;                }            }            if(isPrime) {                // save it!                primes[numPrimes] = curPrime;                numPrimes++;                        }        }// End while                // print all the primes out        String ret="";        for(int i = 0; i < numPrimes; i++) {        	ret+=+primes[i]+" ";        }return ret;}

  

测试代码:

package hw03;import static org.junit.Assert.*;import org.junit.Test;public class TestHw03 {	private static final int testCases[]={1,2,3,4,5,6,7,8,9,10};	private static final String testAns[]=        {"2 ","2 3 ","2 3 5 ","2 3 5 7 ","2 3 5 7 11 ","2 3 5 7 11 13 ",        "2 3 5 7 11 13 17 ","2 3 5 7 11 13 17 19 ","2 3 5 7 11 13 17 19 23 ",        "2 3 5 7 11 13 17 19 23 29 ",};	@Test	public void primePathCover(){		for(int i=0;i

测试结果:

转载于:https://www.cnblogs.com/blackwiseman/p/8641068.html

你可能感兴趣的文章
split的用法回顾,快忘记了@ →@
查看>>
正则表达式的简单应用
查看>>
【ubuntu】系统设置打不开
查看>>
抽象工厂模式和autofac的使用总结
查看>>
ManyToMany参数(through,db_constraint)
查看>>
Struts工作原理、流程
查看>>
(转)Entity Framework在三层架构中的使用--MVC三层架构启示
查看>>
【原】记2015招商银行信用卡中心在线笔试------4.2
查看>>
Node Graph ......
查看>>
开放平台-web实现人人网第三方登录
查看>>
跨域iframe高度自适应(兼容IE/FF/OP/Chrome)
查看>>
如何在遗留代码基础上开发
查看>>
git使用命令, 特别:git checkout -b a 与 git branch a区别(转)
查看>>
vs中附加IIS进程调试
查看>>
Mongodb的安装方法 -- 转自朋友微博
查看>>
作业09-异常
查看>>
UI基础 - UINavigationController
查看>>
C#综合揭秘——细说多线程(下)
查看>>
第十一回 基础才是重中之重~Conditional特性使代码根据条件在debug或者release模式中执行...
查看>>
Attention Model详解
查看>>