Software Testing 2 —— Fault、error and failure小练习
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小练习的更多相关文章
- ST HW2 fault & error & failure
Software Testing 3014218128 牛菲菲 Below are two faulty programs. Each includes a test case that result ...
- 结对编程--fault,error,failure
结对编程对象:叶小娟 对方博客地址:http://www.cnblogs.com/yxj63/ 双方贡献比例:1:1 结对照片: 结对题目:输入一定个数的数字,对其排序后输出最大值. 1 pack ...
- 结对编程学习fault、error、failure三种状态
点滴成就 学习时间 新编写代码行数 博客量(篇) 学习知识点 第一周 10小时 0 0 了解软件工程 第二周 10小时 0 1 项目开题 第三周 15小时 0 1 开通博客.开展项目调查 第四周 20 ...
- 结对编程之Fault、Error、Failure
1.结对说明 结对对象:刘世麟 博客地址:http://www.cnblogs.com/liushilin/ 双方贡献:1:1 2.题目要求 构造程序,分别是: •不能触发Faul ...
- 结对编程——关于Fault、Error、Failure程序设计
一.问题描述: 构造程序,分别是: •不能触发Fault •触发Fault,但是不能触发Error •触发Error,但是不能产生Fai ...
- 结对项目——fault,error,failure的程序设计
一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周宗耀.周浩: 2.结对截图: 三.结对项 ...
- 软件测试中的fault,error,failure
问题:给定两段代码,设计fault,error,failure的测试用例. fault:即引起错误的原因,类似病因. error:类似疾病引起的内部结果. failure:类似疾病引起的症状. 代码1 ...
- 【Software Test】Introduction to Software Testing
Introduction to Software Testing 文章目录 Going to Learn --. Evolution of The Software Industry Errors, ...
- FW:Software Testing
Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...
随机推荐
- halcon之 distance_transform
Compute the distance transformation of a region 该算子的作用是计算对region转换距离.该算子的形式为distance_transform(Reg ...
- python 解除装饰器,调用原本函数。
假设fun函数被装饰器装饰了,name调用fun,就不是调用fun本身了,那么如何继续调用本身呢.使用fun_raw = fun.__wrapped__这样使用fun_raw就是调用没被装饰器修饰后的 ...
- git使用git-credential-winstore保存https访问密码
使用 https 方式 clone 一个 git 仓库,每次pull 或者 push 的时候都需要输入用户名和密码. 访问远程Git仓库可以用 SSH 方式和 https 方式,https 每次访问时 ...
- win10下VS2017配置GSL库
GSL库:GNU Scientific Library 1. 下载:下载Complete package, except sources和Sources两个exe文件 2. 安装:将两个exe安装 ...
- [ICPC 北京 2017 J题]HihoCoder 1636 Pangu and Stones
#1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...
- 谢大神给的C++和C# DES加解密代码
// CPPdesTest.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"//#include <windows.h>//#inc ...
- 【CF660E】Different Subsets For All Tuples 结论题
[CF660E]Different Subsets For All Tuples 题意:对于所有长度为n,每个数为1,2...m的序列,求出每个序列的本质不同的子序列的数目之和.(多个原序列可以有相同 ...
- python爬虫工具
一直都听说python写爬虫工具非常方便,为了获取数据,我也要写点爬虫,但是python太灵活了,不知道python爬虫要哪些框架,要了解,比如beatiful soup,scrapy, 爬虫的额主要 ...
- 11.12git部分和redis
2018-11-12 09:54:58 这星期把luffycity看完,然后周末回学校 越努力,越幸运!永远不要高估自己! 具体可以参考 戳我啊!! 一些git常用命令: 目前已使用Git的四个命令 ...
- 查看集成环境 phpstudy 中 mysql 版本号
1. 打开面板 2.其他选项菜单 3. Mysql工具 4. mysql命令行 5.输入密码,回车.phpstudy mysql默认 root 6.运行 select version();