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

Автор minimario, история, 7 лет назад, По-английски

Hi,

Is there any program that can test a program on a large set of .in files against a large set of .out files? I heard about Ineffable, but I also heard it's really buggy.

Thanks!

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

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

If you use Linux, here is the command you are looking for:

for i in *.in; do j=${i%.*}; ./cpp < $j.in > my$j.out; echo ---$j---; diff -w my$j.out $j.out; done;

What it does is loop over all files having extension .in (this is the value of i), then j becomes the filename without the extension and after that it just runs your code with j.in, saves your output in myj.out and compares it to the correct output j.out.

Here is what it should look like if among 10 cases, the 7th one fails:

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

    Thanks! very useful

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

    I'm trying to extend this to files of the type I.(number) and O.(number). The current line I have is this:

    for i in I.*; do j=${*.i%}; ./cpp < I.$j > my$j.out; echo ---$j---; diff -w my$j.out O.$j; done;
    

    Unfortunately it seems to be failing to get the proper j (it thinks it is the character I). I am not very experienced with this kind of thing (I don't even know what it's called). Could you please tell me how I can get it to obtain the proper j values?

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +21 Проголосовать: не нравится
      do j=${i##*.}
      

      What this does is remove the longest match of *. from the front of i, which results into the extension we need. I also don't know a lot about bash, just a few things I find helpful for testing.

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

    Does anyone have a good solution for people who don't use Linux?

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

      For windows this works, if you want to test main.exe with all the pairs (x.in,x.ans) in the folder you do: $run.bat main

      @echo off
      setlocal enabledelayedexpansion
      
      set exe=%1.exe
      
      if not exist %exe% exit /B
      
      for %%I in (*.in) do (
        set testId=%%~nI
        set inputFile=%%I
        set answerFile=!testId!.ans
        set outputFile=!testId!.out
        %exe% <!inputFile!> !outputFile!
        echo Test #!testId!
        FC !answerFile! !outputFile!
      )
      

      You can start with this .bat and try to improve it