Hello Codeforces
I decided to share this article about stress testing after watching the last screencast made by Errichto. To be more precise when he started making stress testing to find counter-test. You can check that here. Errichto has a full video called How to test your solution in Competitive Programming, on Linux? I highly recommend you to check it, basically this article is the same but I am extending it to stress test solutions with multiple answers using a written checker, and I thought maybe you like written articles more than watching videos (some people do).
You can find the article here. I hope you will like it, please share with me your thoughts and if you use other helpful tools then you can share them in the comments below.
You can also check some of my previously written articles about Competitive Programming at:
Is there a way to stop the bash script if one of the 3 files being compiled returned an error. When one of the files doesn't compile there is no point running the rest of the script right?
Sure, you can kill the script at any time using Ctrl + C
Add "set -e" at the beginning of the script file, it means: "if any command exits with non-zero status, which make/g++ commands do in case of compile error, the script will instantly terminate". This also means if generator/one of stresstested solutions crashes the script terminates instantly.
Added, thanks for pointing at it.
Thanks for sharing, this is a cool method I didn't know about.
Alternative method I use in case anyone is interested:
In bash (and most other scripting languages I suppose), the variable $? contains the exit condition of the previously run program, so you can just have a break condition in the script which triggers if the variable is non-zero after the execution. However yeah,
set -e
does seem to be a better way to do it. Also if you're running this directly from the terminal instead of from a script file, don't forget to doset +e
at the end to disable it.Also one other small note (for the author), I'd be careful using the "-w" option for diff, missing whitespace may not always result in the correct answer.
Edit: Also completely unrelated rant, why does mathjax still parse {backslash}{dollar sign} some text {backslash}{dollar sign}...
Most good online judges ignore extra whitespaces, but I think you are right, I will point for that just to be careful while using it.
Removing extra whitespaces is mostly fine, you'll usually only get WA on samples in the worst case which usually isn't be a penalty. But consider a question where you have to print two space separated numbers to the output. Say the answer is
10 11
, if the code somehow prints a wrong answer101 1
the diff won't complain if you're using -w.Possibly using -Z instead to remove trailing spaces might be a better idea.
Also is there any reason you use rand() over mt19937?
rand() has its problems, mt19937 is much faster and its quite often easier to use it with uniform_int_distribution or similar.
The link for the second problem is incorrect in the blog.