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的更多相关文章

  1. 软件测试学习日志———— round 2 Junit+intellj idea 安装及简单的测试使用

    今天是软件测试的上机,主要内容是对junit的安装以及对一个简单类的测试实践.老师推荐用eclipse,但是我原来一直在 用intellj Idea,所以我试了试intellj Idea对junit的 ...

  2. 软件测试学习日志————round 0 An impressed error in my past projects

    在初学各种语言时总会出现各种错误,比如main携程mian.忘了加各种库,打错字等等等等.虽然这些错误后面看来很幼稚,但是有的时候真的会让人印象很深刻. 在初学JavaScript时,我对JavaSc ...

  3. GRE学习日志

    发现开博客园真的很有督促作用,今天也顺便开个GRE学习日志吧 2015-02-09:单词 2015-02-10:单词 2015-02-11:单词 2015-03-02:阅读 2015-03-04:阅读 ...

  4. Cortex-M3学习日志(六) -- ADC实验

    上一次简单的总结了一下DAC方面的知识,好吧,这次再来总结一下ADC方面的东东.ADC即Analog-to-Digital Converter的缩写,指模/数转换器或者模拟/数字转换器.现实世界是由模 ...

  5. Cortex-M3学习日志(五) -- DAC实验

    终于逮了个忙里偷闲的机会,就再学一下LPC1768的外围功能吧,循序渐进是学习的基本规则,也许LPC1768的DAC与8位单片机16位单片机里面集成的DAC操作类似,但是既然这是懒猫的学习日志,就顺便 ...

  6. webpack2学习日志

    webpack说容易也容易,说难也难,主要还是看个人,想学到什么样的程度,很多公司可能要求仅仅是会用就行,但是也有一些公司要求比较高,要懂一些底层的原理,所以还是要花一些时间的,看个人需求.这篇仅仅是 ...

  7. javascript学习日志:前言

    javascript学习日志系列的所有博客,主要理论依据是<javascript权威指南>(犀牛书第6版)以及<javascript高级程序设计第三版>(红色书),目前js行业 ...

  8. MobileForm控件的使用方式-用.NET(C#)开发APP的学习日志

    今天继续Smobiler开发APP的学习日志,这次是做一个title.toolbar.侧边栏三种效果 样式一 一.          Toolbar 1.       目标样式 我们要实现上图中的效果 ...

  9. 我的游戏学习日志3——三国志GBA

    我的游戏学习日志3——三国志GBA 三国志GBA由日本光荣公司1991~1995所推出<三国志>系列游戏,该作是光荣在GBA上推出的<三国志>系列作品的第一款.本游戏登场武将总 ...

随机推荐

  1. log4net简单用法

    一.NuGet在Server,mvc中添加Common.Logging和common.Logging.Log4Net如下图 二.在Server层创建logger类 <?xml version=& ...

  2. CentOS mini版安装后增加gcc编译环境

    使用如下命令即可: sudo yum install gcc gcc-c++ make -y

  3. Github 常用命令

    小记一些Github常用命令 : 在一个项目中... 假如要修补问题追踪系统上的 #53 问题.顺带说明下,Git 并不同任何特定的问题追踪系统打交道.这里为了说明要解决的问题,把新建的分支取名为 i ...

  4. 转:HTML 5 控件事件属性

    Window 事件属性 window 对象触发的事件. 适用于 <body> 标签: 属性 值 描述 onafterprint script 在打印文档之后运行脚本 onbeforepri ...

  5. 算法_php猴子选大王_约瑟夫问题

    题目: n个猴子围坐一圈,从第一个猴子开始数,到第m个出列,求最后一个猴子的编号. 分析: 首先想到循环,然后队列,然后堆,所以用数组模拟一个循环的列表,下标为[0-(n-1)],下标+1整除m干掉元 ...

  6. yii2 安装过程中的问题及解决方法

    一.php版本要求5.4+,如果使用wamp组合包,建议更换 二.各种模块的支持,一般只要修改php.ini文件,去掉相应模块前的注释即可. 注意,Intl extension模块的支持需要将     ...

  7. mysql性能优化学习笔记(6)数据库配置优化&硬件优化

    一.操作系统配置优化:          1. 网络方面,修改/etc/sysctl.conf文件,增加tcp支持的队列数,减少断开连接时,资源的回收.          2. 打开文件数的限制.修改 ...

  8. 关于ThinkPHP下使用Uploadify插件 仅有火狐提示HTTP Error (302)错误的解决办法

    'VAR_SESSION_ID' => 'session_id', //修复uploadify插件无法传递session_id的bug 首先在项目目录中的Common/Conf/config.p ...

  9. 根据群ID和用户Id查询 + string QueryQunByUserIdAndQunId(int userId, int qunId) V1.0

    #region  根据群ID和用户Id查询 + string QueryQunByUserIdAndQunId(int userId, int qunId)  V1.0 /// <summary ...

  10. FileProvider是个什么东西?

    FileProvider是个什么东西? 在<读取并监控文件的变化>中,我们通过三个简单的实例演示从编程的角度对文件系统做了初步的体验,接下来我们继续从设计的角度来继续认识它.这个抽象的文件 ...