zoukankan      html  css  js  c++  java
  • 软件测试作业二

         (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

  • 相关阅读:
    JID 2.0 RC4 发布,高性能的 Java 序列化库
    FBReaderJ 1.6.3 发布,Android 电子书阅读器
    Arquillian 1.0.3.Final 发布,单元测试框架
    JavaScript 的宏扩展 Sweet.js
    Hypertable 0.9.6.5 发布,分布式数据库
    JRuby 1.7.0 发布,默认使用 Ruby 1.9 模式
    httppp 1.4.0 发布,HTTP响应时间监控
    Redis 2.6.0 正式版发布,高性能K/V服务器
    OfficeFloor 2.5.0 发布,IoC 框架
    XWiki 4.3 首个里程碑发布
  • 原文地址:https://www.cnblogs.com/shangcong/p/5263100.html
Copyright © 2011-2022 走看看