|
#include<stdio.h>
#include<math.h>
int input(float *);
int treat(float a,float b,float c,float d);
float myF(int flag,float m,float n);
void myPrint(int type,int i,int j,int k,float a,float b,float c,float d);
int time,temp=0;
int inputnum(float *num)
{
int again=1;
int flag ;
while(again==1)
{
printf ("\nPlease Enter 4 nums(1~13):\n");
i=0;
flag=0;
while (flag==0)
{
i++;
for(i=0;i<4;i++)
{
scanf("%f",&num);
if (num<1 || num>13 || num!=int(num))
flag++;
}
if(flag!=0)
{
printf ("Error input again\n",i);
flag=0;
}
else
flag=1;
}
}
}
void main()
{
int i,j,k,t,res;
float num[4];
inputnum(num);
for (i=0;i<4;i++)
for (j=0;j<4;j++)
if (j!=i)
for (k=0;k<4;k++)
if (k!=j && k!=i)
for (t=0;t<4;t++)
if (t!=i && t!=j && t!=k)
{
res=treat(num,num[j],num[k],num[t]);
}
if (res==0)
printf ("\nNo answer\n");
printf ("\n1: Go on\n2: Quit\n");
scanf ("%d",&again);
}
int treat(float a,float b,float c,float d)
{
int i,j,k;
float sum1,sum2,sum3;
for (i=0;i<4;i++)
for (j=0;j<6;j++)
for (k=0;k<6;k++)
{
if ((!(i==3 && b==0)) && (!(j==3 && c==0)) && (!(k==3 && d==0)))
{
sum1=myF(i,a,b);
sum2=myF(j,sum1,c);
sum3=myF(k,sum2,d);
if (fabs(sum3-24)<0.1)
{
temp++;
myPrint(1,i,j,k,a,b,c,d);
}
}
if (k==2)
{
sum1=myF(i,a,b);
sum2=myF(j,c,d);
sum3=sum1*sum2;
if (fabs(sum3-24)<0.1)
{
temp++;
myPrint(2,i,j,k,a,b,c,d);
}
}
if (k==3)
{
sum1=myF(i,a,b);
sum2=myF(j,c,d);
if (sum2!=0)
{
sum3=sum1/sum2;
if (fabs(sum3-24)<0.1)
{
temp++;
myPrint(3,i,j,k,a,b,c,d);
}
}
}
}
if (temp==0)
return 0;
else
return 1;
}
float myF(int flag,float m,float n)
{
// time++;
if (flag==0)
return (m+n);
if (flag==1)
return (m-n);
if (flag==2)
return (m*n);
if (flag==3)
if (n==0)
return 30000;
else
return (m/n);
if (flag==4)
return (n-m);
if (flag==5)
if (m==0)
return 30000;
else
return (n/m);
return 0;
}
void myPrint(int type,int i,int j,int k,float a,float b,float c,float d)
{
char sigle[6];
sigle[0]='+';
sigle[1]='-';
sigle[2]='*';
sigle[3]='/';
sigle[4]='-';
sigle[5]='/';
if (type==1){
if(j==4 || j==5)
{
if (k==4 || k==5)
printf("%2.0f %c (%2.0f %c (%2.0f %c %2.0f)) =24\n",d,sigle[k],c,sigle[j],a,sigle,b);
else
printf("(%2.0f %c (%2.0f %c %2.0f)) %c %2.0f =24\n",c,sigle[j],a,sigle,b,sigle[k],d);
}
else if (k==4 || k==5)
{
printf("%2.0f %c ((%2.0f %c %2.0f) %c %2.0f) =24\n",d,sigle[k],a,sigle,b,sigle[j],c);
}
else
printf("((%2.0f %c %2.0f) %c %2.0f) %c %2.0f =24\n",a,sigle,b,sigle[j],c,sigle[k],d);
}
if (type==2 || type==3)
{
printf("(%2.0f %c %2.0f) %c (%2.0f %c %2.0f) =24\n",a,sigle,b,sigle[k],c,sigle[j],d);
}
}
(1)白盒测试,对上述的myPrint子程序进行DD路径测试,写出满足C1覆盖
(边覆盖)的测试用例
(2)集成测试,写出myPrint()所对应的桩;名字为stubMyPrint(),其中myPrint()的测试用例由(1)的答案给出。
|
|