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. JavaScript input type=file 获取文件大小及类型限制

    <input name="txtName" type="file" id="pic" onchange="loadImage ...

  2. UILabel头文件常见属性

    text : default is nil 文本属性,默认值是 nil @property(nullable, nonatomic,copy) NSString *text; font : defau ...

  3. java中关于窗体居中显示问题

    最近在学着用java写qq聊天程序,首先是登录和聊天界面,书上没有给出居中显示,通过上网查找知道有两种方案 先说第一种方法,也是以前用的方法 /获得屏幕大小Dimension screenSize = ...

  4. oracle distinct 去除重复,同时按某字段排序

    SELECT distinct supplier_id, min(evidence_date) as evidence_date FROM TD_SUPPLIER_EVIDENCE_INFO wher ...

  5. jQuery实现逐字输入效果

    之前做了个测试小游戏(姑且叫游戏吧)为了增加神秘性,就想给她加个逐字输入效果:刚好在网上找到一个挺好用的,于是就发扬拿来主义:按照自己的喜好做了一丢丢的修改(勉强算是吧\( ̄︶ ̄)> ). 代码 ...

  6. JVM(Java虚拟机)优化大全和案例实战

    堆内存设置 原理 JVM堆内存分为2块:Permanent Space 和 Heap Space. Permanent 即 持久代(Permanent Generation),主要存放的是Java类定 ...

  7. Qt开发初步,循序渐进,preRequest for 蓝图逆袭

    1,使用Qt面向对象类继承创建第一个窗口主部件,使用setMinimumSize(),setMaximumSize()配置主部件窗口是否能够resize;

  8. oracle动态游标

    declare   v_col1 varchar2(254);   v_col2 varchar2(254);   v_sql  varchar2(1024);   type my_cursor is ...

  9. Mongodb 权限管理

  10. Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的适用版本

    Jet   可以访问 Office 97-2003,但不能访问 Office 2007. ACE 既可以访问 Office 2007,也可以访问 Office 97-2003. 另外:Microsof ...