软件测试:Homework 2

Homework 2:

     

    

Questions:


Identify the fault.

 If possible, identify a test case that does not execute the fault. (Reachability) 

 If possible, identify a test case that executes the fault, but does not result in an error state.

 If possible identify a test case that results in an error, but not a failure.

 

Answer:

 

左边程序的第六行改为:for (int i=x.length-1; i >= 0; i--)

   右边程序的第五行改为:for (int i=x.length-1; i >= 0; i--)

 

左边程序:All inputs execute the fault - even the null input. 

   右边程序:All inputs execute the fault - even the null input. 

 

左边程序 :如果不执行循环,那么就不会出现error,所以输入为空或者只含有一个元素。

                     input:x = [3]; y = 2

                     Expected Output: -1

                     Actual Output: -1

   右边程序 :如果不执行循环,那么就不会出现error; 如果循环只执行一次,那么从左到右和从右到左遍历的结果是一样的,也不会出现error。

                     input:x = [2]

                     Expected Output: -1

                     Actual Output: -1

 

左边程序测试实例:当输入超过一个元素时,便会出现error;当期望值与实际值相等时,便不会出现failure。

                     input: x = [3,2,5] ; y = 2

                     Expected Output: 1

                     Actual Output: 1

   右边程序测试实例:当输入超过一个元素时,便会出现error;当期望值与实际值相等时,便不会出现failure。

                     input:x = [5,2,0]

                     Expected Output: 2

                     Actual Output: 2

 

posted @ 2018-03-12 17:45  hellomq  阅读(154)  评论(0编辑  收藏  举报