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:项目中有有影响的部分必须导致一些输出或结果的不正确

  • 相关阅读:
    截取图片中间部分
    chrome调试手机webview中页面
    页面中如何让标点不出现在行首
    jquery checkbox checked 却不显示对勾
    thinkphp 5.x No input file specified 解决
    常用的一些子域名,旁站等查询网站
    Windows应急日志常用的几个事件ID
    fsockopen反弹shell脚本
    LOG日志溯源取证总结
    交互式shell脚本web console
  • 原文地址:https://www.cnblogs.com/yi-jie/p/5256448.html
Copyright © 2011-2022 走看看