Software Testing hw2
2016-03-15 23:08
141 查看
Fault的定义:可能导致系统或功能失效的异常条件(Abnormal condition that can cause an element or an item tofail.),可译为“故障”。
Error的定义:计算、观察或测量值或条件,与真实、规定或理论上正确的值或条件之间的差异(Discrepancy between a computed, observed
or measured value or condition and the true, specified, or theoretically correct value or condition.),可译为“错误”。Error是能够导
致系统出现Failure的系统内部状态。
Failure的定义:当一个系统不能执行所要求的功能时,即为Failure,可译为“失效”。(Termination of the ability of an element or an item to
perform a function as required.)
程序1:
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
答:
1)for循环中循环条件应该是i>=0;
2)当x为零时,运行时直接跳过for循环不执行错误代码;
3)当x中与y相等的元素不是x[0]时,代码运行且不报错;
4)x中只有一个元素时,出现error没有failure。
程序2:
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)for循环里应该是for (int i = x.length - 1; i >= 0; i --);
2)所有用例都进过错误代码;
3)当x中只有一个元素时,如x = [1]时,虽然运行到了出错代码,但并不会出现错误。
4)当x中只有一个0或没有0时,程序运行出现Error,但没有Failure。
Error的定义:计算、观察或测量值或条件,与真实、规定或理论上正确的值或条件之间的差异(Discrepancy between a computed, observed
or measured value or condition and the true, specified, or theoretically correct value or condition.),可译为“错误”。Error是能够导
致系统出现Failure的系统内部状态。
Failure的定义:当一个系统不能执行所要求的功能时,即为Failure,可译为“失效”。(Termination of the ability of an element or an item to
perform a function as required.)
程序1:
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
答:
1)for循环中循环条件应该是i>=0;
2)当x为零时,运行时直接跳过for循环不执行错误代码;
3)当x中与y相等的元素不是x[0]时,代码运行且不报错;
4)x中只有一个元素时,出现error没有failure。
程序2:
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)for循环里应该是for (int i = x.length - 1; i >= 0; i --);
2)所有用例都进过错误代码;
3)当x中只有一个元素时,如x = [1]时,虽然运行到了出错代码,但并不会出现错误。
4)当x中只有一个0或没有0时,程序运行出现Error,但没有Failure。
相关文章推荐
- Lucene教程
- [Audio processing] wav音频文件合并
- 1001
- go源码阅读笔记(math.1)
- leetcode:Restore IP Addresses 【Java】
- 编程之路
- “咻一咻”的背后
- TYVJ 2032 搜索
- ArrayList源码分析
- Redis的阻塞式列表解析
- TYVJ 2032 搜索
- hdu2955 01背包
- struts2——(8)(①3种情况通配符的使用方法②动态方法调用 )
- 大道至简阅读笔记01
- 接续符和转义符
- 正则表达式初学习
- HTTP 请求方式: GET和POST的比较
- .net的锁
- 能不转发的就不要转发——记一次文件下载丢包填坑之旅
- [Audio processing] wav音频文件读取int和double数组的关系