20180925-4 单元测试,结对

此作业的要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2146

我们使用catch进行的单元测试

我们在产生随机字符串这部分出现了除零异常的现象,修改后代码如下:

for( i=0; i<7; i++)
    {
        if(i%2==0)
        {
            if(F)
            {
                str1[i]=rand()%10+'0';
            }
            else
            {
                while(1)
                {
                    tmp=rand()%10;
                    if(tmp)
                    {
                        str1[i]=tmp+'0';
                        break;
                    }
                }
            }

        }
        else
        {
            str1[i]=Flag();
            if(str1[i]=='/')
                F=false;
            else
                F=true;
        }
    }

修改了功能四,输出格式错误后的代码如下

flag=false;
        GetStr();
        if(rand()%2==1)
        {
            int KH=rand()%5;
            switch(KH)
            {
            case 0:
                for(i=7; i>0; i--)
                    str1[i]=str1[i-1];
                for(i=8; i>4; i--)
                    str1[i]=str1[i-1];
                str1[0]='(';
                str1[4]=')';
                str1[9]='';
                break;
            case 1:
                for(i=7; i>0; i--)
                    str1[i]=str1[i-1];
                for(i=8; i>6; i--)
                    str1[i]=str1[i-1];
                str1[0]='(';
                str1[6]=')';
                str1[9]='';
                break;
            case 2:
                for(i=7; i>2; i--)
                    str1[i]=str1[i-1];
                for(i=8; i>6; i--)
                    str1[i]=str1[i-1];
                str1[2]='(';
                str1[6]=')';
                str1[9]='';
                break;
            case 3:
                for(i=7; i>2; i--)
                    str1[i]=str1[i-1];
                str1[2]='(';
                str1[8]=')';
                str1[9]='';
                break;
            case 4:
                for(i=7; i>4; i--)
                    str1[i]=str1[i-1];
                str1[4]='(';
                str1[8]=')';
                str1[9]='';
                break;
            default:
                break;
            }
        }


        float Tans=Arithmetic(str1);
        //printf("2");
        for(i=0; i<j; i++)
        {
            if(Tans==QE[i])
            {
                flag=true;
                break;
            }
        }
        if(flag)
        {
            n++;
            continue;
        }
        QE[j++]=Tans;

        int len=strlen(str1);
        for(i=0; i<len; i++)
        {
            fprintf(fp,"%c",str1[i]);
        }
        fprintf(fp,"=");
        if(len==7)
            fprintf(fp,"  ");
        fprintf(fp,"%12.3f
",Tans);
原文地址:https://www.cnblogs.com/zhushenying123/p/9755950.html