Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

bhaskar_op's blog

By bhaskar_op, 2 hours ago, In English

Hi All CPers,

While contest or practice, when you submit code, the majority of times you get WA at some test cases which you can't see. So you've to think about edge cases where your code is failing.

This code will do stress testing for you and will give you test cases where your code is failing.

This code has main two function

  • One is your_function() where you'll paste your code which got WA.
  • Another one is bruteforce_function() where you'll write bruteforce solution.

Now you've to construct inputs.

Template has various functions of generating random inputs

  • generate_random_number()

  • generate_random_lowercase_string_of_length_n()

  • generate_random_uppercase_string_of_length_n()

  • generate_random_both_case_string_of_length_n()

  • generate_random_numeric_string_of_length_n()

  • generate_vector_of_random_value_of_length_n()

Using these functions you'll generate inputs in stress_testing() function and have to pass them as function parameters in three functions i.e. your_function(), bruteforce_function() and print_input()

You've to write print statements in print_input() function just to see the generated test cases. Other print statements are already written. You should write print statements for inputs because input format changes from problem to problem. (In future, I'll try to make this print_input() function automatic type and will update the repo where it'll automatically print the generated inputs and you have to do nothing).

For example, you need a test case that needs N and an array of length N. Then you should do something like this

  • int N = generate_random_number(some_max_value);

  • vector v = generate_vector_of_random_value_of_length_n(N,array_element's_lower_range,array_element's_upper_range);

Then you can change the number of test cases (Recommending you to not set more than 100) in main() function and then compile and run the program.

The code will give you output for all test cases in this format (Screenshot added down below).

Github Repo

Concept of doing this.

  • Writing a bruteforce solution of a problem won't take more than 10 minutes and you can quickly write bruteforce and can know test cases where your original code is failing.

Stress-Testing-Output

Happy Coding!.. Good Night

  • Vote: I like it
  • +2
  • Vote: I do not like it