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. Oracle 物理DG切换

    在进行DATA GUARD的物理STANDBY切换前需要注意:确认主库和从库间网络连接通畅:确认没有活动的会话连接在数据库中:PRIMARY数据库处于打开的状态,STANDBY数据库处于MOUNT状态 ...

  2. JAVA 8 新特性和改进

    Java 8的所有新特性及改进包括(JEP全称为JDK Enhancement Proposal,JDK改进建议): 语言改进: JEP 126:Lambda表达式 & 虚拟扩展方法 JEP ...

  3. mysql 查询表的行数和空间使用及其它信息

    use information_schema; select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB') as data from TABLE ...

  4. sql update小结

    以前update用的不少,但都是简单的单表操作,没有在意,最近查阅多表关联更新及更新top n,发现update还真灵活,记录如下(在mssqlserver2008r2下测试通过): 1单表操作  u ...

  5. Jsoup小Demo

    Jsoup小Demo public class JsoupUtil { public void parseWangYi() { Document doc = null; try { //eg1:解析百 ...

  6. Python简明教程---学习笔记

    字符双引号括起,数字不括: 分隔符为逗号(,),不能为空格 变量定义时即赋值 采用utf-8编码:#-*-coding:utf-8-*-或者#coding:utf-8 字符串定义:单/双引号括起 %符 ...

  7. Android设置全屏

    全屏显示 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLA ...

  8. ODI Studio拓扑结构的创建与配置(Oracle)

    一.概念解释 Topology Manager主要用来管理下面5类任务,并将信息存储在主资料库中,供所有模块共享使用. 物理体系结构: 定义各种技术及其数据服务器.物理架构.物理代理.数据服务器瞎可以 ...

  9. [Django] Windows 下安装 配置Pinax 工程

    Pinax 是一个基于Django开发的脚手架,有一些现成的模板和功能模块可以使用,方便快速有效的开发一个Django项目.下面举个例子如何安装一个pinax项目到集成开发环境Aptana里面. 先从 ...

  10. Oracle 导出HTML

    http://www.linuxidc.com/Linux/2010-10/29133.htm Oracle 执行计划: http://czmmiao.iteye.com/blog/1471756 h ...