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].

ST HW2 fault & error & failure的更多相关文章

  1. 软件测试中的fault,error,failure

    问题:给定两段代码,设计fault,error,failure的测试用例. fault:即引起错误的原因,类似病因. error:类似疾病引起的内部结果. failure:类似疾病引起的症状. 代码1 ...

  2. 结对编程2—Fault&Error&Failure

    学习进度表 点滴成就 学习时间 新编写代码行数 博客量(篇) 学到知识点 第一周 8 0 0 了解软件工程 第二周 10 0 1 博文一篇 第三周 15 0 2 选择项目.调查问卷 第四周 20 80 ...

  3. 结对编程--fault,error,failure的程序设计

    一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周浩,周宗耀 2.结对截图: 三.结对项目 ...

  4. 结对项目——fault,error,failure的程序设计

    一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周宗耀.周浩: 2.结对截图: 三.结对项 ...

  5. 软件测试作业 - fault error failure

    给出的题目如下: 我的解答如下: For program 1:1. where i > 0 is the fault , it should be changed to i>= 0 to ...

  6. NDK配置debug环境时:Error:FAILURE: Build failed with an exception

    Error:FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:ex ...

  7. Error: failure: repodata/repomd.xml from fedora: [Errno 256] No more mirrors to try.

    记录一个小问题,重新买的linux换yum源的时候一直提示: Error: failure: repodata/repomd.xml ] No more mirrors to try. 一直说那个XM ...

  8. [linux]Error: failure: repodata/repomd.xml from fedora: [Errno 256] No more mirrors to try.

    在使用fedora17 系统的yum源的时候出现了例如以下错误: Error: failure: repodata/repomd.xml from fedora: [Errno 256] No mor ...

  9. 安装zabbix-agent报错 Error: failure: repodata/primary.xml.gz from zabbix: [Errno 256] No more mirrors to try.

    安装zabbix-agent报错 yum install -y zabbix-agent Loaded plugins: fastestmirror, refresh-packagekit, secu ...

随机推荐

  1. Recurrent Neural Network系列2--利用Python,Theano实现RNN

    作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 本文翻译自 RECURRENT NEURAL NETWORKS T ...

  2. Weex系列一、构建Weex工程

    Weex比React Native更简单,更容易学习,并且做到真正的跨平台,一套代码可以多个平台运行.所以建议大家都用Weex吧. 一.安装Node 已经安装Node的,请忽略过去. 检查Node是否 ...

  3. java服务器获取客户端ip

    在写服务端代码时,有时需要对客户端ip做认证,比如限制只有某些ip能访问,或者1个ip1天只能访问几次.最近就碰到个需要限制ip的情况,从网上找了一些服务器获取客户端ip的方法,说的都不太完善,这里整 ...

  4. java基础概略总结

    /*************************************************/ String b=""; String c=""; // ...

  5. Go并发编程实践

    前言 并发编程一直是Golang区别与其他语言的很大优势,也是实际工作场景中经常遇到的.近日笔者在组内分享了我们常见的并发场景,及代码示例,以期望大家能在遇到相同场景下,能快速的想到解决方案,或者是拿 ...

  6. 蓝桥网试题 java 基础练习 矩形面积交

    ------------------------------------------------------------------------------------------- 思路见锦囊2 - ...

  7. python报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 0 解决方案

    环境:mac+python 2.7 场景描述:在使用python修改excel内容修改表格内容为中文保存时报以下错误 此时已经设置了utf-8了 但保存时仍然报错错 此时将python中的中文使用un ...

  8. Flash、Ajax各自的优缺点,在使用中如何取舍?

    1.Flash ajax对比 Flash适合处理多媒体.矢量图形.访问机器:对CSS.处理文本上不足,不容易被搜索. Ajax对CSS.文本支持很好,支持搜索:多媒体.矢量图形.机器访问不足. 共同点 ...

  9. Transport (VMDB) error -44: Message

     关于点击电源按钮的时候出现了这情况Transport (VMDB) error -44: Message.   虚拟机有个服务没开.开始菜单--运行--services.msc 回车   找到VMw ...

  10. 架设WIN32汇编程序的开发环境

    笔者在学习Windows下的图形界面应用程序(GUI,Graphical User Interface)的时候碰到的第一个麻烦就是架设WIN32汇编程序的开发环境,在这里笔者愿意和大家分享这段经历. ...