SoftwareTesting_Homework2
2016-03-06 20:43
330 查看
[b]SoftwareTesting_Homework2[/b]
[b]For the Program1, [/b]
For Question1:
The fault is that in the loop condition, ' i ' should be not less than(>=) 0 rather than just greater than(>) 0. This will result in the problem that if the target is just in the position 0 and then the program cannot return the correct answer.
The original one is like this,
for (int i=x.length-1; i > 0; i--)
However, it should be like this,
for (int i=x.length-1; i >= 0; i--)
For Question2:
Test: x = [2], y = 2
In this test case, the length of the ' x ' is just 1 and then it cannot suit the condition of the loop. In the other word, it will not go into the loop and then the program will return -1. And this is not the correct answer obversely.
For Question3:
Test: x = [3,2,5], y = 2
In this test case, the original
program will not occur a failure because the target is not in the
position 0. As a result, this will not make a mistake even if it has the
reachability.
But it will be in a error state.
For Question4:
Test: x=[2, 2, 5]; y = 2
Expected = 1
As a result, the program do not check the x[0] and this is an error condition but the answer is correct and this is not a failure.
[b]For the Program2,[/b]
For Question1:
The fault is that the origenal program return the first 0 that occurs in ' x ' but not the last.
The original one is like this,
for (int i = 0; i < x.length; i++)
However, it should be like this,
for (int i=x.length-1; i >= 0; i--)
For Question2:
I think it is impossible or maybe ' x ' is an empty array (that may throw a NullPointerException). And then this may not execute the fault.
For Question3:
Test case: x = [3]
Or maybe it is impossible.
For Question4:
Test: x = [0,1,1] return is 0 and this is right.
Because the 0 is the only one in the array and then the first and the last is the same.
[b]For the Program1, [/b]
For Question1:
The fault is that in the loop condition, ' i ' should be not less than(>=) 0 rather than just greater than(>) 0. This will result in the problem that if the target is just in the position 0 and then the program cannot return the correct answer.
The original one is like this,
for (int i=x.length-1; i > 0; i--)
However, it should be like this,
for (int i=x.length-1; i >= 0; i--)
For Question2:
Test: x = [2], y = 2
In this test case, the length of the ' x ' is just 1 and then it cannot suit the condition of the loop. In the other word, it will not go into the loop and then the program will return -1. And this is not the correct answer obversely.
For Question3:
Test: x = [3,2,5], y = 2
In this test case, the original
program will not occur a failure because the target is not in the
position 0. As a result, this will not make a mistake even if it has the
reachability.
But it will be in a error state.
For Question4:
Test: x=[2, 2, 5]; y = 2
Expected = 1
As a result, the program do not check the x[0] and this is an error condition but the answer is correct and this is not a failure.
[b]For the Program2,[/b]
For Question1:
The fault is that the origenal program return the first 0 that occurs in ' x ' but not the last.
The original one is like this,
for (int i = 0; i < x.length; i++)
However, it should be like this,
for (int i=x.length-1; i >= 0; i--)
For Question2:
I think it is impossible or maybe ' x ' is an empty array (that may throw a NullPointerException). And then this may not execute the fault.
For Question3:
Test case: x = [3]
Or maybe it is impossible.
For Question4:
Test: x = [0,1,1] return is 0 and this is right.
Because the 0 is the only one in the array and then the first and the last is the same.
相关文章推荐
- 卷积神经网络(CNN)的简单实现(MNIST)
- linux时间片轮转小程序
- 矩形翻转
- HDU 4302 Holedox Eating(multiset)
- yii 用户管理 controller
- FZU 2195 思维
- Linux内核分析— —操作系统是如何工作的(20135213林涵锦)
- static 用法详细解释
- 常用未分类命令
- 使用Arduino读取噪声传感器分贝值
- 安卓手机恢复大师镜像存储的使用教程
- 详解Python中的下划线
- How to Develop blade and soul Skills
- 写给自己
- Java中equals、==、hashcode的区别
- poj 2533 dp
- Web安全之点击劫持(ClickJacking)
- STL与泛型编程<四>:List
- 二叉搜索树的后序遍历序列
- 设计模式之外观模式(Facade)