Sylvia_Kim

导航

【SoftwareTesting】Homework2

For the Program1,

  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.

 

For the Program2,

  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.

posted on 2017-03-02 20:02  Sylvia_Kim  阅读(94)  评论(0编辑  收藏  举报