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

将所有测试用例放入 input.txt

你的输出将打印在 output.txt 文件中

于 2012-04-25T11:52:44.100 回答