软件测试作业二

(1)findLast

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

(a)  Identify the fault:

for (int i=x.length-1; i > 0; i--)  ,"i>0" should be "i>=0",otherwise, the 0 index can not be included

(b)If possible, identify a test case that does not execute the fault. (Reachability)

test: x=null;y=1;

expected=null;

fact = null;

(c)If possible, identify a test case that executes the fault, but does not result in an error state.

test:x=[3,2,5];y=2

expected=1;

fact = 1;

(d)If possible identify a test case that results in an error, but not a failure.

test:x=[3,2,5] ; y=6

expected = -1;

fact = -1;

(2)lastZero

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

(a)  Identify the fault:

for (int i = 0; i < x.length; i++), order should be from high to low ,should be "for (int i=x.length-1; i > 0; i--) "

(b)If possible, identify a test case that does not execute the fault. (Reachability)

no possible

(c)If possible, identify a test case that executes the fault, but does not result in an error state.

test:x=[1]

expected=-1;

fact = -1;

(d)If possible identify a test case that results in an error, but not a failure. 

test:x=[1,0,1]

expected = 1;

fact = 1;

tips:

Software Fault : A static defect in the software (软件中的设计错误,就是代码本身就写错了)

Software Failure : External, incorrect behavior with respect to the requirements or other description of the expected behavior (失效,与预期不一样,表现出来的)

Software Error : An incorrect internal state that is the manifestation of some fault (在运行过程中的)

fault -> error -> failure,软件中的缺陷在运行时会产生error,当error累计到一定程度时会导致失效,这些都是bug

时间: 2024-08-11 08:50:36

软件测试作业二的相关文章

软件测试作业二——找出程序中的错误

一.软件程序中的错误 软件程序中的错误有三种:faults(故障), errors(错误), failures(失败). 软件故障(faults):软件中的静态缺陷. 软件错误(errors):不正确的内部状态,该状态是某个故障的表现. 软件失败(failures):与需求或其他期望行为的描述有关的,外部的,不正确的行为. 二.分析下列程序 程序一: public int findLast (int[] x,int y){ //Effects:If x==null throw NullPoint

day1作业二:多级菜单

    作业二:多级菜单 1.三级菜单 2.可以次选择进入各子菜单 3.所需新知识点:列表.字典 4.打印b回到上一层 5.打印q退出循环 流程图如下: readme: (1)存储三级菜单的字典;设置标识符active用来循环: (2)生成存储省市的字典,d1 = {1: '河南', 2: '广东', 3: '湖南'}; (3)用户输入查询编码,如果用户输入q退出循环:如果用户输入小于1或大于3则重新输入:输入编码在range(1,4)中,则输出省,并继续循环; (4)生成存储市的字典d2 =

day1作业二:多级菜单操作(函数实现)

作业二:多级菜单 (1)三级菜单 (2)可以次选择进入各子菜单 (3)所需新知识点:列表.字典 要求:输入back返回上一层,输入quit退出整个程序 本示例的三级菜单是一个yaml文件格式,格式如下: 香港: 香港 澳门: 澳门 台湾: 台湾 钓鱼岛: 钓鱼岛 北京市: - 市辖区 - 东城区 - 西城区 - 崇文区 - 宣武区 - 朝阳区 河北省: - 石家庄市: - 长安区 - 桥东区 - 桥西区 - 新华区 - 唐山市: - 路南区 - 路北区 - 古冶区 - 开平区 - 秦皇岛市: -

机器学习 1 linear regression 作业(二)

机器学习 1 linear regression 作业(二) 这个线性回归的作业需要上传到https://inclass.kaggle.com/c/ml2016-pm2-5-prediction 上面,这是一个kaggle比赛的网站.第一次接触听说这个东西,恰好在京东上有一本刚出来的关于这个的书<Python机器学习及实践:从零开始通往Kaggle竞赛之路>.把我自己写的代码运行保存的结果提交上去后发现,损失函数值很大,baseline是6,而我的却是8,于是很不心甘,尝试了其他方法无果后,准

第二次作业: 二维数组

高级语言程序设计报告   实习题目 第二次作业: 二维数组 P228计算机双学位第8章实验题:学生成绩管理系统 l 在上次作业的基础上,改为每学生2门课,用二维数组编程实现相应功能,相应功能所有涉及分数的均需可以处理每门课程分数及每个学生课程总分. l 涉及到排序的,均需提供冒泡及选择两种排序方法,可增加菜单项. l 功能5中按学号查询学生排名及成绩,要求用折半法,为此你的学生数据可以多一点. l 数组中可以事先有数据(省却每次输入数据浪费时间),为此输入数据菜单可以改造为增加数据菜单. l 在

家庭作业二

家庭作业二(Chapter 3) P206 3.60 考虑下面的源代码,这里R,S,T都是用#define声明的常数 int A[R][S][T]; int store_ele(int i,int j,int k,int *dest) { *dest=A[i][j][k]; return sizeof(A); } 编译这个程序,GCC产生下面的汇编代码:(i at %ebp+8,j at %ebp+12,k at %ebp+16,dest at %ebp+20) movl 8(%ebp),%ec

機器學習基石(Machine Learning Foundations) 机器学习基石 作业二 课后习题解答

大家好,我是Mac Jiang,首先祝贺大家清明节快乐!作为一名苦逼的程序员,博主只能窝在实验室玩玩游戏,顺便趁着大早上没人发一篇微博.不过还是祝各位出行的兄弟玩的开心! 今天和大家分享coursera-NTU-機器學習基石(Machine Learning Foundations)-作业二的习题解答.笔者在做这些题目时遇到很多困难,当我在网上寻找答案时却找不到,而林老师又不提供答案,所以我就想把自己做题时对题目如何思考的写下来,为大家提供一些思路.当然,我对题目的理解不一定是正确的,如果各位博

【作业二】林轩田机器学习基石

作业一被bubuko抓取了,要是能注明转载就更好了() 作业二关注的题目是需要coding的Q16~Q20 Q16理解了一段时间,题目阐述的不够详细.理解了题意之后,发现其实很简单. 理解问题的关键是题目中给的's'是啥意思: (1)如果s=1,则意味着x>theta y预测为1,x<theta y预测为-1: (2)如果s=2,则以为着x<theta y预测为1,x<theta y预测为1 想明白这个事情之后,直接分theta大于0,小于0讨论,s=1 or s=-1把几种情况分

day1作业二:多级菜单操作

作业二:多级菜单 (1)三级菜单 (2)可以次选择进入各子菜单 (3)所需新知识点:列表.字典 要求:输入b返回上一层,输入q退出整个程序