• 软件测试作业二


         (1)findLast

    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
    

    (a)  Identify the fault:

    for (int i=x.length-1; i > 0; i--)  ,"i>0" should be "i>=0",otherwise, the 0 index can not be included

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

    test: x=null;y=1;

    expected=null;

    fact = null;

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

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

    expected=1;

    fact = 1;

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

     test:x=[3,2,5] ; y=6

    expected = -1;

    fact = -1;

    (2)lastZero

    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

    (a)  Identify the fault:

    for (int i = 0; i < x.length; i++), order should be from high to low ,should be "for (int i=x.length-1; i > 0; i--) "

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

    no possible

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

     test:x=[1]

    expected=-1;

    fact = -1;

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

     test:x=[1,0,1] 

    expected = 1;

    fact = 1;

    tips:

    Software Fault : A static defect in the software (软件中的设计错误,就是代码本身就写错了) 

    Software Failure : External, incorrect behavior with respect to the requirements or other description of the expected behavior (失效,与预期不一样,表现出来的)

    Software Error : An incorrect internal state that is the manifestation of some fault (在运行过程中的)

     

     fault -> error -> failure,软件中的缺陷在运行时会产生error,当error累计到一定程度时会导致失效,这些都是bug

  • 相关阅读:
    javascript 使用链式结构
    javascript 闭包
    javascript 使用canvas绘画
    (14)javascript 函数表达式 递归、闭包
    (13)javascript 面向对象 创建对象
    wpf和winform的区别
    XtraReport1添加参数
    {$DEFINE WANYI}
    $('#myModal').modal('show') //显示$('#myModal').modal('hide')隐藏
    计算机音视频技术
  • 原文地址:https://www.cnblogs.com/shangcong/p/5263100.html
Copyright © 2020-2023  润新知