Debugging and to take (a): to generate test data to beat +

  Today, playing seasonal small series very angry, next door LSH had run the wrong file, and repeat all the teachers on the land, and small series but love revert to take the eye, so Xiao Bian decided to build their own data or re-test the code again, then concentrated on studying the method for generating test data.

  Actually very simple, a few random numbers generated by the random number generator according to data from the scale and then mold on it, (you can add some specific test points if necessary), a few lines of code can not explain ( do not ask me why, windows system programming instructions is so, think about why so hello to spell it ):

  data.cpp

 1 #include<iostream>
 2 #include<windows.h>
 3 #include<ctime>
 4 using namespace std;
 5 int main()
 6 {
 7     srand(time(NULL));
 8     cout<<rand()%10<<" "<<rand()%10;
 9     return 0;
10 } 

  Followed by two sets of test code (see a problem occurs)

  a.cpp

1 #include<iostream>
2 using namespace std;
3 int main()
4 {
5     int a,b;
6     cin>>a>>b;
7     cout<<a*a+b;
8     return 0;
9 }

  b.cpp

1 #include<iostream>
2 using namespace std;
3 int main()
4 {
5     int a,b;
6     cin>>a>>b;
7     cout<<a*2+b*3;
8     return 0;
9 }

  Usually two code is a positive solution and violence code, we must ensure that violence is correct, and then continue to generate input data comparison violence and answers positive solutions, in order to check whether the positive solution is right.

  Next is a shot procedure:

  compare.cpp

 1 #include<iostream>
 2 #include<windows.h>
 3 using namespace std;
 4 int main()
 5 {
 6     int n=10;
 7     while(n--)
 8     {
 9         system("data.exe > data.txt");
10         system("a.exe < data.exe > a.txt");
11         system("b.exe < data.exe > b.txt");
12         if(system("fc a.txt b.txt")) break;
13     }
14     if(n==0) cout<<"Great!"<<endl;
15     else cout<<"error"<<endl;
16     return 0;
17 }

  Mr. Cheng test data are input in two programs, the final comparison output. [Note]: You must file in the same directory, but also for the operation of the program is to shoot exe file.

Guess you like

Origin www.cnblogs.com/TFLS-gzr/p/11028716.html