Software Testing

3014218128 牛菲菲

Below are two faulty programs. Each includes a test case that results in failure.Answer the following questions (in the next slide) about each program.

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-1; i > 0; i--)
{
if (x[i] == y)
{
return i;
}
}
return -1;
}
// test: x=[2, 3, 5]; y = 2
// Expected = 0

answer:

1) Identify the fault.

Fault: for (int i=x.length-1; i > 0; i--)

i should end with 0, but not with 1. The right should be" i>=0 "

Error: i is 1, not 0, on the last iteration
Failure: return the wrong result -1
2) If possible, identify a test case that does not execute the fault. (Reachability)

test: x = NULL, y=2

In this case, the fault isn't executed.

3) If possible, identify a test case that executes the fault, but does not result in an error state.

test: x=[3, 5, 2]; y=2

expected = 2, result is 2

In this case, it 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.

test: x=[3, 5, 2]; y=1

expected = -1, result is -1

In this case, it results in an error but not a failure.

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 = 0; i < x.length; i++)
{
  if (x[i] == 0)
  {
    return i;
  }
}

  return -1;
}
// test: x=[0, 1, 0]
// Expected = 2

answer:

1) Identify the fault.

Fault: for (int i = 0; i < x.length; i++)

  It will return on the first iteration while it should continue iteration.

Failure: expected =2, result = 0
2) If possible, identify a test case that does not execute the
fault. (Reachability)

x=NULL

3) If possible, identify a test case that executes the fault, but
does not result in an error state.

test: x=[1, 2, 3]

4) If possible identify a test case that results in an error, but
not a failure.

test: x=[1, 0, 2].

最新文章

  1. 【CoreData】分页查询和模糊查询
  2. 如何使用TestFlight进行Beta测试
  3. 好玩儿的expect
  4. JS,CSS,HTML制作网页首页,视频轮播,隐藏点击等等。
  5. Codeforces Round #373 (Div. 2)A B
  6. Jquery图片轮播和CSS图片轮播
  7. javascript中,你真的会用console吗?
  8. 【strtok()】——分割字符串
  9. 分享学习——ERP项目管理经验
  10. Yii2之行为
  11. C Primer Plus 第8章 字符输入/输出和验证输入 编程练习
  12. webp图片技术调研最终结论(完全真实数据可自行分析)
  13. 在Asp.Net Core中使用DI的方式使用Hangfire构建后台执行脚本
  14. 换目标啦,初识PHP
  15. NetSec2019 20165327 Exp3 免杀原理与实践
  16. dos5章
  17. Butterknife--Android Butterknife使用方法总结(转)
  18. 开源邮件系统Zimbra Collaboration – Open Source Edition
  19. macaca使用中问题解决方法整理
  20. CodeForces Contest #1137: Round #545 (Div. 1)

热门文章

  1. 安装使用GYP,并编译libpomelo2
  2. 第一篇:CUDA 6.0 安装及配置( WIN7 64位 / 英伟达G卡 / VS2010 )
  3. jquery常用的一些方法
  4. &lt;C++Primer&gt;第四版 阅读笔记 第一部分 “基本语言”
  5. 解决maven 下载 hadoop-client 客户端 报错的问题
  6. 【译】JavaScript Promise API
  7. SQL Server-聚焦事务对本地变量、临时表、表变量影响以及日志文件存满时如何收缩(三十一)
  8. SwingBench---ORACLE压力测试工具
  9. oracle 11G RAC会话故障转移测试
  10. jQuery 监听元素内容变化的方法