插入过程的黑盒测试用例
insertion_procedure (int a[], int p [], int N)
{
int i,j,k;
for (i=0; i<=N; i++) p[i] = i;
for (i=2; i<=N; i++)
{
k = p[i];
j = 1;
while (a[p[j-1]] > a[k]) {p[j] = p[j-1]; j--}
p[j] = k;
}
}
对于这个特定的插入过程,有哪些好的测试用例?
insertion_procedure (int a[], int p [], int N)
{
int i,j,k;
for (i=0; i<=N; i++) p[i] = i;
for (i=2; i<=N; i++)
{
k = p[i];
j = 1;
while (a[p[j-1]] > a[k]) {p[j] = p[j-1]; j--}
p[j] = k;
}
}
What would be few good test cases for this particular insertion procedure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确读取此函数,则任何具有此属性的输入
a[0]> a[2] 将分段错误
首先循环通过
for (i=2; i<=N; i++)
跟踪我头脑中的变量。
i = 2
k = p[i] == 2
j = 1
p[j-1] = p[0] == 0
a[0] > a[2]
while 循环条件为 true,因此j-- == 0
while (a[p[-1] > k)
-> SEGFAULT这可能是一个很好的测试:-)
看起来没有任何有用的输入可以使 while 循环在没有段错误的情况下运行多次,所以我想说那里存在逻辑错误
If I read this function correctly any input with this property
a[0] > a[2] will seg fault
First loop through
for (i=2; i<=N; i++)
Tracing the variables in my head.
i = 2
k = p[i] == 2
j = 1
p[j-1] = p[0] == 0
a[0] > a[2]
while loop condition is true, thereforej-- == 0
while (a[p[-1] > k)
-> SEGFAULTThat might be a good test :-)
It doesn't look like there is any useful input that would make that while loop run more than once without a segfault so I'd say there is a logic error there
我将从
看看实现(我不在c中编程),我怀疑其中一些将是AV。
简而言之,您至少应该对输入参数进行边界分析,并为每个参数设置一个测试,其中每个值都出界、边界和入站。
示例
如果您有 1 个参数并确定界限为 0 和 10,则应该产生 6 个测试用例。您应该传入 -1、0、1、9、10 和 11。
进一步研究
随着参数数量的增加,测试所有组合很快就会变得不可能。这就是全对测试派上用场的地方。
I would start with these
Looking at the implementation (I don't programm in c), I suspect some of these will AV.
In a nutshell, you should at least do a boundary analysis of your input parameters and device a test for each parameter with each value out of bound, on the boundary and inbound.
Example
If you have 1 parameter and determine the bounds are 0 and 10, it should result in 6 testcases. You should pass in -1, 0, 1, 9, 10 and 11.
Further study
As the ammount of parameters grows, it will quickly become impossible to test all combinations. This is where all-pairs testing would come in handy.