Software Test HOMEWORK02:

Software Test HOMEWORK02

The first test case:

                              

1. Identify the fault:

  As we can see, there is a fault marked in the red circle on the figure above. Because the judgment condition of the loop is i > 0, the program can not enter the loop when i = 0.

  The judgment condition is supposed to i >= 0. In that case, if test : x = [2,3,5]; y = 2, the actual output is “-1” which not equal to the expected.

2. a test case that dose not execute the fault:

     x = null ; y = 2

     Expected: Null Pointer Exception

     Actual: Null Pointer Exception

3. a test case that executes the fault, but does not result in an error state:3

     x = [3,5,2] ; y = 2  Or  x =[3,2,5] ; y = 2

     Expected: 2                 Expected: 1

     Actual: 2                     Actual:1

  Because the error state is i = 0 when the condition is i > 0 . But if the program return i before i change to 0, it can avoid the error state.

4. a test case that results in an error, but not a failure:4.

     x = [1,3,5] ; y = 2

     Expected: -1

     Actual: -1   

  In that case the program will reach the state that i = 0, but there is no “2” in elements of x, so it will not result in a failure.

 

The second test case:

                               

1. Identify the fault:

  As we can see, there is a fault marked in the red circle on the figure above. The loop starts by index = 0, and the array is searched in the order of forward and backward,which is marked by the red circle. In this order, the program “return i”, returns the index of the first 0 element in the array x.

  And in my opinion, there is supposed to change the order of this for loop and the same as the first test case. For example:

              for(int i = x.length-1; i >= 0; i--)

2. a test case that dose not execute the fault:

    x = null

    Expected: Null Pointer Exception

    Actual: Null Pointer Exception

  In those cases, the program will not execute the for loop.

3. a test case that executes the fault, but does not result in an error state: 

     x = [1,1,1]

     Expected: -1

     Actual: -1

  The error state is i equal to the index of the first 0.

  Once the program executes and there is no 0 in the array, it’s state of i is right. Therefore, the program execute the fault, but avoid the error state.

4. a test case that results in an error, but not a failure:4.

     x = [0,1,1] (an array that only has one 0)

     Expected: 0

     Actual: 0

  The error state is i equal to the index of the first 0. When there is a 0 in the array, the program is in this error state, the actual outcome is the expected and not a failure.

posted on 2017-02-28 09:17  HuMeng96  阅读(172)  评论(0编辑  收藏  举报

导航