您的位置:首页 > 其它

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.

  

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: