0

私はCプログラムを持っていて、いくつかのテストデータを含むファイルを使用してそれをテストし、結果を自動的に出力する必要があります。これどうやってするの?プログラムを変更する必要がありますか、それともCまたはPythonのようなものを使用して別のプログラムを作成する必要がありますか?どちらが簡単ですか?

これが私のCプログラムです:

int main()
{
    double wh,sh,salary;
    int num = 0;
    int valid = 1;
    printf("Please input two non-negative numbers as a employee's working hours in one week and salary per hour.\n");
    printf("Notice that the salary per hour can't be greater than 1000\nAlso you can't input more than 10 sets of data\n");
    printf("Input them like this:\n20,34\nthen enter the Enter key\n");
    while(scanf("%lf,%lf",&wh,&sh) == 2 && num < 10)
    {
        if(sh <0 || wh <0)
        {
            printf("Salary per hour or salary per hour can't be negative!\n");
        }
        else if(wh > 168)
        {
            printf("Working hours in one week can't be more than 168!\n");
        }
        else if(sh > 1000)
        {
            printf("Salary can't be greater than 1000!\n");
        }
        else
        {
            num ++;
            if(wh <= 40)
            {
                if(sh <= 1000)
                {
                    salary = wh * sh;
                }
                else if(sh > 1000 )
                {
                    salary = wh * 1000;
                }
            }
            else if(wh > 40 && wh <= 50)
            {
                if(sh*1.5 < 1000)
                {
                    salary = 40*sh + (wh-40)*1.5*sh;
                }
                else if(sh*1.5 > 1000 && sh < 1000)
                {
                    salary = 40*sh + (wh-40)*1000;
                }
                else if(sh > 1000)
                {
                    salary = wh * 1000;
                }
            }
            else if(wh > 50)
            {
                if(sh*3 < 1000)
                {
                    salary = 40*sh + 10*1.5*sh + (wh-50)*3*sh;
                }
                else if(sh*1.5 < 1000 && sh*3 >=1000)
                {
                    salary = 40*sh + 10*1.5*sh + (wh-50)*1000;
                }
                else if(sh*1.5 >= 1000 && sh <= 1000)
                {
                    salary = 40*sh + (wh-40)*1000;
                }
                else if(sh > 1000)
                {
                    salary = wh*1000;
                }
            }
            printf("The total working hours is %lf, and salary per hour is %lf, salary is %lf\n",wh,sh,salary);
        }
    }
    return 0;
}

今のところ、これらのリテラルが浮かんでいるのは無視してください。

テストデータを含むファイルは次のようになっていると思います。

1,2
34,34
67,43
...

このテスト自動化がどのように機能するのか本当にわかりません。助けてください!

4

1 に答える 1

0

cmdプロンプトで

入力

c:\> myprog.exe <input.txt> output.txt

すべてのurテストケースをinput.txtに入れます

urの出力はoutput.txtファイルに出力されます

于 2012-04-25T11:52:44.100 に答える