Блог пользователя C137

Автор C137, история, 4 года назад, По-английски

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:

  • Проголосовать: нравится
  • +82
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится -10 Проголосовать: не нравится

    Sure, you can kill the script at any time using Ctrl + C

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +6 Проголосовать: не нравится

      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.

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Added, thanks for pointing at it.

      • »
        »
        »
        »
        4 года назад, # ^ |
        Rev. 4   Проголосовать: нравится +1 Проголосовать: не нравится

        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 do set +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}...

        • »
          »
          »
          »
          »
          4 года назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          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.

          • »
            »
            »
            »
            »
            »
            4 года назад, # ^ |
            Rev. 4   Проголосовать: нравится +10 Проголосовать: не нравится

            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 answer 101 1 the diff won't complain if you're using -w.

            Possibly using -Z instead to remove trailing spaces might be a better idea.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
2 года назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

The link for the second problem is incorrect in the blog.