zoukankan      html  css  js  c++  java
  • 软件测试第二次作业

    Below are four faulty programs. Each includes a test case that results in failure. Answer the following questions (in the next slide) about each program.

    public int findLast (int[] x, int y) { //Effects: If x==null throw                NullPointerException // else return the index of the last element // in x that equals y. // If no such element exists, return -1 for (int i=x.length-1; i > 0; i--) { if (x[i] == y) { return i; } } return -1; } // test: x=[2, 3, 5]; y = 2 // Expected = 0

    public static int lastZero (int[] x) { //Effects: if x==null throw NullPointerException // else return the index of the LAST 0 in x. // Return -1 if 0 does not occur in x for (int i = 0; i < x.length; i++) { if (x[i] == 0) { return i; } } return -1; }
    // test: x=[0, 1, 0] // Expected = 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.

    (1)fault:由i>0知,i不可能为0,所以不可能得到期望值0

           不执行故障测试用例  :x=[]; y=2  期望值=-1       执行故障不导致错误用例  : x=[3,2,5]; y=2 期望值=1

           导致错误但不是失败结果的用例: x=[1,3,5]; y=2 期望值=-1

     ( 2 )fault: 因为数组第一个即为0,所以到第一个时已经返回了0,不可能得到期望2

           不执行故障测试用例 :x=[]  期望值=-1

           执行故障不导致错误用例  : x=[1,2,3] 期望值=-1

           导致错误但不是失败结果的用例: x=[2,3,0,4] 期望值=2

  • 相关阅读:
    XML 特殊字符
    asp.net Application、 Session、Cookie、ViewState、Cache、Hidden 的区别
    Oracle 和 SqlServer 的区别
    TFS源代码管理的8大注意事项
    json 排序
    网页中内容的显示问题
    e.target与事件委托简例(转)
    form 中的 table元素过滤定位事件
    (转) Ajax 重定向
    Django ajax post 403 问题
  • 原文地址:https://www.cnblogs.com/shenyuelong/p/5258615.html
Copyright © 2011-2022 走看看