zoukankan      html  css  js  c++  java
  • 软件测试技术 作业2

     1  public int findLast (int[] x, int y) {
     2 //Effects: If x==null throw
     3 NullPointerException
     4 // else return the index of the last element
     5 // in x that equals y.
     6 // If no such element exists, return -1
     7 for (int i=x.length-1; i > 0; i--)
     8 {
     9 if (x[i] == y)
    10 {
    11 return i;
    12 }
    13 }
    14 return -1;
    15 }
    16 // test: x=[2, 3, 5]; y = 2
    17 // Expected = 0

    错误:

    for (int i=x.length-1; i > 0; i--)

    应改为
    for (int i=x.length-1; i >= 0; i--)  //原代码中不会遍历到数组中第0个数据

    不会执行故障的用例:  x = [2,3,5];y = 5;Excepted = 2;

    执行故障但是不会导致错误状态的测试用例:  ??

    导致故障而不会失败的测试用例:  x = [2,3,5];y = 0; Excepted = -1;

     1 public static int lastZero (int[] x) {
     2 //Effects: if x==null throw
     3 NullPointerException
     4 // else return the index of the LAST 0 in x.
     5 // Return -1 if 0 does not occur in x
     6 for (int i = 0; i < x.length; i++)
     7 {
     8 if (x[i] == 0)
     9 {
    10 return i;
    11 }
    12 } return -1;
    13 }
    14 // test: x=[0, 1, 0]
    15 // Expected = 2

    错误:

    for (int i = 0; i < x.length; i++)

    应改为
    for (int i = x.length - 1; i >= 0 ; i--)  //原代码搜索出数组中第一个0而非最后一个
    不会执行故障的测试用例:  ??

    执行故障但是不会导致错误状态的测试用例:  ??

    导致故障而不会失败的测试用例:  x = [1,0,1];  Expected = 1;




    知识点:
    • 软件故障(software Fault):软件中的静态代码的缺陷
    • 软件错误(software Error):不正确的内部状态,该状态是故障的表现。
    • 软件失败(software Failure):与需求或期望的行为的描述有关德尔、外部的、不正确的行为
    Reachability:项目中错误的位置是可以找到的
    infection:项目中该阶段必须是不正确的
    Propagation:项目中有有影响的部分必须导致一些输出或结果的不正确

  • 相关阅读:
    CSS 使用技巧
    CSS display
    CSS float
    .NET自动识别HttpWebResponse的编码及是否压缩
    通用权限管理系统基类中数据库的连接
    通用权限底层实现的记录软删除及表中应包含的基本字段
    最好用的兼容多种数据库通用高效的大数据分页功能
    水平权限漏洞的修复方案
    通用权限管理系统菜单展示的一个技巧
    IE11下用forms身份验证的问题
  • 原文地址:https://www.cnblogs.com/yi-jie/p/5256448.html
Copyright © 2011-2022 走看看