• 软件测试作业2


    对于第一道题:

    public intfindLast(int[] x, inty) {
    //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 (inti=x.length-1; i> 0; i--)
        {
            if (x[i] == y)
            {
            return i;
            }
        }
        return -1;
        }
    // test: x=[2, 3, 5]; y = 2
    // Expected = 0            
    

      

    Fault:i>0的写法是错误的,应该是i>=0;

    不执行这个fault的测试用例:x=[2,3,4];y=2;

    执行了这个fault但是没有导致error:x=[2,3,4];y=2;

    导致了error但是没有导致failure的:x=[2,4,5];y=0;

    对于第二道题:

    public static intlastZero(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 (inti= 0; i< x.length; i++)
        {
                if (x[i] == 0)
                {
                return i;
                }
        }
      
    return -1; } // test: x=[0, 1, 0] // Expected = 2

    这个fault是for循环写的顺序不对,应该写成从后往前找:for(int i = x.length-1; i >= 0; i--)

    不执行这个fault的测试用例:x=[];

    执行了这个fault但是没有导致error:x=[2,3,0];

    导致了error但是没有导致failure的:x=[2,4,0];

    //老师其实我还是不大理解error和fault怎么区分,例如这个第二道题,fault是比较大的错误了已经,如果要执行fault,我认为马上就会遇到error,迭代就倒序了。

  • 相关阅读:
    Linux 重新挂载分区的方法
    SQL复习三(子查询)
    SQL复习四(完整性约束)
    SQL 复习二(数据查询语言)
    SQL复习一(基础知识)
    在windos 环境下安装
    tt程序分析(一)
    单例模式Singleton
    用命令行使用soot反编译生成jimple
    在win10环境下安装eclipse mars版本
  • 原文地址:https://www.cnblogs.com/yanwenxiong/p/5259396.html
Copyright © 2020-2023  润新知