博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第二次作业
阅读量:4676 次
发布时间:2019-06-09

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

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 -------------------------------------------------------------------------- 1. Identify the fault. for循环中的判断条件应该为:for (int i=x.length-1; i >= 0; i--) 2. If possible, identify a test case that does not execute the fault. (Reachability) text:x=[]; 测试结果:抛出空指针异常,没有执行下面的程序,没有执行fault 3.If possible, identify a test case that executes the fault, but does not result in an error state. text:x=[3,2,1] expected=1 测试结果:执行了含有fault的程序,但是并没有产生错误,即执行了fault,没有执行error 4.If possible identify a test case that results in an error, but not a failure. test: x=[3, 2, 5]; y = 1 expected = -1 测试结果:没有遍历x=1,直接返回了-1,因此执行了error,没有执行failure -------------------------------------------------------------------------- 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 --------------------------------------------------------------------------------------- 1.Identify the fault. for循环中的判断条件应该为:for(int i=x.length-1; i > =0; i–-); 2.If possible, identify a test case that does not execute the fault. (Reachability) test: x=[]; 测试结果:抛出空指针异常,没有执行下面的程序,则没有执行fault 3.If possible, identify a test case that executes the fault, but does not result in an error state. test: x=[1, 2, 0] Expected = 2 测试结果:执行了含有fault的程序,但是并没有产生错误,即执行了fault,没有执行error 4.If possible identify a test case that results in an error, but not a failure. test: x=[3, 2, 5]; Expected = -1 测试结果:遍历到i=3时,返回了-1,不符合设计目的,因此执行了error,没有执行failure

转载于:https://www.cnblogs.com/leimingmwj/p/8577063.html

你可能感兴趣的文章
powershell 查看程序的tcp网络连接
查看>>
C++技术问题总结-第12篇 设计模式原则
查看>>
Spring的事件处理
查看>>
利用Android属性动画实现Banner的原理与实践
查看>>
【MySQL案件】mysql登录-S失败
查看>>
白话经典算法系列之中的一个 冒泡排序的三种实现
查看>>
Eclipse断点调试
查看>>
ubuntu 步步为营之uclinux编译和移植(完整版)
查看>>
取消SVN版本号控制的bash脚本
查看>>
ASP.NET 后台接收前台POST过来的json数据方法
查看>>
Python(简单图形和文件处理)编程
查看>>
C#写点酷玩意,波形图控件
查看>>
MS SQL 批量操作
查看>>
CSRF
查看>>
mysql中创建用户和赋权限
查看>>
(Hive)史上最难解析的json字符串解析出来了!!
查看>>
Linux学习之一--VI编辑器的基本使用
查看>>
Activity启动模式 及 Intent Flags 与 栈 的关联分析
查看>>
iOS5可能会删除本地文件储存
查看>>
周四总结
查看>>