SThw2——find the error in the follow case
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SThw2——find the error in the follow case相关的知识,希望对你有一定的参考价值。
public int findLast (int[] x, int y) {
//Effects: If x==null throw
NullPointerException?
// 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
l Identity the fault
这样的话丢掉了x[0]=y的情况
应该变成【for (int i=x.length-1; i >= 0; i--)】
l If possible, identity a test case that does not execute the fault. (Reachability)
一个到达了错误代码行,却没有执行的例子
比如:x = null,y = 2
返回:期望值——-1
实际值——-1
l If possible, identity a test case that execute the fault, but dose not result in an error state.
到达了错误的代码行,却没有导致错误的结果
test: x = [2, 3, 5]; y = 3/5
返回:期望值——1/2
实际值——1/2
l If possible, identity a test case that results in an error, but not a failure.
产生了error,而不是failure
test: x = [2, 3, 5]; y = 2
返回:期望值——0
实际值——-1
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
l Identity the fault
这样显示的是第一个0而不是最后一个0
应该改为for (int i = x.length – 1 ; i >= 0; i--)
l If possible, identity a test case that does not execute the fault. (Reachability)
一个数组中不含0的数组,例如test: x = [3, 1, 3]
返回:期望值——-1
实际值——-1
l If possible, identity a test case that execute the fault, but dose not result in an error state.
大概是一个回文结构的数组,0在最中间
例如test: x = [3, 0, 3]
返回:期望值——1
实际值——1
l If possible, identity a test case that results in an error, but not a failure.
test: x = [0, 1, 0]
返回:期望值——2
实际值——0
以上是关于SThw2——find the error in the follow case的主要内容,如果未能解决你的问题,请参考以下文章
AS打包报错:Generate Signed APK: Errors while building APK. You can find the errors in the 'Messages&
ERROR 1133 42000 Can't find any matching row in the user
Installing MIB in Ubuntu and Solving the Error “SNMP Cannot Find Module …”
ERROR: Could not find com.android.tools.build:gradle:3.5.0. Searched in the following locations:
关于jmeter命令行执行.jmx文件出现Error in NonGUIDriver java.lang.RuntimeException: Could not find the TestPlan c
could not find a writer for the specified extension in function ‘cv::imwrite_‘