Questions:

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.

Program One:

 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-; i > ; i--)
{
if (x[i] == y) {
return i;
}
}
return -;
}
// test: x=[2, 3, 5]; y = 2
// Expected = 0

Answers:

1、错误代码:

for(int i = x.length-; i > ; i--)

原因:应共遍历x.length次,且数组下标从零开始。

改正为:

for(int i = x.length-; i >= ; i--)

2、A test case: x = [] ——> If x == null throw NullPointerException,不会执行fault。

3、A test case: x = [2, 3, 5]; y = 3 ——> The result is 1,执行了fault,且结果正确。

4、A test case: x = [2, 3, 5]; y = 4 ——> The result is -1,是error,不是failure。


Program Two:

 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 = ; i < x.length; i++)
{
if (x[i] == ) {
return i;
}
}
return -;
}
// test: x=[0, 1, 0]
// Expected = 2

Answers:

1、错误代码:

for (int i = ; i < x.length; i++)

原因:返回的应该是最后一个零的位置,上述代码返回的是第一个零的位置,且数组下标从零开始。

改正为:

for (int i = x.length-; i >= ; i--)

2、A test case: x = [] ——> If x == null throw NullPointerException,不会执行fault。

3、A test case: x = [1, 0, 1] ——> The result is 1,执行了fault,且结果正确。

4、A test case: x = [2, 3, 5] ——> The result is -1,是error,不是failure。

Software Testing 2 —— Fault、error and failure小练习的更多相关文章

  1. ST HW2 fault & error & failure

    Software Testing 3014218128 牛菲菲 Below are two faulty programs. Each includes a test case that result ...

  2. 结对编程--fault,error,failure

    结对编程对象:叶小娟 对方博客地址:http://www.cnblogs.com/yxj63/ 双方贡献比例:1:1 结对照片: 结对题目:输入一定个数的数字,对其排序后输出最大值.   1 pack ...

  3. 结对编程学习fault、error、failure三种状态

    点滴成就 学习时间 新编写代码行数 博客量(篇) 学习知识点 第一周 10小时 0 0 了解软件工程 第二周 10小时 0 1 项目开题 第三周 15小时 0 1 开通博客.开展项目调查 第四周 20 ...

  4. 结对编程之Fault、Error、Failure

    1.结对说明 结对对象:刘世麟  博客地址:http://www.cnblogs.com/liushilin/ 双方贡献:1:1 2.题目要求  构造程序,分别是:         •不能触发Faul ...

  5. 结对编程——关于Fault、Error、Failure程序设计

    一.问题描述:         构造程序,分别是:         •不能触发Fault         •触发Fault,但是不能触发Error         •触发Error,但是不能产生Fai ...

  6. 结对项目——fault,error,failure的程序设计

    一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周宗耀.周浩: 2.结对截图: 三.结对项 ...

  7. 软件测试中的fault,error,failure

    问题:给定两段代码,设计fault,error,failure的测试用例. fault:即引起错误的原因,类似病因. error:类似疾病引起的内部结果. failure:类似疾病引起的症状. 代码1 ...

  8. 【Software Test】Introduction to Software Testing

    Introduction to Software Testing 文章目录 Going to Learn --. Evolution of The Software Industry Errors, ...

  9. FW:Software Testing

    Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...

随机推荐

  1. Stack堆栈的数据结构

    1.

  2. CentOS 6.8 防火墙配置

    系统: CentOS release 6.8 (Final) iptables v1.4.7 执行命令: #清除所有规则 iptables -F #开放redis端口 iptables -A INPU ...

  3. vue2.0 在微信端如何使用本地IP访问项目

    我们会遇到这样的需求,在PC端开发vue脚手架项目,希望在微信端随时浏览页面(如果打包再发布到服务器又太麻烦),怎么办? 思路很简单:保证手机和电脑在同一个IP下,用同一个IP访问项目,这样就可以了: ...

  4. springBoot整合ftp上传图片功能

    知识点: springBoot后端项目,接收前端框架传到的图片,把图片上传到ftp图片服务器上 注意:在上传的过程中可能回出现,可以创建文件夹,但是图片上传不了的问题: 尝试了网上的很多方法,最后将f ...

  5. 学习Vue 入门到实战——学习笔记(二)

    闲聊: 哈哈哈!过了好几天才更新博客啦,嘻嘻,马上过年了,大家最近是不是都开心的快飞起来了,小颖好几个朋友公司都已经放假了,可是我们公司要等到腊月29上完班才给放假,哎!心情不美气的很,用我之前大学舍 ...

  6. yum安装mysql-5.6(centos7)

    centos 7.3 安装mysql 5.6 rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm yu ...

  7. CoAP 协议解析说明(转)

    CoAP 协议全面分析 HTTP与COAP 请求与响应示例 HTTP请求(文本格式) POST https://getman.cn/echo HTTP/1.1 User-Agent: Fiddler ...

  8. SQLite可视化工具SQLite studio

    特点: 1.轻量级2.独立性,没有依赖,无需安装3.隔离性 全部在一个文件夹系统4.跨平台 支持众多操作系统5.多语言接口 支持众多编程语言6.安全性 事物,通过独占性和共享锁来实现独立事务的处理,多 ...

  9. 网络流24T

    说出来你们可能不信,我咕了三个多星期了,今晚忽然不想再写题了,(写自闭了,把这边整理一下 1. 洛谷P2756 飞行员配对问题 二分图匹配: #include <bits/stdc++.h> ...

  10. 百度地图API密钥

    百度地图API密钥 DD279b2a90afdf0ae7a3796787a0742e nSxiPohfziUaCuONe4ViUP2N   /*亲测可用*/ PlhFWpA02aoURjAOpnWcR ...