软件测试学习日志————round 1 some questions of two small programs
Below are four faulty programs. Each includes a test case that results in failure.
Answer the following questions (in the next slide) about each program.
questions:
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.
programs:
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-; i > ; i--) {
if (x[i] == y) { return i; }
}
return -;
}
// test: x=[2, 3, 5]; y = 2
// Expected = 0
answers:
1. The variable i should bigger than 0 or equals 0.
In this program i>0 is not right. It cannt get x[0].
2. test: x=[]; y=2
3. test: x=[3,1,5]; y=2
4. test: x=[2,3,5]; y=2
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 = ; i < x.length; i++) {
if (x[i] == ) { return i; }
}
return -;
}
// test: x=[0, 1, 0]
// Expected = 2
answers:
1. The variable i should from x.length-1 to 0.
This program is scanning a wrong order which is from 0 to x.length-1. It's wrong.
This program means that once there is a 0 from the beginning of x, it will return
the position of i.
2. test: x=[];
3. test: x=[1,2,0]
4. test: x=[0,1,0]
after the question: This is an exercise to remind us of the RIP rules, which are Reachability, Infection and Propagation.
It's important to software testing.
软件测试学习日志————round 1 some questions of two small programs的更多相关文章
- 软件测试学习日志———— round 2 Junit+intellj idea 安装及简单的测试使用
今天是软件测试的上机,主要内容是对junit的安装以及对一个简单类的测试实践.老师推荐用eclipse,但是我原来一直在 用intellj Idea,所以我试了试intellj Idea对junit的 ...
- 软件测试学习日志————round 0 An impressed error in my past projects
在初学各种语言时总会出现各种错误,比如main携程mian.忘了加各种库,打错字等等等等.虽然这些错误后面看来很幼稚,但是有的时候真的会让人印象很深刻. 在初学JavaScript时,我对JavaSc ...
- GRE学习日志
发现开博客园真的很有督促作用,今天也顺便开个GRE学习日志吧 2015-02-09:单词 2015-02-10:单词 2015-02-11:单词 2015-03-02:阅读 2015-03-04:阅读 ...
- Cortex-M3学习日志(六) -- ADC实验
上一次简单的总结了一下DAC方面的知识,好吧,这次再来总结一下ADC方面的东东.ADC即Analog-to-Digital Converter的缩写,指模/数转换器或者模拟/数字转换器.现实世界是由模 ...
- Cortex-M3学习日志(五) -- DAC实验
终于逮了个忙里偷闲的机会,就再学一下LPC1768的外围功能吧,循序渐进是学习的基本规则,也许LPC1768的DAC与8位单片机16位单片机里面集成的DAC操作类似,但是既然这是懒猫的学习日志,就顺便 ...
- webpack2学习日志
webpack说容易也容易,说难也难,主要还是看个人,想学到什么样的程度,很多公司可能要求仅仅是会用就行,但是也有一些公司要求比较高,要懂一些底层的原理,所以还是要花一些时间的,看个人需求.这篇仅仅是 ...
- javascript学习日志:前言
javascript学习日志系列的所有博客,主要理论依据是<javascript权威指南>(犀牛书第6版)以及<javascript高级程序设计第三版>(红色书),目前js行业 ...
- MobileForm控件的使用方式-用.NET(C#)开发APP的学习日志
今天继续Smobiler开发APP的学习日志,这次是做一个title.toolbar.侧边栏三种效果 样式一 一. Toolbar 1. 目标样式 我们要实现上图中的效果 ...
- 我的游戏学习日志3——三国志GBA
我的游戏学习日志3——三国志GBA 三国志GBA由日本光荣公司1991~1995所推出<三国志>系列游戏,该作是光荣在GBA上推出的<三国志>系列作品的第一款.本游戏登场武将总 ...
随机推荐
- asp.net生成缩略图、文字图片水印
/// <summary> /// 会产生graphics异常的PixelFormat /// </summary> private static PixelFormat[] ...
- node学习第一篇
创建一个http服务器 //app.js var http = require("http"); function start(req, res){ //res.writeHead ...
- Java的常见误区与细节
网上转来的 昨天整整一天,我都都呆在图书里.本打算找一些书学习“正则表达式”,很失望,没找到有这部分的内容的书.发现了一本<Java深入解析>,其中涉及了很多平时没有注意的一些误区,也许开 ...
- mysql 建立索引的原则
建索引的几大原则 1. 最左前缀匹配原则,非常重要的原则,mysql会一直向右匹配直到遇到范围查询(>.<.between.like)就停止匹配,比如a 1="" an ...
- Spring XML 不给提示
a)window – preferences – myeclipse – xml – xml catalog b)User Specified Entries – add i. Location: D ...
- Python之路第三天,基础(3)-set,函数,内置函数,文件,三元运算,lambda
set集合 集合是一个无序的,不重复的元素集合. 集合的创建: name_set = {'tom','jerry','alex','rose'} 或 name_set = set(['tom','je ...
- jQuery学习-事件之绑定事件(三)
在上一篇<jQuery学习-事件之绑定事件(二)>我们了解了jQuery的dispatch方法,今天我们来学习下handlers 方法: handlers: function( event ...
- ASP.NET 网站在域环境内配置授权访问
在 IIS 中,通常需要配置域中的某些用户或者用户组有权限访问部署的 WEB 站点或者 WEB 服务.我们知道要实现这种功能可以有如下几种方式: 代码,获取当前用户,到域服务器上去验证当前用户是否为合 ...
- EditPlus3.3 集成 SVN
今天在玩EditPlus的时候,由于自己想上传文件至SVN,本机已经安装了TSVN,听说近期EditPlus支持了SVN操作,于是自己便带着好奇的心试试了. 已有的环境: EditPlus 3 ...
- HCE:Host-based Card Emulation基于Android设备的卡片模拟器
HCE技术支持提供了一个软实现SE的通路,Service实现的方式很多,可以使用文件,使用网络,甚至连接真正的SE.支持HCE的测试手机:目前可以确定使用了NXP PN547作为CLF的NFC手机已经 ...