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:

  1. public int findLast (int[] x, int y) {
  2. // Effects: If x==null throw NullPointerException
  3. // else return the index of the last element
  4. // in x that equals y.
  5. // If no such element exists, return -1
  6. for (int i = x.length-; i > ; i--)
  7. {
  8. if (x[i] == y) {
  9. return i;
  10. }
  11. }
  12. return -;
  13. }
  14. // test: x=[2, 3, 5]; y = 2
  15. // Expected = 0

Answers:

1、错误代码:

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

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

改正为:

  1. 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:

  1. public static int lastZero (int[] x) {
  2. // Effects: if x==null throw NullPointerException
  3. // else return the index of the LAST 0 in x.
  4. // Return -1 if 0 does not occur in x
  5. for (int i = ; i < x.length; i++)
  6. {
  7. if (x[i] == ) {
  8. return i;
  9. }
  10. }
  11. return -;
  12. }
  13. // test: x=[0, 1, 0]
  14. // Expected = 2

Answers:

1、错误代码:

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

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

改正为:

  1. 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. golang处理signal

    signal一般用来实现优雅重启,或者重新加载配置文件等操作. 废话不多说,上表格 动作 号码 信号 golang kill pid 15 SIGTERM terminated kill -9 pid ...

  2. JSP之连接SQL Server

    1.在SQL Server中启用sa(请参考本人博客:http://www.cnblogs.com/zhouhb/archive/2011/02/15/1955324.html)2.在SQL Serv ...

  3. gsoap使用总结

    WebService.soap.gsoap基本概念 WebService服务基本概念:就是一个应用程序,它向外界暴露出一个可以通过web进行调用的API,是分布式的服务组件.本质上就是要以标准的形式实 ...

  4. netty 的 JBoss Marshalling 编码解码

    一. JBoss Marshalling 简介. JBoss Marshalling 是一个Java 对象序列化包,对 JDK 默认的序列化框架进行了优化,但又保持跟 Java.io.Serializ ...

  5. Eclipse Maven profiles 多环境配置,测试环境与开发环境分开打包

    1.将开发环境.测试环境.生产环境的配置文件分开存放,如下图: 2.在Maven中配置不同的环境打包配置文件的路径,配置如下: <profiles> <profile> < ...

  6. Elasticsearch学习笔记——分词

    1.测试Elasticsearch的分词 Elasticsearch有多种分词器(参考:https://www.jianshu.com/p/d57935ba514b) Set the shape to ...

  7. tensorflow finuetuning 例子

    最近研究了下如何使用tensorflow进行finetuning,相比于caffe,tensorflow的finetuning麻烦一些,记录如下: 1.原理 finetuning原理很简单,利用一个在 ...

  8. MySQL命令学习

    上面两篇博客讲了MySQL的安装.登录,密码重置,为接下来的MySQL命令学习做好了准备,现在开启MySQL命令学习之旅吧. 首先打开CMD,输入命令:mysql -u root -p  登录MySQ ...

  9. 134、直接拿来用,Android界最火的开源项目

    Android酷炫开源动框架2015-2016双年榜(转载) http://blog.csdn.net/u011200604/article/details/54428128 GitHub上受欢迎的A ...

  10. jenkins之 Throttle Concurrent Builds使用

    Jenkins控制并发插件 Throttle Concurrent Builds介绍,管网见:https://github.com/jenkinsci/throttle-concurrent-buil ...