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. C# MVC分页,razor,view传送model

    IMVCPages interface IMVCPages { int GetItemsCount(); int GetPageSize(); int GetPagesCount(); /// < ...

  2. 点击TextView浏览器打开指定网页

    直接上代码: /** * 点击跳转到版权页面 */ private void getCopyRight() { // TODO Auto-generated method stub TextView ...

  3. android stuido 快捷键

    Alt+回车 导入包,自动修正 Ctrl+N   查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L  格式化代码 Ctrl+Alt+O 优化导入的类和包 Alt+Insert 生成代码 ...

  4. mysql错误号码:1129

    mysql 错误号码1129: mysql error 1129: Host 'bio.chip.org' is blocked because of many connection errors; ...

  5. Foundation 框架

    1.框架是有许多类,函数,方法,文档按照一定的逻辑组织起来的集合 2. Foundation框架是所有框架的基础 3.术语cocoa指的是foundation框架和appication kit框架 4 ...

  6. C语言中两个相等的char值比较 结果为false

    unsigned char appendChar1[] = {0xD3, 0xD0, 0xCF, 0xDE, 0xB9, 0xAB, 0xCB, 0xBE}; char appendChar2[] = ...

  7. DataGridview 填写数字

    private DataGridViewTextBoxEditingControl CellEdit = null; // 声明 一个 CellEdit        private void dgv ...

  8. PHP 源码加密扩展(php-beast)PHP7 版本发布

    此版本主要支持PHP7,在github(https://github.com/liexusong/php-beast)上选择php7分支然后编译安装即可.   来源于:https://github.c ...

  9. css 问题总结

    background: <color> <image> <position> <attachment> <repeat>本文来自:佳木中国( ...

  10. 提高mindmanager 8的启动速度

    提高mindmanager 8的启动速度一连串 发布于:2010-01-13 18:12不少人抱怨mindmanager 8的启动速度较慢,用以下办法配置一下就能解决:1.进入mindmanager ...