nhivd's blog

By nhivd, history, 6 years ago, In English

Hi everyone! I have a testcases include a lot of tests (example 1.in/1.out,...). But I do not know how to write a script (or a program with C++ or any language) to test my testcases. If you know how to do it, hope you will help me! Thank you.

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

| Write comment?
»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I use https://ideone.com/88FCXo to generate the outputs for all input files. You can throw in a diff command to compare the output files.

»
6 years ago, # |
  Vote: I like it +12 Vote: I do not like it

You can check out this mini-grader bash script made by marsenis. It is very easy to use.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you, it actually helpful.

  • »
    »
    6 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    chpipis But, I use a brute-force solution to test, it returned Runtime Error instead of Time Limit Exceed :( Can you help me?

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      Hi, did you check if you actually had a Runtime Error (eg. allocating too much memory)?

      Also, do you return 0; at the end of main()? That may be a possible reason. I cannot think of anything else at the moment, it usually works smoothly for me.

      • »
        »
        »
        »
        6 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I had recheck but nothing wrong :( I have return 0;. Oh, I'm using MacOS High Sierra, what OS are you using?

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
            Vote: I like it +8 Vote: I do not like it

          Ubuntu 16.04 but I am not sure it has to do with the OS. Have you tried replacing the default G++ flags of the script by your own?

          • »
            »
            »
            »
            »
            »
            6 years ago, # ^ |
              Vote: I like it +8 Vote: I do not like it

            Yes, I add 2 flag to the default script? What wrong with it? I think the it also can depend on OS, because your C++ compiler can be g++ and my own is clang, is that true?

            • »
              »
              »
              »
              »
              »
              »
              6 years ago, # ^ |
                Vote: I like it +8 Vote: I do not like it

              Oh yeah, you must be right. I have g++ so I cannot test this on my machine.

»
6 years ago, # |
  Vote: I like it +5 Vote: I do not like it

I use very simple script on python to run exe-file on many tests. It can be easily modified, hope it will help you. Link

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I think your script can't check TLE and RE?

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      This script is not checking TLE and RE but I'm sure that you can find more information about subprocess and its return value or configuration at the official Python site.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The link is not working, Can you please update it?

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Oh, I changed my GitHub login from VladimirPetrov to vovuh so you can just change this part of URL (here is the correct link)

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        change: p = subprocess.Popen(path, stdin=fin, stdout=fout)

        to: p = subprocess.Popen(exepath, stdin=fin, stdout=fout)

»
6 years ago, # |
  Vote: I like it -37 Vote: I do not like it

But I do not know how to write a script (or a program with C++ or any language) to test my testcases.

LooOoLoOoooOoLoOooOoOoOoL. ROFL. LMAO. How have you been trying to learn "programming"? Have you written so much unreadable code to solve unrealistic problems that you cannot even write a simple program to solve a trivial problem?

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    You think it a simple trivial problem? Can you give me your code to test a testcases? Your code have to annouce all results such as accepts, time run, run time error or anything else like an online judge?

»
6 years ago, # |
  Vote: I like it +3 Vote: I do not like it

https://github.com/convict-git/.vimrc/blob/master/compile
It's a shell script. Save it as /usr/bin/compile Make a folder for every problem you solve. And save the inputs as input1, input2, .... and outputs as output1, output2, ... And whenever you want to run your code against these test cases,
compile [cppfile] [allowed run time]
eg. compile sol.cpp 1

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

you can use polygon

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I mean test locally. I have created problems on polygon, it only require input file and solution file to generate output. It doesn't check whether my solution is correct or not.

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      My bad, I read one of your comments above and for some reason thought you were testing it against a bruteforce solution, sorry.

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Khủng

»
5 years ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it