软件测试入门的学习与思考

第一次题目:

Briefly describe an error from your past projects that you have recently completed or an error from other projects which impress you most. State the reason, impact of the error and how did you find it.

  • 说到近期的印象比较深的error,第一时间想到的是某次在做acm题的时候,需要用到判断某个数m是否是素数。m的数据范围应该是超过10的12次方了。

我的错误函数:

bool prime(lli m){
    if(m == 1) return 0;
    for(int i = 2;i *i <= m;i++){
        if(m % i == 0) return 0;
    }
    return 1;
}
  1. 然后在交题后却得到了time exceed的提示,大概算了一下复杂度,感觉应该不会超时的,于是感觉是某些地方出逻辑问题了。于是开始一个函数一个函数排查,最后发现在prime这个函数迟迟没有结束。。
  2. 才发现i*i这里爆精度了,i是int型的,i*i也默认是int型。。。
  3. 改成long long int 就OK了。

第二次:

Below are two faulty programs. Each includes a test case that results in failure. Answer the following questions (in the next slide) about each program.

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,显然x[0]访问不到。
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
  • 这个很显然连最基本的功能都没实现(实现错了),找最后一个0,为什么要从同开始遍历?

然后是一个概念的辨析:

  • fault:A static defect in the software。指的是那些写错的地方的代码。
  • error:An incorrect internal state that is the manifestation of some fault。由于内部的错误的代码(fault)所产生的错误的表现形式。
  • failure:External, incorrect behavior with respect to the requirements or other description of the expected behavior。外部的错误。
If possible, identify a test case that does not execute the fault. (Reachability)
1)//x=null
2)//x=null
If possible, identify a test case that executes the fault, but does not result in an error state.
1)//test: x=[2, 3, 5]; y = 5 // Expected = 5
2)//test: x=[0, 3, 5];  // Expected = 0
If possible identify a test case that results in an error, but not a failure. 
1)//test: x=[2, 3, 5]; y = 2 // Expected = 5; // actually:-1
2)//test: x=[0, 3, 0];  // Expected = 2; // actually: 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值