博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
software testing hw2- find the error
阅读量:4309 次
发布时间:2019-06-06

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

Below are two faulty programs. Each includes a test case that results in failure.

Answer the following questions (in the next slide) about each program.

(1) Identify the fault.

(2) If possible, identify a test case that does not execute the
fault. (Reachability)
(3) If possible, identify a test case that executes the fault, but
does not result in an error state.
(4) If possible identify a test case that results in an error, but
not a failure

1.

public int findLast (int[] x, int y) {
//Effects: If x==null throw
NullPointerException
// else return the index of the last element
// in x that equals y.
// If no such element exists, return -1
for (int i=x.length-1; i > 0; i--)
{
if (x[i] == y)
{
return i;
}
}
return -1;
}
// test: x=[2, 3, 5]; y = 2
// Expected = 0
(1)it will not check the first element,if only the first is equle to y it will return -1
(2)if y=1 the case: [0 2 1]
(3)if y=1 the case: [0 2 3]
(4)if y=1 the case: [1 2 3]

2.

public static int lastZero (int[] x) {
//Effects: if x==null throw
NullPointerException
// else return the index of the LAST 0 in x.
// Return -1 if 0 does not occur in x
for (int i = 0; i < x.length; i++)
{
if (x[i] == 0)
{
return i;
}
} return -1;
}
// test: x=[0, 1, 0]
// Expected = 2
(1)it will show the first zero not the last
(2)case: [0 1 2]
(3)case: [1 2 3]
(4)case: [0 0 0]

转载于:https://www.cnblogs.com/QinYongGui/p/6445842.html

你可能感兴趣的文章
<h:commandLink>和<h:inputLink>的区别
查看>>
<a4j:keeyAlive>的英文介绍
查看>>
关于list对象的转化问题
查看>>
VOPO对象介绍
查看>>
suse创建的虚拟机,修改ip地址
查看>>
linux的挂载的问题,重启后就挂载就没有了
查看>>
docker原始镜像启动容器并创建Apache服务器实现反向代理
查看>>
docker容器秒死的解决办法
查看>>
管理网&业务网的一些笔记
查看>>
openstack报错解决一
查看>>
openstack报错解决二
查看>>
linux source命令
查看>>
openstack报错解决三
查看>>
乙未年年终总结
查看>>
子网掩码
查看>>
第一天上班没精神
查看>>
启动eclipse报错:Failed to load the JNI shared library
查看>>
eclipse安装插件的两种方式在线和离线
查看>>
linux下源的相关笔记(suse)
查看>>
linux系统分区文件系统划分札记
查看>>