futurechampion's blog

By futurechampion, history, 6 years ago, In English

My question in title .I will be glad if you help me.

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

| Write comment?
»
6 years ago, # |
Rev. 3   Vote: I like it +49 Vote: I do not like it
@echo off
REM The line above prevents commands from being printed before execution

REM Type 'for /?' in command prompt for detailed help about for's options
REM Note that you should use double % sign in scripts, and single % sign in command prompt
REM For's variables should always be single-letter
for %%t in (*.in) do (
  REM There are special forms of accessing for's variable, see `for /?`
  solution <%%t >%%~nt.out || exit /b
  REM a || b means 'run a, if it fails, run b'.
  REM In the next line, if 'fc' (file compare) fails,
  REM then 'exit /b' is called (closes current batch script, but not the command prompt)
  fc %%~nt.out %%~nt.ans || exit /b
)
echo ok

Feel free to ask any questions you have about the script.

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

    Here is how it works: suppose you have a compiled solution.exe in the current working directory (it should read from stdin and print to stdout, no file I/O at all), as well as your tests: 01.in (first input), 01.ans (expected output for the first input), 02.in, 02.ans, ..., complex.in, complex.ans (it's not necessary for the test name to be a number). Now, if you save the script here as testall.cmd (or testall.bat, whatever, I prefer the former), you can run it from command prompt and check its output.

    So, directory structure may go like this:

    D:\work\180522
    |- solution.exe
    |- 01.in
    |- 01.ans
    |- 02.in
    |- 02.ans
    |- complex.in
    |- complex.ans
    |- testall.cmd
    

    If you type the following in command prompt (cmd.exe), it should run the solution on all tests:

    D:
    cd D:\work\180522
    testall
    

    It will test until the solution fails or its output (stored in 01.out, 02.out, complex.out) does not match the expected output. If something goes wrong, the script terminates. If everything goes well, it ends and prints ok in the very end.