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。

     

  • 相关阅读:
    BGP community和联邦实验
    BGP RR的设计原则
    BGP不可比较的AS间的度量问题的解决办法
    BGP理解错误的部署RR造成的环路
    BGP数据结构表
    BGP RR的环路避免机制
    BGP Lab RR & Loop (1)
    Lab BGP Summary
    70、对象复用的了解,零拷贝的了解
    66、malloc、realloc、calloc的区别
  • 原文地址:https://www.cnblogs.com/lixuntaohaolihai/p/5281683.html
Copyright © 2011-2022 走看看