博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
软件测试基础(英文版)P16第三题
阅读量:5323 次
发布时间:2019-06-14

本文共 1391 字,大约阅读时间需要 4 分钟。

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

Identify the fault.
If possible, identify a test case that does not execute the fault. (Reachability)
If possible, identify a test case that executes the fault, but does not result in an error state.
If possible identify a test case that results in an error, but not a failure.

public intfindLast(int[] x, inty) {//Effects: If x==null throwNullPointerException// else return the index of the last element// in x that equals y.// If no such element exists, return -1for (inti=x.length-1; i> 0; i--){if (x[i] == y){return i;}}return -1;}// test: x=[2, 3, 5]; y = 2// Expected = 0

(a)Fault: i > 0, 导致x[0]无法被遍历,正确应该为i >= 0。

(b)Test: x = null; y = 2

(c)Test: x = [2,3,5]; y = 5.   Excepted = 2

(d)Test: x = [2,3,5]; y = 2.   Excepted = -1

public static intlastZero(int[] x) {//Effects: if x==null throwNullPointerException// else return the index of the LAST 0 in x.// Return -1 if 0 does not occur in xfor (inti= 0; i< x.length; i++){if (x[i] == 0){return i;}} return -1;}// test: x=[0, 1, 0]// Expected = 2

(a)Fault: 遍历顺序错误,正确结果应该为从后往前遍历,即 for(int i = x.length - 1; i >= 0; i --)

(b)Test: x = null

(c)Test: x = [2,1,0]   Excepted = 2

(d)Test: x = [0,1,0]   Excepted = 2, but result = 0

转载于:https://www.cnblogs.com/eric7/p/5274126.html

你可能感兴趣的文章
iOS如何过滤掉文本中特殊字符
查看>>
基础学习:C#中float的取值范围和精度
查看>>
javaagent 简介
查看>>
python升级安装后的yum的修复
查看>>
Vim配置Node.js开发工具
查看>>
web前端面试题2017
查看>>
ELMAH——可插拔错误日志工具
查看>>
MySQL学习笔记(四)
查看>>
【Crash Course Psychology】2. Research & Experimentation笔记
查看>>
两数和
查看>>
移动设备和SharePoint 2013 - 第3部分:推送通知
查看>>
SOPC Builder中SystemID
查看>>
MySQL数据库备份工具mysqldump的使用(转)
查看>>
NTP服务器配置
查看>>
关于 linux 的 limit 的设置
查看>>
HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)
查看>>
vim中文帮助教程
查看>>
MySQL基础3
查看>>
RxJS & Angular
查看>>
面向对象(多异常的声明与处理)
查看>>