jeudi 3 novembre 2022

How can i create a two different .txt file in c++ (Stress Testing)

A few days ago, I learned about stress testing and wanted to ask how to make two different .txt files.

Like one for Output and one for my failed test case.

It would work like this:

output: it would have all the output, correct solution, and wrong solution

failedtestcase.txt: it would have only those test cases detail that have failed and which inputs were given for the particular failed test case.

`

int main() {
    freopen("output.txt", "w", stdout);
    //create a freopen for Failed test case

    srand(time(NULL));
    int t = rand() % 10;
    cout<< "======================================" << endl;
    cout << "            Test Case: "<< t << "           "<<  endl;
    cout<< "======================================" << endl;
  
    while(t--){
        int n = rand() % 11;
        cout << "Number of Element: " <<  n << endl;
        int d = rand() % n;
        cout << "Kth: " << d << endl;
        cout << "Araray: " << endl;
        int arr[n];
        for(int i=0; i< n;i++){
            arr[i] = rand() % 11;
            cout<< arr[i] << " ";
        }
        sort(arr, arr+n);
        cout << endl;

        KthSAndL(arr, n, d);

        freopen("FailedTestcase.txt", "w", stdout);

        pair<int, int> MySolution = KthSAndL(arr, n, d);
        pair<int, int> ActualSolution = kthSmallestLargest(arr, n, d);

        if(MySolution.first != ActualSolution.first && MySolution.second != ActualSolution.second){
            cout << "Wrong Answer" << endl;
            cout << "Your Answer: " << MySolution.first << " " << MySolution.second << endl;
            cout << "Actual Answer: " << ActualSolution.first << " " << ActualSolution.second << endl;
        }

        cout << endl;
        cout<< "======================================" << endl;
    }

    return 0;
}

`

This is the code and i'm getting this Kind of output 😑

enter image description here

I was trying to have my all output in output.txt and only failed test case inputs will be shows in failedtestcase.txt

What I tried:

  1. Moving the Lines up down before cout'ing (Might work I thought)

and well actully I have no idea what I can do 🤷

Aucun commentaire:

Enregistrer un commentaire