zoukankan      html  css  js  c++  java
  • Software Testing hw2

       

    Fault的定义可能导致系统或功能失效的异常条件(Abnormal condition that can cause an element or an item tofail.),可译为“故障”。
     
    Error的定义计算、观察或测量值或条件,与真实、规定或理论上正确的值或条件之间的差异(Discrepancy between a computed, observed
    or measured value or condition and the true, specified, or theoretically correct value or condition.),可译为“错误”。Error是能够导
    致系统出现Failure的系统内部状态。

     

    Failure的定义:当一个系统不能执行所要求的功能时,即为Failure,可译为“失效”。(Termination of the ability of an element or an item to

    perform a function as required.)

     

    程序1:

    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

     

    答:

    1)for循环中循环条件应该是i>=0;

    2)当x为零时,运行时直接跳过for循环不执行错误代码;

    3)当x中与y相等的元素不是x[0]时,代码运行且不报错;

    4)x中只有一个元素时,出现error没有failure。

     

    程序2:

    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

    答:

    1)for循环里应该是for (int i = x.length - 1; i >= 0; i --);

    2)所有用例都进过错误代码;

    3)当x中只有一个元素时,如x = [1]时,虽然运行到了出错代码,但并不会出现错误。

    4)当x中只有一个0或没有0时,程序运行出现Error,但没有Failure。

     

  • 相关阅读:
    安装lnmp 时如何修改数据库数据存储地址及默认访问地址
    ubuntu 设置root用户密码并实现root用户登录
    解决ubuntu 远程连接问题
    linux 搭建FTP服务器
    PHP 根据ip获取对应的实际地址
    如何发布自己的composer包
    使用composer安装composer包报Your requirements could not be resolved to an installable set of packages
    laravel 框架配置404等异常页面
    使用Xshell登录linux服务器报WARNING! The remote SSH server rejected X11 forwarding request
    IoTSharp 已支持国产松果时序数据库PinusDB
  • 原文地址:https://www.cnblogs.com/lixuntaohaolihai/p/5281683.html
Copyright © 2011-2022 走看看