Questions:

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

Program One:

 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、错误代码:

for(int i = x.length-; i > ; i--)

原因:应共遍历x.length次,且数组下标从零开始。

改正为:

for(int i = x.length-; i >= ; i--)

2、A test case: x = [] ——> If x == null throw NullPointerException,不会执行fault。

3、A test case: x = [2, 3, 5]; y = 3 ——> The result is 1,执行了fault,且结果正确。

4、A test case: x = [2, 3, 5]; y = 4 ——> The result is -1,是error,不是failure。


Program Two:

 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、错误代码:

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

原因:返回的应该是最后一个零的位置,上述代码返回的是第一个零的位置,且数组下标从零开始。

改正为:

for (int i = x.length-; i >= ; i--)

2、A test case: x = [] ——> If x == null throw NullPointerException,不会执行fault。

3、A test case: x = [1, 0, 1] ——> The result is 1,执行了fault,且结果正确。

4、A test case: x = [2, 3, 5] ——> The result is -1,是error,不是failure。

Software Testing 2 —— Fault、error and failure小练习的更多相关文章

  1. ST HW2 fault & error & failure

    Software Testing 3014218128 牛菲菲 Below are two faulty programs. Each includes a test case that result ...

  2. 结对编程--fault,error,failure

    结对编程对象:叶小娟 对方博客地址:http://www.cnblogs.com/yxj63/ 双方贡献比例:1:1 结对照片: 结对题目:输入一定个数的数字,对其排序后输出最大值.   1 pack ...

  3. 结对编程学习fault、error、failure三种状态

    点滴成就 学习时间 新编写代码行数 博客量(篇) 学习知识点 第一周 10小时 0 0 了解软件工程 第二周 10小时 0 1 项目开题 第三周 15小时 0 1 开通博客.开展项目调查 第四周 20 ...

  4. 结对编程之Fault、Error、Failure

    1.结对说明 结对对象:刘世麟  博客地址:http://www.cnblogs.com/liushilin/ 双方贡献:1:1 2.题目要求  构造程序,分别是:         •不能触发Faul ...

  5. 结对编程——关于Fault、Error、Failure程序设计

    一.问题描述:         构造程序,分别是:         •不能触发Fault         •触发Fault,但是不能触发Error         •触发Error,但是不能产生Fai ...

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

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

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

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

  8. 【Software Test】Introduction to Software Testing

    Introduction to Software Testing 文章目录 Going to Learn --. Evolution of The Software Industry Errors, ...

  9. FW:Software Testing

    Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...

随机推荐

  1. Java多线程:CountDownLatch、CyclicBarrier 和 Semaphore

    场景描述: 多线程设计过程中,经常会遇到需要等待其它线程结束以后再做其他事情的情况. 有几种方案:   1.在主线程中设置一自定义全局计数标志,在工作线程完成时,计数减1.主线程侦测该标志是否为0,一 ...

  2. could not resolve property: leader_id of: pojo.Project

    https://www.cnblogs.com/zhaocundang/p/9211270.html hibernate 双向1对多 出现问题 外键解析错误! log4j:WARN No append ...

  3. CentOS安装和配置Apache(httpd)

    1. 安装httpd yum install httpd #安装apache 2. 启动httpd systemctl start httpd.service #启动apache 3. 随服务器自启动 ...

  4. Mixed Content: xxx This request has been blocked; the content must be served over HTTPS.

    在升级https的过程中,出现如下问题: Mixed Content: The page at 'https://www.xxx.com/denglu.html' was loaded over HT ...

  5. HTTP Headers 信息

    点开一个条目,可以查看请求的详细信息: General —— 通用信息 Request URL:请求的URL     Request Method:请求的方法     Status Code:响应状态 ...

  6. login流程

    DirServer增加,修改-后台网页操作 维护所有分区的当前信息创建,修改,上报分区信息分区:状态,版本号,注册量等 一.loginserver定时从dir同步所有区服的信息 登陆相关 1.CmdI ...

  7. Qt编写自定义控件9-导航按钮控件

    前言 导航按钮控件,主要用于各种漂亮精美的导航条,我们经常在web中看到导航条都非常精美,都是html+css+js实现的,还自带动画过度效果,Qt提供的qss其实也是无敌的,支持基本上所有的CSS2 ...

  8. 转载:margin外边距合并问题以及解决方式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 六种常见排序算法的java实现

    package edu.cn.ysw; //八种排序算法的实现与效率分析 /* * 内排序的种类: * 1.插入排序:直接插入排序.希尔排序. * 2.选择排序:简单选择排序.堆排序. 3.交换排序: ...

  10. 13.vue组件

    vue组件(一) 组件嵌套: 1.全局嵌套: <!doctype html> <html> <head> <meta charset="utf-8& ...