2012-04-25 29 views
0

我有一個C程序,我需要使用包含一些測試數據的文件進行測試,並自動輸出結果。我怎樣才能做到這一點?我應該修改程序還是應該使用C或Python之類的其他程序編寫另一個程序?哪個更容易?如何自動測試一個C程序的使用文件?

這裏是我的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 
... 

我真的不知道這個測試自動化是如何工作的,請大家幫忙!

回答

0

命令提示符

進入

C:\> MYPROG.EXE < input.txt中> output.txt的

把所有的烏爾測試用例在input.txt中

烏爾輸出會打印在output.txt文件中

+0

你怎麼稱呼這個自動化測試... – Gnijuohz 2012-04-25 12:02:16

+0

好吧,我改變了主意。這是一個很好的回答:) – Gnijuohz 2012-04-25 14:20:28

相關問題