问答题
论述题3:
已知C源程序如下:
/*longIntAdd*/
#include<stdio.h>
#include<string.h>
#define LENGTH 81
void addLInt(char s1[],char s2[]);
void reverse(char s[]);
int main()
{
char intstr1[LENGTH],intstr2[LENGTH];
printf("请输入超长整数的被加数和加数:\n");
scanf("%s%s",intstr1,intstr2);
addLInt(intstr1,intstr2);
printf("超长整数和为:%s",intstr1);
return 0;
}
void addLInt(char s1[],char s2[])
{
int i=0,tmp,c=0;
char s[LENGTH];
if(strlen(s1)<strlen(s2)){
strcpy(s,s1);
strcpy(s1,s2);
strcpy(s2,s);
}
reverse(s1);reverse(s2);
while(s2[i]!=;\0’){
tmp=s1[i]-’0’+s2[i]-’0’+c;
81[i]=tmp%10+’0’;
c=tmp/10;
i++;
}
while(si[1]!=’\0’&&c){
tmp=s1[i]-’0’+c;
s1[i]=tmp%10+’0’;
c=tmp/10;
i++;
}
If(c){
s1[i++]=c+’0’;
s1[i]=’\0’;
}
reverse(s1);
}
void reverse(char s[])
{
int i,j,c;
for(i=0,j=strlen(s)-1;i<j;i++,j--){
c=s[i];
s[i]=s[j];
s[j]=c;
}
}
设计一组测试用例,使该程序addLInt函数的语句覆盖率和分支覆盖率均能达到100%。如果认为该函数的语句覆盖率或分支覆盖率无法达到100%,需说明为什么。
【参考答案】
测试用例a.s1:“1111111111111111” s2:“2222222222222222"b.s1:“12345......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)